# Chapter 5 Linear Models

## 5.1 t test

• t.test(DF$CONTINUOUS_VAR ~ DF$FACTOR_VAR) tests the difference between the two levels of the FACTRO_VAR on the CONTINUOUS_VAR
• same results can be obtained with the lm(), aov() and glm()functions with the FACTRO_VAR dummy coded

## 5.2 one-way ANOVA

• model.aov <- aov(DF$CONTINUOUS_VAR ~ DF$FACTOR_VAR) creates an object with the Analysis of Variance estimation and summary(model.AOV) prints the details about the model estimation
• glht()function from the multcomp package can be used to define specific contrasts:
• model.aov.contrasts <- rbind("LEVEL 1 vs 2"=c(-1, 1, 0), "LEVEL 3 vs 1"=c(-1, 0, 1)) specifies the contrasts LEVEL 1 vs 2 and LEVEL 3 vs 1
• summary(glht(aov(DF$CONTINUOUS_VAR ~ DF$FACTOR_VAR), linfct=model.aov.contrasts, alternative="two.sided"), test=adjusted("none")) uses the linfct=model.aov.contrastsargument to input the specified contrast and prints the details about the model estimation
• same results can be obtained with the lm(), aov() and glm()functions with the FACTRO_VAR dummy coded

## 5.4 linear regression

• model.lm <- lm(DF$CONTINUOUS1 ~ DF$CONTINUOUS2) creates an object with the Simple Linear Model estimation and summary(model.lm) prints the details about the model estimation
• model.multi.lm1 <- lm(DF$CONTINUOUS1 ~ DF$CONTINUOUS2 + DF$CONTINUOUS3 + DF$CONTINUOUS4) uses the same logic above but on a Multiple Linear Model with 3 predictors the DF$CONTINUOUS2 and DF$CONTINUOUS3
• model.multi.lm2 <- lm(DF$CONTINUOUS1 ~ DF$CONTINUOUS2 + DF$CONTINUOUS3 + DF$CONTINUOUS4 + DF\$CONTINUOUS5) uses the same logic above but with 5 predictors
• anova(model.multi.lm2, model.multi.lm1) will compare de two models in a Hierarchical Linear Model
• lm.beta(lm()) function prints the details about any Linear Modeling specified but provides information about the standardized estimates (particularly useful for Multiple Linear Models, requires the lm-beta package)