Analysis of associations between variables: Multiple Linear Regression Analysis

To perform a stepwise multiple linear regression analysis download datafile "Bodymeasures.txt", then recode variable Sex[M,F] into Sex_num[0,1] and make sure the variable is treated as numeric. You can then create a linear regression model with the variables you want, and display it

> Dataset <- read.table("/BodyMeasures.txt", header=TRUE, sep=",", na.strings="NA", dec=".", strip.white=TRUE)
> Dataset$Sex_num[Dataset$Sex=="M"] <- 0
> Dataset$Sex_num[Dataset$Sex=="F"] <- 1

> Dataset$Sex_num <- as.numeric(Dataset$Sex_num)
> fit <- lm(Sex_num~Mass+Fore+Head,data=Dataset)
> fit

Load library MASS (which is likely already pre-installed on your system), perform stepwise model selection by exact AIC, and display the results

> library(MASS)
> step <- stepAIC(fit, direction="both")
> step$anova


last modified: 2/19/13