I have fitted a linear regression model:

   Lin <- lm(y~x, data=df)

When I use the summary function, I get some output. How do I extract the parameter coefficients from this output?

有帮助吗?

解决方案

Here are a few ways of getting the parameter estimates:

R> m = lm(y ~ x)
R> m
Call:
lm(formula = y ~ x)

Coefficients:
(Intercept)            x  
     0.5821       0.0878  

Or

##See ?coef for details
R> coef(m)
R> coefficients(m)

or

##m is a list. So extract as usual
##str(m)
R> m$coefficients
R> m[[1]]

The crucial point is that m is an R list that you can interrogate as usual.

The same ideas apply when you use the summary function:

R> summary(m)$coefficients[,1]
(Intercept)           x 
    0.58213     0.08781 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top