【问题标题】:Extracting only some coefficients for the logistic regression model and its plot仅提取逻辑回归模型及其图的一些系数
【发布时间】:2022-06-15 04:33:29
【问题描述】:
sample_data = read.table("http://freakonometrics.free.fr/db.txt",
                         header=TRUE, sep=";")
head(sample_data)
model = glm(Y~0+X1+X2+X3,family=binomial,data=sample_data)
summary(model)
exp(coef(model ))
exp(cbind(OR = coef(model ), confint(model )))

我有上面的逻辑回归样本数据和分类预测器 我尝试上面的代码得到以下输出,

            OR       2.5 %     97.5 %
X1  1.67639337 1.352583976 2.09856514
X2  1.23377720 1.071959330 1.42496949
X3A 0.01157565 0.001429430 0.08726854
X3B 0.06627849 0.008011818 0.54419759
X3C 0.01118084 0.001339984 0.08721028
X3D 0.01254032 0.001545240 0.09539880
X3E 0.10654454 0.013141540 0.87369972

但我想知道如何仅针对因子提取 OR 和 CI。我的 所需的输出将是:

 OR       2.5 %     97.5 %
X3A 0.01157565 0.001429430 0.08726854
X3B 0.06627849 0.008011818 0.54419759
X3C 0.01118084 0.001339984 0.08721028
X3D 0.01254032 0.001545240 0.09539880
X3E 0.10654454 0.013141540 0.87369972

谁能帮我提取代码? 另外我想用置信区间绘制上面的 OR 提取的一个。 你也可以帮我用绘图或箱线图的代码吗?

【问题讨论】:

    标签: r regression linear-regression coefficients


    【解决方案1】:

    您可以过滤掉与数据框中的变量名称相同的行,因为那些附加因子级别的行名称将不匹配:

    result <- exp(cbind(OR = coef(model ), confint(model )))
    
    result[!rownames(result) %in% names(sample_data),]
    #>             OR       2.5 %     97.5 %
    #> X3A 0.01157565 0.001429430 0.08726854
    #> X3B 0.06627849 0.008011818 0.54419759
    #> X3C 0.01118084 0.001339984 0.08721028
    #> X3D 0.01254032 0.001545240 0.09539880
    #> X3E 0.10654454 0.013141540 0.87369972
    

    【讨论】:

      猜你喜欢
      • 2020-12-22
      • 1970-01-01
      • 2013-09-30
      • 2017-12-22
      • 2019-12-20
      • 2013-04-10
      • 2021-08-21
      • 2018-12-09
      • 2015-11-18
      相关资源
      最近更新 更多