Linear regression
year <- c(2000 , 2001 , 2002 , 2003 , 2004)
rate <- c(9.34 , 8.50 , 7.62 , 6.93 , 6.60)
fit <- lm(rate ~ year)
fit
##
## Call:
## lm(formula = rate ~ year)
##
## Coefficients:
## (Intercept) year
## 1419.208 -0.705
summary(fit)
##
## Call:
## lm(formula = rate ~ year)
##
## Residuals:
## 1 2 3 4 5
## 0.132 -0.003 -0.178 -0.163 0.212
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1419.2080 126.9496 11.2 0.0015 **
## year -0.7050 0.0634 -11.1 0.0016 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.201 on 3 degrees of freedom
## Multiple R-squared: 0.976, Adjusted R-squared: 0.968
## F-statistic: 124 on 1 and 3 DF, p-value: 0.00156
anova(fit)
## Analysis of Variance Table
##
## Response: rate
## Df Sum Sq Mean Sq F value Pr(>F)
## year 1 4.97 4.97 124 0.0016 **
## Residuals 3 0.12 0.04
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(car)
head(Prestige)
## education income women prestige census type
## gov.administrators 13.11 12351 11.16 68.8 1113 prof
## general.managers 12.26 25879 4.02 69.1 1130 prof
## accountants 12.77 9271 15.70 63.4 1171 prof
## purchasing.officers 11.42 8865 9.11 56.8 1175 prof
## chemists 14.62 8403 11.68 73.5 2111 prof
## physicists 15.64 11030 5.13 77.6 2113 prof
fit <- lm(prestige ~education +log2(income) +women,data=Prestige)
fit
##
## Call:
## lm(formula = prestige ~ education + log2(income) + women, data = Prestige)
##
## Coefficients:
## (Intercept) education log2(income) women
## -110.9658 3.7305 9.3147 0.0469
summary(fit)
##
## Call:
## lm(formula = prestige ~ education + log2(income) + women, data = Prestige)
##
## Residuals:
## Min 1Q Median 3Q Max
## -17.364 -4.429 -0.101 4.316 19.179
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -110.9658 14.8429 -7.48 3.3e-11 ***
## education 3.7305 0.3544 10.53 < 2e-16 ***
## log2(income) 9.3147 1.3265 7.02 2.9e-10 ***
## women 0.0469 0.0299 1.57 0.12
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.09 on 98 degrees of freedom
## Multiple R-squared: 0.835, Adjusted R-squared: 0.83
## F-statistic: 165 on 3 and 98 DF, p-value: <2e-16
anova(fit)
## Analysis of Variance Table
##
## Response: prestige
## Df Sum Sq Mean Sq F value Pr(>F)
## education 1 21608 21608 429.55 < 2e-16 ***
## log2(income) 1 3233 3233 64.28 2.3e-12 ***
## women 1 124 124 2.46 0.12
## Residuals 98 4930 50
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1