Obtaining regression coefficients from reduced major axis regression models using lmodel2 package

ぐ巨炮叔叔 提交于 2019-12-12 04:59:41

问题


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]

And then export them in a .csv

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

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

Here is a small sample of the data:

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

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

回答1:


What about this?

# 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

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   

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

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


来源:https://stackoverflow.com/questions/46673012/obtaining-regression-coefficients-from-reduced-major-axis-regression-models-usin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!