Extracting parameter coefficients from the summary function [duplicate]

风格不统一 提交于 2019-12-14 03:48:04

问题


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?


回答1:


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 


来源:https://stackoverflow.com/questions/18208498/extracting-parameter-coefficients-from-the-summary-function

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