[R] Need help to locate my mistake
Louise Hoffman
louise.hoffman at gmail.com
Mon Mar 3 00:46:29 CET 2008
> This is certainly ***NOT*** correct. (If you really got those numbers
> from Matlab, then Matlab is up to Puttee.)
It was my mistake =) I had calculated the straight line so the edge of
the plot was the y-axis =)
> Have you plotted your data?
>
> (1) Fitting a straight line is ridiculous.
Yes, I guess we have to realise that in the project, and explain why
it is not good enough =) Next step is to use exponential smoothing =)
> (2) If you are so foolish as to fit a straight line, you get
> theta to have entries -4197.96 (intercept) and 2.16 (slope).
> The line y = 79.69 + 0.18*x is off the edge of the graph and
> does not even appear.
It was clearly a bad mistake of mine! =(
> Yes. The expression (t(x)%*%x)^(-1) is the matrix of entry
> by entry reciprocals of the entries of t(x)%*%x.
>
> You want:
>
> theta <- solve(t(x)%*%x))%*%t(x)%*%y
Thanks =)
> Anyhow, if you're going to use R, why not ***use R***?
>
> fit <- lm(fpi ~ rtime,data=fuelData)
> theta <- coef(fit)
>
> This gives an answer identical to that from the corrected version of
> your ``from scratch'' expression. (That expression, while
> theoretically
> correct, is numerically ill-advised. The cognoscenti use either the
> Choleski or the ``qr'' decomposition of t(x)%*%x to effect the
> calculations.
This is great stuff!
More information about the R-help
mailing list