Hi all, Could you please help me?
I am trying to understand why this line works: lm1x = lm(y~X-1, tmp) Here it seems that I was combining the design matrix and the data frame... And X below is not a single column, in fact, it's a bunch of columns in matrix form... I don't understand why this line works... Is it just luck, i.e. if we change the data-set and/or formulas to something else, this will potentially fail? (that's something I would like to catch and avoid...) Thank you! ------------------------------- The data is located at: http://www.ling.uni-potsdam.de/~vasishth/book.html In the section: downloadable errata, code, datasets ERRATA Corrected Pages VasishthBroebook.R beauty.txt mathachieve.txt mathachschool.txt ------------------------------ MathAchieve <- read.table("mathachieve.txt") colnames(MathAchieve) <- c("School", "Minority", "Sex", "SES", "MathAch", "MEANSES") head(MathAchieve) MathAchSchool <- read.table("mathachschool.txt") colnames(MathAchSchool) <- c("School", "Size", "Sector", "PRACAD", "DISCLIM", "HIMINTY", "MEANSES") MathScores <- merge(MathAchieve, MathAchSchool, by = "School") lm1 = lm(MathAch ~ SES + factor(Sector) , MathScores) X=model.matrix(MathAch ~ SES+factor(Sector) , MathScores) y=MathScores$MathAch tmp=MathScores tmp$y=y tmp$X=X lm1x = lm(y~X-1, tmp) plot(fitted(lm1), fitted(lm1x)) max(abs(fitted(lm1) - fitted(lm1x))) [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.