Regression Tables from ‘GLM’, ‘GEE’, ‘GLMM’, ‘Cox’ and ‘survey’ Results for Publication.

Install

GEE Table: from geeglm object from geepack package

library(geepack)  ## for dietox data
data(dietox)
dietox$Cu <- as.factor(dietox$Cu)
dietox$ddn = as.numeric(rnorm(nrow(dietox)) > 0)
gee01 <- geeglm (Weight ~ Time + Cu , id = Pig, data = dietox, family = gaussian, corstr = "ex")
geeglm.display(gee01)
gee02 <- geeglm (ddn ~ Time + Cu , id = Pig, data = dietox, family = binomial, corstr = "ex")
geeglm.display(gee02)

Mixed model Table: lmerMod or glmerMod object from lme4 package

library(lme4)
l1 = lmer(Weight ~ Time + Cu + (1|Pig) + (1|Evit), data = dietox) 
lmer.display(l1, ci.ranef = T)
l2 = glmer(ddn ~ Weight + Time + (1|Pig), data= dietox, family= "binomial")
lmer.display(l2)

GLM for survey data : svyglm object from survey package

library(survey)
data(api)
apistrat$tt = c(rep(1, 20), rep(0, nrow(apistrat) -20))
apistrat$tt2 = factor(c(rep(0, 40), rep(1, nrow(apistrat) -40)))

dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
ds <- svyglm(api00~ell+meals+mobility + tt2, design=dstrat)
ds2 <- svyglm(tt~ell+meals+mobility + tt2, design=dstrat, family = quasibinomial())
svyregress.display(ds)

Cox model for survey data :svycoxph object from survey package

data(pbc, package="survival")
pbc$sex = factor(pbc$sex)
pbc$stage = factor(pbc$stage)
pbc$randomized<-with(pbc, !is.na(trt) & trt>0)
biasmodel<-glm(randomized~age*edema,data=pbc,family=binomial)
pbc$randprob<-fitted(biasmodel)

if (is.null(pbc$albumin)) pbc$albumin<-pbc$alb ##pre2.9.0

dpbc <- svydesign(id=~1, prob=~randprob, strata=~edema, data=subset(pbc,randomized))

model <- svycoxph(Surv(time,status>0)~ sex + protime + albumin + stage,design=dpbc)
svycox.display(model)
## Stratified Independent Sampling design (with replacement)
## svydesign(id = ~1, prob = ~randprob, strata = ~edema, data = subset(pbc, 
##     randomized))
## Stratified Independent Sampling design (with replacement)
## svydesign(id = ~1, prob = ~randprob, strata = ~edema, data = subset(pbc, 
##     randomized))
## Stratified Independent Sampling design (with replacement)
## svydesign(id = ~1, prob = ~randprob, strata = ~edema, data = subset(pbc, 
##     randomized))
## Stratified Independent Sampling design (with replacement)
## svydesign(id = ~1, prob = ~randprob, strata = ~edema, data = subset(pbc, 
##     randomized))
## Stratified Independent Sampling design (with replacement)
## svydesign(id = ~1, prob = ~randprob, strata = ~edema, data = subset(pbc, 
##     randomized))

## $table
##               crude HR(95%CI)      crude P value adj. HR(95%CI)       
## sex: f vs m   "0.62 (0.4,0.97)"    "0.038"       "0.55 (0.33,0.9)"    
## protime       "1.37 (1.09,1.72)"   "0.006"       "1.52 (1.2,1.91)"    
## albumin       "0.2 (0.14,0.29)"    "< 0.001"     "0.31 (0.2,0.47)"    
## stage: ref.=1 NA                   NA            NA                   
##    2          "5.67 (0.77,41.78)"  "0.089"       "10.94 (1.01,118.55)"
##    3          "9.78 (1.37,69.94)"  "0.023"       "17.03 (1.69,171.6)" 
##    4          "22.89 (3.2,163.48)" "0.002"       "22.56 (2.25,226.42)"
##               adj. P value
## sex: f vs m   "0.017"     
## protime       "< 0.001"   
## albumin       "< 0.001"   
## stage: ref.=1 NA          
##    2          "0.049"     
##    3          "0.016"     
##    4          "0.008"     
## 
## $metric
##                        [,1] [,2] [,3] [,4]
## <NA>                     NA   NA   NA   NA
## No. of observations  312.00   NA   NA   NA
## No. of events        144.00   NA   NA   NA
## AIC                 1483.12   NA   NA   NA
## 
## $caption
## [1] "Survey cox model on time ('time') to event ('status > 0')"

Sub-group analysis for Cox/svycox model

library(survival); library(dplyr)
lung %>% 
mutate(status = as.integer(status == 1),
       sex = factor(sex),
       kk = factor(as.integer(pat.karno >= 70)),
       kk1 = factor(as.integer(pat.karno >= 60))) -> lung

TableSubgroupMultiCox(Surv(time, status) ~ sex, var_subgroups = c("kk", "kk1"), data=lung, line = T)
## Survey data
library(survey)
data.design <- svydesign(id = ~1, data = lung)
TableSubgroupMultiCox(Surv(time, status) ~ sex, var_subgroups = c("kk", "kk1"), data = data.design, line = F)