加載包
library(sjPlot)
library(sjmisc)
library(sjlabelled)
數(shù)據(jù)準備
data('efc')
efc <- as_factor(efc,c161sex,c172code)
建模(線性模型)
m1 <- lm(barthtot ~ c160age + c12hour + c161sex + c172code, data = efc)
m2 <- lm(neg_c_7 ~ c160age + c12hour + c161sex + e17age, data = efc)
繪制三線表
tab_model(m1)
圖片.png
自動加因變量標簽(自動加入了因變量標簽同欠,若沒有標簽,顯示因變量名mpg)
m.mtcars <- lm(mpg ~ cyl + hp + wt, data = mtcars)
tab_model(m.mtcars)
圖片.png
關閉自動加因變量標簽
auto.label= FALSE
tab_model(m1,auto.label = F)
圖片.png
否則為4圖
多個模型繪制三線圖
tab_model(m1,m2)
圖片.png
廣義線性模型的三線圖(自動系數(shù)指數(shù)化變?yōu)镺R)
m3 <- glm(
tot_sc_e ~ c160age + c12hour + c161sex + c172code,
data = efc,
family = poisson(link = "log")
)
efc$neg_c_7d <- ifelse(efc$neg_c_7 < median(efc$neg_c_7, na.rm = TRUE), 0, 1)
m4 <- glm(
neg_c_7d ~ c161sex + barthtot + c172code,
data = efc,
family = binomial(link = "logit")
)
tab_model(m3, m4,auto.label=F)
圖片.png
廣義線性模型不進行自動指數(shù)變換
tab_model(m3,m4,transform=NULL,auto.label=F)
圖片.png
選擇或剔除相應的列
tab_model(m3,m4,transform=NULL,auto.label=F)#個體化顯示行
show.est #顯示預測值
show.ci #顯示置信區(qū)間
show.se #顯示標準誤
show.std #顯示系數(shù)赵讯?
show.p #顯示p值
show.stat #顯示系數(shù)的統(tǒng)計學檢驗值
show.df #顯示自由度
tab_model(m1,auto.label=F)
tab_model(m1, show.se = TRUE, show.std = TRUE, show.stat = TRUE,auto.label = F)
圖片.png
tab_model(m3, m4, show.ci = FALSE, show.p = FALSE, auto.label = FALSE)
tab_model(m3,m4,auto.label = F)
圖片.png
個體化顯示行
tab_model(
m1, auto.label = F,show.se = TRUE, show.std = TRUE, show.stat = TRUE,
col.order = c("p", "stat", "est", "std.se", "se", "std.est")
)
圖片.png
置信區(qū)間合并
tab_model(m1,collapse.ci = T,auto.label = F)
tab_model(m1,collapse.ci = F,auto.label = F)
圖片.png
自定義行列名(pred.labels定義變量名巡揍,dv.labels定義模型名,)
tab_model(m1,m2,auto.label = F)
tab_model(
m1, m2,
pred.labels = c("a", "b", "c", "d","e", "f","g"),
dv.labels = c("e", "f"),
string.est = 'ee',
string.pred = "g",
string.ci = "h",
string.p = "i"
)
圖片.png
自定義P值(stars為*號油够,scientific為科學計數(shù)法
tab_model(m1, m2, p.style = "stars",auto.label = F) #*表示
tab_model(m1, m2, p.style = "scientific", digits.p = 2,auto.label = F) #科學計數(shù)法保留兩位小數(shù)
圖片.png
圖片.png
僅僅顯示特定的變量(terms,rm.terms)
tab_model(m1,auto.label = F)
tab_model(m1, terms = c("c160age", "c12hour"),auto.label = F)
tab_model(m1, rm.terms = c("c172code2", "c161sex2"),auto.label = F)
圖片.png