Let's say I have data:
data = data.frame(xdata = 1:10, ydata = 6:15)
I look at the data
data
xdata ydata
1 1 6
2 2 7
3 3 8
4 4 9
5 5 10
6 6 11
7 7 12
8 8 13
9 9 14
10 10 15
Now I want to include a third column to the data which should be an increment/estimate and a fourth column we should be standard errors. To do this, I estimate the increment for each row of the data by fitting a linear model and taking the slope/estimate and also the associated standard error. So I fit model_1:
model_1 = lm(ydata~xdata,data = data)
out = summary(model_1)
out
It gives me:
Call:
lm(formula = ydata ~ xdata, data = data)
Residuals:
Min 1Q Median 3Q Max
-5.661e-16 -1.157e-16 4.273e-17 2.153e-16 4.167e-16
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.000e+00 2.458e-16 2.035e+16 <2e-16 ***
xdata 1.000e+00 3.961e-17 2.525e+16 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.598e-16 on 8 degrees of freedom
Multiple R-squared: 1, Adjusted R-squared: 1
F-statistic: 6.374e+32 on 1 and 8 DF, p-value: < 2.2e-16
To extract the estimate, I can simply do:
out$coefficients[2,1]
To extract the standard error, I can simply do:
out$coefficients[2,2]
but my interest is to have an out put that shows estimates and standard errors for each row so that I end up with 10 estimates and 10 standard errors. Is there a way to do this?
Many thanks!