Extract regression coefficient values

0 votes

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) 

The summary output of mg is:

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

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

                  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 

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

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?

Mar 26 in Machine Learning by Nandini
• 5,480 points

1 answer to this question.

0 votes

A quick rundown. These values are stored in a matrix named 'coefficients' by the lm object. As a result, you can get the value you're looking for by typing:

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

Or, to put it another way, coef(summary(mg))["a2","Pr(>|t|)")].
It is suggested that you utilize those extractor functions since you can be sure that they will always return the proper information, even if the function authors decide to shuffle things about behind the scenes.

Maybe they add more information to one of the model list object's elements, which causes things to go out of order? All of your code will be broken.

answered Mar 30 by Dev
• 6,000 points

Related Questions In Machine Learning

0 votes
1 answer

Logistic regression coefficient meaning

What did the intercept teach you? It's ...READ MORE

answered Mar 23 in Machine Learning by Nandini
• 5,480 points
0 votes
1 answer

Linear regression returning bad fit with large x values

To make the date values start at ...READ MORE

answered Mar 23 in Machine Learning by Nandini
• 5,480 points
0 votes
1 answer

How to export regression equations for grouped data?

First, you'll need a linear model with ...READ MORE

answered Mar 14 in Machine Learning by Dev
• 6,000 points
0 votes
1 answer

How to add regression line equation and R2 on graph?

Below is one solution: # GET EQUATION AND ...READ MORE

answered Jun 1, 2018 in Data Analytics by DataKing99
• 8,240 points
0 votes
1 answer
0 votes
1 answer

How to extract the regression coefficient from statsmodels.api?

The coefficients can be obtained using the ...READ MORE

answered Mar 17 in Machine Learning by Dev
• 6,000 points
Send OTP
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP