【问题标题】:Obtaining regression coefficients from reduced major axis regression models using lmodel2 package使用 lmodel2 包从简化的主轴回归模型中获取回归系数
【发布时间】:2018-03-22 05:32:49
【问题描述】:

我有一个大型数据集,我正在用它进行许多回归分析。我正在使用带有 r 的 lmodel2 包的减少的主轴回归。我需要做的是从 RMA 模型中提取回归系数(r 平方、p 值、斜率和截距)。我可以使用 OLS 回归轻松做到这一点:

RSQ<-summary(model)$r.squared
PVAL<-summary(model)$coefficients[2,4]
INT<-summary(model)$coefficients[1,1]
SLOPE<-summary(model)$coefficients[2,1]

然后将它们导出为 .csv

export<-data.frame(RSQ,PVAL,INT,SLOPE)
write.csv(export, file="FILE_NAME.csv",row.names=F)

这些命令似乎不适用于lmodel2 回归。有人知道怎么做吗?

这里是一小部分数据:

x            y
0.440895993 227.7
0.294277869 296.85
0.171754892 298.05
0           427.65
0.210884179 215.55
0.053238011 293.7
0.105395366 127.9
0.463933834 229.5
0           165.45
0.482128605 192.15
0.247341039 266.9
0           349.35
0.198833301 185.05
0.170786027 203.85
0.269818315 207.05
0.129543682 222.75
0.441665334 251.35
0           262.8
0.517974685 107.05
0.446336968 191.6

以及我正在使用的模型 II 回归代码

library(lmodel2)
data<-sample_data
mod_2<-lmodel2(y~x,data=data,"interval","interval",99)
mod_2

【问题讨论】:

    标签: r regression intercept p-value coefficients


    【解决方案1】:

    这个呢?

    # making data reproducable
    data <- read.table(text = "x            y
    0.440895993 227.7
    0.294277869 296.85
    0.171754892 298.05
    0           427.65
    0.210884179 215.55
    0.053238011 293.7
    0.105395366 127.9
    0.463933834 229.5
    0           165.45
    0.482128605 192.15
    0.247341039 266.9
    0           349.35
    0.198833301 185.05
    0.170786027 203.85
    0.269818315 207.05
    0.129543682 222.75
    0.441665334 251.35
    0           262.8
    0.517974685 107.05
    0.446336968 191.6", header = TRUE)
    
    #estimate model
    library(lmodel2)
    mod_2 <- lmodel2(y ~ x, data = data, "interval", "interval", 99)  # 99% ci
    

    简要查看summary(),它提供了有关如何保存模型统计信息的信息。 (你也可以试试str())。

    # view summary
    summary(mod_2)
    #                      Length Class      Mode   
    # y                    20     -none-     numeric
    # x                    20     -none-     numeric
    # regression.results    5     data.frame list   
    # confidence.intervals  5     data.frame list   
    # eigenvalues           2     -none-     numeric
    # H                     1     -none-     numeric
    # n                     1     -none-     numeric
    # r                     1     -none-     numeric
    # rsquare               1     -none-     numeric
    # P.param               1     -none-     numeric
    # theta                 1     -none-     numeric
    # nperm                 1     -none-     numeric
    # epsilon               1     -none-     numeric
    # info.slope            1     -none-     numeric
    # info.CI               1     -none-     numeric
    # call                  6     -none-     call   
    

    可以看出,GOF 的变量名称(您称它们为“命令”)是特定于包的。您可以通过在 $ 运算符之后将它们添加到模型的对象名称来进行选择。

    # Getting r squared
    (RSQ <- mod_2$rsquare)
    # [1] 0.1855163
    

    对于系数及其统计信息lmodel2 想要$regression.results

    mod_2$regression.results
    # Method Intercept     Slope Angle (degrees) P-perm (1-tailed)
    # 1    OLS  277.2264 -177.0317       -89.67636              0.04
    # 2     MA  457.7304 -954.2606       -89.93996              0.04
    # 3    SMA  331.5673 -411.0173       -89.86060                NA
    # 4    RMA  296.6245 -260.5577       -89.78010              0.04
    
    # wanted results from the RMA model
    (INT <- mod_2$regression.results[[2]][4])
    # [1] 296.6245
    (SLOPE <- mod_2$regression.results[[3]][4])
    # [1] -260.5577
    (PVAL <- mod_2$regression.results[[5]][4])
    # [1] 0.04
    
    # Combined together in a data frame:
    data.frame(RMA = rbind(INT, SLOPE, PVAL))
    #             RMA
    # INT    296.6245
    # SLOPE -260.5577
    # PVAL     0.0400
    

    【讨论】:

    • 感谢您快速而富有启发性的回复。我仍然有点困惑,因为mod_2$x[c(2,4)] 给了我[1] 0.2942779 0.0000000。 RMA 斜率和截距值分别为 -260.5577 和 296.6245。我错过了什么?
    • 不客气。我刚刚扩展了我的答案,现在这对你有用吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-22
    • 2013-10-14
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    相关资源
    最近更新 更多