【问题标题】:How to get the result of lrm() respectively?如何分别得到 lrm() 的结果?
【发布时间】:2021-09-21 14:30:37
【问题描述】:

如何分别得到lrm()的结果?

我使用lrm()建立一个逻辑模型,得到的结果如下:

n <- 1000     # define sample size
y              <- rep(0:1, 500)
age            <- rnorm(n, 50, 10)
sex            <- factor(sample(c('female','male'), n,TRUE))

f <- lrm(y ~ age + sex, x=TRUE, y=TRUE)
f


                       Model Likelihood    Discrimination    Rank Discrim.    
                             Ratio Test           Indexes          Indexes    
 Obs          1000    LR chi2      1.50    R2       0.002    C       0.520    
  0            500    d.f.            2    g        0.088    Dxy     0.040    
  1            500    Pr(> chi2) 0.4714    gr       1.092    gamma   0.040    
 max |deriv| 2e-13                         gp       0.022    tau-a   0.020    
                                           Brier    0.250                     
 
           Coef    S.E.   Wald Z Pr(>|Z|)
 Intercept  0.2206 0.3370  0.65  0.5127  
 age       -0.0030 0.0065 -0.46  0.6485  
 sex=male  -0.1455 0.1266 -1.15  0.2504  

如何分别得到上面的结果作为data.frame?喜欢:

mydf$df1

                       Model Likelihood    Discrimination    Rank Discrim.    
                             Ratio Test           Indexes          Indexes    
 Obs          1000    LR chi2      1.50    R2       0.002    C       0.520    
  0            500    d.f.            2    g        0.088    Dxy     0.040    
  1            500    Pr(> chi2) 0.4714    gr       1.092    gamma   0.040    
 max |deriv| 2e-13                         gp       0.022    tau-a   0.020    
                                           Brier    0.250        

mydf$df2

           Coef    S.E.   Wald Z Pr(>|Z|)
 Intercept  0.2206 0.3370  0.65  0.5127  
 age       -0.0030 0.0065 -0.46  0.6485  
 sex=male  -0.1455 0.1266 -1.15  0.2504  

【问题讨论】:

    标签: r logistic-regression


    【解决方案1】:

    试试,

    res = capture.output(print(f), append = F, sep = " ")
    lapply(res, function(x) write.table(data.frame(x), 'res.csv'  , append= T, sep=',' ))
    

    【讨论】:

    • 谢谢,我试了一下,但它只是将结果捕获为字符串并输出到csv 文件。我可以得到可以直接在R中使用的data.frame的结果吗?
    猜你喜欢
    • 1970-01-01
    • 2022-08-15
    • 2018-05-01
    • 1970-01-01
    • 2015-04-08
    • 2021-04-19
    • 2021-07-31
    • 2020-11-15
    • 2015-12-04
    相关资源
    最近更新 更多