getwd() setwd( "/Users/jasmma/abl") zxb=read.csv("zxb111.csv") log<-glm(frail~age+txl+BMI+ag+tx+BM+address+sex+marriage+live+smoking+drink+exercise+education+primary+DM+HP+Hrart +Cero+com+pro+income+follow+depress+anxiety+RBC+Hb+HCT+fe+Ca+P+iPTH+alb+cr+bun+com1,family = binomial,data = zxb) summary(log) log.step<-step(log) summary(log.step) # ##############制作表格######## install.packages(c("stats", "MASS", "car", "tidyverse", "knitr", "kableExtra")) library(stats) library(MASS) library(car) library(tidyverse) library(knitr) library(kableExtra) kable(summary(log.step)$coefficients, align = "c", caption = "Logistic Regression Results") %>% kable_styling(bootstrap_options = "hover", full_width = F) %>% column_spec(1, bold = T) %>% column_spec(4, color = "white", background = "steelblue") ############### 将结果转化为表格形式##### result <- data.frame( variable = names(log.step$coefficients)[-1], # 变量名称 beta = coef(log.step)[-1], # β系数 wald_stat = summary(log.step)$coefficients[-1, "z"], # Wald统计量 se = summary(log.step)$coefficients[-1, "Std. Error"], # 标准误差 or = exp(coef(log.step)[-1]), # 比值比 ci_low = exp(confint(log.step)[-1, 1]), # 置信区间下限 ci_high = exp(confint(log.step)[-1, 2]), # 置信区间上限 p_value = summary(log.step)$coefficients[-1, "Pr(>|z|)"] # P值 )
时间: 2024-01-05 13:04:44 浏览: 143
R语言 CSV文件.pdf
这段代码是进行 logistic 回归分析的,包括数据读入、模型拟合、模型选择以及结果展示等步骤。其中,使用step()函数进行模型选择,生成的模型结果通过summary()函数进行总结统计,并通过kable()和kableExtra()函数将结果转化为表格形式进行展示。最后,将结果保存到result数据框中。
阅读全文