使用 lmodel2 包从简化的主轴回归模型中获取回归系数 [英] Obtaining regression coefficients from reduced major axis regression models using lmodel2 package

查看:107
本文介绍了使用 lmodel2 包从简化的主轴回归模型中获取回归系数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a large data set with which I'm undertaking many regression analyses. I'm using a reduced major axis regression with r's lmodel2 package. What I need to do is extract the regression coefficients (r-squared, p-values, slope and intercept) from the RMA models. I can do this easily enough with the OLS regressions using:

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

然后将它们导出为 .csv

And then export them in a .csv

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

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

These commands don't seem to work for the lmodel2 regressions. Does anybody know how to do it?

以下是一小部分数据:

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 回归代码

And the model II regression code I'm using

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

推荐答案

这个呢?

# 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()).

Take a brief look at the summary(), which is informative of how the model statistics is saved. (Also you may want to try 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 的变量名称(您称之为命令")是特定于包的.您可以通过在 $ 运算符之后将它们添加到模型的对象名称中来进行选择.

As can be seen the variable names of the GOFs (you called them 'commands') are specific to the package. You can select by adding them to the object name of your model after a $ operator.

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

对于系数及其统计数据 lmodel2 需要 $regression.results.

For the coefficients and their statistics lmodel2 wants $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

这篇关于使用 lmodel2 包从简化的主轴回归模型中获取回归系数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆