Hello, I am trying to learn how to perform Multiple Regression Analysis in R. I decided to take a simple example given in this PDF: http://www.utdallas.edu/~herve/abdi-prc-pretty.pdf
I created a small CSV called, students.csv that contains the following data: s1 14 4 1 s2 23 4 2 s3 30 7 2 s4 50 7 4 s5 39 10 3 s6 67 10 6 Col headers: Student id, Memory span(Y), age(X1), speech rate(X2) Now the expected results are: yHat[0]:15.166666666666668 yHat[1]:24.666666666666668 yHat[2]:27.666666666666664 yHat[3]:46.666666666666664 yHat[4]:40.166666666666664 yHat[5]:68.66666666666667 This is based on the following equation (given in the PDF): Y = 1.67 + X1 + 9.50 X2 I ran the following commands in R: data = read.table("students.csv", head=F, as.is=T, na.string=".", row.nam=NULL) X1 = as.factor(data[[3]]) X2 = as.factor(data[[4]]) Y = data[[2]] mod = lm(Y ~ X1*X2, na.action = na.exclude) Y.hat = fitted(mod) Y.hat This gives me the following output: > Y.hat 1 2 3 4 5 6 14 23 30 50 39 67 Obviously I am doing something wrong. Please help. Thanks. [[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.