提取回归系数值 [英] Extract regression coefficient values

查看:113
本文介绍了提取回归系数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些用于研究药物利用情况的时间序列数据的回归模型.目的是使样条曲线适合时间序列并计算95%CI等.模型如下:

I have a regression model for some time series data investigating drug utilisation. The purpose is to fit a spline to a time series and work out 95% CI etc. The model goes as follows:

id <- ts(1:length(drug$Date))
a1 <- ts(drug$Rate)
a2 <- lag(a1-1)
tg <- ts.union(a1,id,a2)
mg <-lm (a1~a2+bs(id,df=df1),data=tg) 

mg的摘要输出为:

Call:
lm(formula = a1 ~ a2 + bs(id, df = df1), data = tg)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.31617 -0.11711 -0.02897  0.12330  0.40442 

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)    
(Intercept)        0.77443    0.09011   8.594 1.10e-11 ***
a2                 0.13270    0.13593   0.976  0.33329    
bs(id, df = df1)1 -0.16349    0.23431  -0.698  0.48832    
bs(id, df = df1)2  0.63013    0.19362   3.254  0.00196 ** 
bs(id, df = df1)3  0.33859    0.14399   2.351  0.02238 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

我正在使用a2Pr(>|t|)值来测试所调查的数据是否是自相关的.

I am using the Pr(>|t|) value of a2 to test if the data under investigation are autocorrelated.

是否可以提取此值Pr(>|t|)(在此模型中为0.33329)并将其存储在标量中以执行逻辑测试?

Is it possible to extract this value of Pr(>|t|) (in this model 0.33329) and store it in a scalar to perform a logical test?

或者,可以使用其他方法解决吗?

Alternatively, can it be worked out using another method?

推荐答案

summary.lm对象将这些值存储在称为'coefficients'matrix中.因此,您可以通过以下方式访问所追求的价值:

A summary.lm object stores these values in a matrix called 'coefficients'. So the value you are after can be accessed with:

a2Pval <- summary(mg)$coefficients[2, 4]

或更一般地/可读地,是coef(summary(mg))["a2","Pr(>|t|)"].有关为什么首选此方法的信息,请参见此处.

Or, more generally/readably, coef(summary(mg))["a2","Pr(>|t|)"]. See here for why this method is preferred.

这篇关于提取回归系数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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