jenniferthompson / JTHelpers

A package of helper functions for my own frequent use.
0 stars 0 forks source link

rms_model_results(): Bug fix for Gls models #2

Open jenniferthompson opened 7 years ago

jenniferthompson commented 7 years ago

Many thanks to Yonghao Pua for catching this and creating a reprex.

_Currently, rms_model_results() works beautifully with ols and lrm objects but I'm wondering if you could very kindly extend its reach to Gls objects. With orm objects, rms_modelresults() works reasonably well; with Gls objects, it balks with an error message: "Error in label == "d.f." : comparison (1) is possible only for atomic and list types". Below, I provide a minimal example.

rm(list=ls())
library(plyr)
library(dplyr)
library(tidyr)
library(rms)
library(JTHelpers)

# create tall-and-thin longitudinal dataframe 
longdf <- data.frame(
    expand.grid(id = seq(1:10), time = 1:5), outcome = round(runif(50, 2, 12), 0)
)

longdf <- longdf %>%
  arrange(id, time) %>%
  mutate( age = rep(round(runif(10, 20, 60),0), each = 5 ))

longdf.dd <- datadist(longdf); options(datadist = "longdf.dd")

glsmod <-Gls(outcome~ time + rcs(age,3), correlation = corCAR1 (form=~time|id), data=longdf)

glsmod; summary(glsmod); anova(glsmod)

rms_model_results(glsmod)  # throws error mesage

Error in label == "d.f." : comparison (1) is possible only for atomic and list types

jenniferthompson commented 7 years ago

Potential fix from Yonghao attached - R script in .txt format (why don't you support .R, Github?)

possible_rms_model_results_fix.txt