How do you pull out a coefficient value from the summary of a linear regression model?
The first two are obtainable with lm1$coefficients[1] or [2], but I’m not sure how to get the third value. In the sprintf code below, I get NA if I use lm1$coefficients[3] or incorrect number of dimensions if lm1$coefficients[1:2,1] is used. In the summary example, the two values I’d want to substitute for %s are 295.274 and 62.012. Does anyone know how to access the latter?
sprintf("The linear relationship can be described using the fitted regression line: Household debt = %s + %s", lm1$coefficients[1], lm1$coefficients[0,1])
> str(summary(M.lm)) # Truncated output...
List of 11
$ call : language lm(formula = MaxSalary ~ Score, data = salarygov)
$ terms :Classes 'terms', 'formula' length 3 MaxSalary ~ Score
...
$ residuals : Named num [1:495] -232.3 -132.6 37.9 114.3 232.3 ...
$ coefficients : num [1:2, 1:4] 295.274 5.76 62.012 0.123 4.762 ...
$ aliased : Named logi [1:2] FALSE FALSE
$ sigma : num 507
$ df : int [1:3] 2 493 2
$ r.squared : num 0.817
$ adj.r.squared: num 0.816
$ fstatistic : Named num [1:3] 2194 1 493
$ cov.unscaled : num [1:2, 1:2] 1.50e-02 -2.76e-05 -2.76e-05 5.88e-08