biostatsPMH / reportRx

Tools for automatically generating reproducible clinical report
Creative Commons Zero v1.0 Universal
2 stars 1 forks source link

strange rm_uvsum behaviour #10

Closed ghost closed 3 years ago

ghost commented 3 years ago

I am unable to re-produce these errors.

From Katrina: If I add empty levels to a variable used in my univariable tables, rm_uvsum behaves a bit weirdly for some types of regressions. I first noticed it using a Cox model. I’m including a reproducible example below, I tried this out for lm() and glm() as well with slightly different results each time.

Reproducible example:

rm(list=ls()) library(reportRx) #development version library(survival)

data(lung)

create variable with empty levels:

lung$Sex <- recode(lung$sex, 1="Male",2="Female") lung$Sex <- factor(lung$Sex, levels=c("","Empty level","Male","Female"))

linear model: no issue

summary(lm(time~Sex, data=lung)) rm_uvsum(response="time",covs="Sex",data=lung)

survival model: rm_uvsum duplicates variable levels in tables

coxph(Surv(time, status)~Sex, data=lung) rm_uvsum(data=lung, response=c("time","status"),covs="Sex")

logistic: missing p-value

lung$binaryvar <- rbinom(nrow(lung), 1, 0.5)

summary(glm(binaryvar~Sex, data=lung, family=binomial(link="logit"))) rm_uvsum(data=lung, response="binaryvar",covs="Sex")