从汇总函数中提取参数系数 [英] Extracting parameter coefficients from the summary function

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

问题描述

我已经拟合了线性回归模型:

I have fitted a linear regression model:

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

当我使用summary函数时,我得到一些输出.如何从此输出中提取参数系数?

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  

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

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

关键点是m是一个R列表,您可以照常查询.

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

使用summary函数时,同样的想法也适用:

The same ideas apply when you use the summary function:

R> summary(m)$coefficients[,1]
(Intercept)           x 
    0.58213     0.08781 

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

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