From 7f10c6e43aa584b8599cced6dfef951b461efb45 Mon Sep 17 00:00:00 2001 From: octopacks Date: Thu, 5 Apr 2018 11:07:55 +0530 Subject: [PATCH] small correction in code In the Swiss data model fitting, output from the lm function was assigned to the object "fit1". In the next line of code fit2 was created by using the update function on the object "fit", which does not exist. Changed the object "fit" to "fit1" --- 07_RegressionModels/02_05_multipleVariables/index.Rmd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/07_RegressionModels/02_05_multipleVariables/index.Rmd b/07_RegressionModels/02_05_multipleVariables/index.Rmd index 043b7dbf3..a1a3c02b2 100644 --- a/07_RegressionModels/02_05_multipleVariables/index.Rmd +++ b/07_RegressionModels/02_05_multipleVariables/index.Rmd @@ -134,8 +134,8 @@ temp <- apply(betas, 1, var); temp[2 : 3] / temp[1] data(swiss); fit1 <- lm(Fertility ~ Agriculture, data = swiss) a <- summary(fit1)$cov.unscaled[2,2] -fit2 <- update(fit, Fertility ~ Agriculture + Examination) -fit3 <- update(fit, Fertility ~ Agriculture + Examination + Education) +fit2 <- update(fit1, Fertility ~ Agriculture + Examination) +fit3 <- update(fit1, Fertility ~ Agriculture + Examination + Education) c(summary(fit2)$cov.unscaled[2,2], summary(fit3)$cov.unscaled[2,2]) / a ``` @@ -170,7 +170,7 @@ sqrt(vif(fit)) #I prefer sd ## How to do nested model testing in R ```{r} fit1 <- lm(Fertility ~ Agriculture, data = swiss) -fit3 <- update(fit, Fertility ~ Agriculture + Examination + Education) -fit5 <- update(fit, Fertility ~ Agriculture + Examination + Education + Catholic + Infant.Mortality) +fit3 <- update(fit1, Fertility ~ Agriculture + Examination + Education) +fit5 <- update(fit1, Fertility ~ Agriculture + Examination + Education + Catholic + Infant.Mortality) anova(fit1, fit3, fit5) ```