How do I construct a variable that is equal to the residuals from my regression??

bwghtreg2<-lm(bwght~cigs+cigprice+cigtax+parity+male+motheduc, data=BWGHT2021)
summary(bwghtreg2)

Call:
lm(formula = bwght ~ cigs + cigprice + cigtax + parity + male +
motheduc, data = BWGHT2021)

Residuals:
Min 1Q Median 3Q Max
-95.970 -11.800 0.756 12.961 153.241

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 103.46163 12.26299 8.437 < 2e-16 ***
cigs -0.50280 0.09238 -5.443 6.19e-08 ***
cigprice 0.04761 0.10906 0.437 0.66250
cigtax 0.06472 0.14339 0.451 0.65182
parity 1.59998 0.60673 2.637 0.00846 **
male 2.88453 1.07747 2.677 0.00751 **
motheduc 0.36320 0.23360 1.555 0.12022

Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 20.03 on 1380 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.03645, Adjusted R-squared: 0.03226
F-statistic: 8.7 on 6 and 1380 DF, p-value: 2.566e-09

bwghtreg2$residuals

The object bwghtreg2 is a list and one of the elements is named residuals. You can see this by running str(bwhtreg2). You can extract the residuals with either of these commands

bwghtreg2$residuals
or
residuals(bwghtreg2)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.