[R] Need help to locate my mistake

From: Louise Hoffman <louise.hoffman_at_gmail.com>
Date: Sun, 02 Mar 2008 21:18:29 +0100


Dear readers

I would like to make General Linear Model (GLM) for the following data set http://louise.hoffman.googlepages.com/fuel.csv

The code I have written is

fuelData<-read.table('fuel.csv',header=TRUE, sep=',') n<-dim(fuelData)[1]
xOnes<- matrix(1,nrow=n,ncol=1)
x<-cbind(xOnes,fuelData[,3])
y<-fuelData[,4]
theta<-((t(x)%*%x)^(-1))%*%t(x)%*%y

which gives

> theta

            [,1]
[1,] 215.8374077
[2,] 0.1083491

When I do it in Matlab I get theta to be 79.69
0.18

which is correct. ~79 is the crossing of the y-axis.

Have I perhaps written theta wrong? The formula for theta is (alpha,beta)^T = (x^T * x)^(-1) * x^T * Y

where ^T means transposed.

Can someone see where the mistake is?

Hugs,
Louise



R-help_at_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. Received on Sun 02 Mar 2008 - 20:22:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 02 Mar 2008 - 21:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive