data("mtcars")
library(lmtest)
fit <- lm(mpg ~ factor(cyl) + wt, mtcars)
fit$coefficients[[3]]
## [1] -6.07086
fit <- lm(mpg ~ factor(cyl) + wt, mtcars)
fitno <- lm(mpg ~ factor(cyl) , mtcars)
fit$coefficients
## (Intercept) factor(cyl)6 factor(cyl)8 wt
## 33.990794 -4.255582 -6.070860 -3.205613
fitno$coefficients
## (Intercept) factor(cyl)6 factor(cyl)8
## 26.663636 -6.920779 -11.563636
fit2 <- lm(mpg ~ factor(cyl) + wt + factor(cyl)*wt, mtcars)
lrtest(fit, fit2)
## Likelihood ratio test
##
## Model 1: mpg ~ factor(cyl) + wt
## Model 2: mpg ~ factor(cyl) + wt + factor(cyl) * wt
## #Df LogLik Df Chisq Pr(>Chisq)
## 1 5 -73.311
## 2 7 -70.741 2 5.1412 0.07649 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#anova(fit1, fit2)
lm(mpg ~ I(wt * 0.5) + factor(cyl), data = mtcars)
##
## Call:
## lm(formula = mpg ~ I(wt * 0.5) + factor(cyl), data = mtcars)
##
## Coefficients:
## (Intercept) I(wt * 0.5) factor(cyl)6 factor(cyl)8
## 33.991 -6.411 -4.256 -6.071
How is the wt coefficient interpretted?
x <- c(0.586, 0.166, -0.042, -0.614, 11.72)
y <- c(0.549, -0.026, -0.127, -0.751, 1.344)
Give the hat diagonal for the most influential point
fit3 <- lm(y~x)
hatvalues(fit3)
## 1 2 3 4 5
## 0.2286650 0.2438146 0.2525027 0.2804443 0.9945734
x <- c(0.586, 0.166, -0.042, -0.614, 11.72)
y <- c(0.549, -0.026, -0.127, -0.751, 1.344)
Give the slope dfbeta for the point with the highest hat value.
fit3 <- lm(y~x)
influence.measures(fit3)
## Influence measures of
## lm(formula = y ~ x) :
##
## dfb.1_ dfb.x dffit cov.r cook.d hat inf
## 1 1.0621 -3.78e-01 1.0679 0.341 2.93e-01 0.229 *
## 2 0.0675 -2.86e-02 0.0675 2.934 3.39e-03 0.244
## 3 -0.0174 7.92e-03 -0.0174 3.007 2.26e-04 0.253 *
## 4 -1.2496 6.73e-01 -1.2557 0.342 3.91e-01 0.280 *
## 5 0.2043 -1.34e+02 -149.7204 0.107 2.70e+02 0.995 *
dfbetas(fit3)
## (Intercept) x
## 1 1.06212391 -0.37811633
## 2 0.06748037 -0.02861769
## 3 -0.01735756 0.00791512
## 4 -1.24958248 0.67253246
## 5 0.20432010 -133.82261293
It is possible for the coefficient to reverse sign after adjustment. For example, it can be strongly significant and positive before adjustment and strongly significant and negative after adjustment.