Message-ID: <CABdHhvE2fmcoGZmq3pFWUj4wTj+yPSn_BMXfBT3FoM7WNfE--A@mail.gmail.com>
Date: 2013-03-21T15:55:11Z
From: Hadley Wickham
Subject: [Rcpp-devel] [rcpp-devel] Rcpp Gallery Example fastLm vs R native lm
In-Reply-To: <FA07C4306DEF5743AC1DB451680DFF590FC22D06@MKEXCHVS4.Mail.Fiserv.net>
On Thu, Mar 21, 2013 at 10:44 AM, Smith, Dale <Dale.Smith at fiserv.com> wrote:
> I have a question about the fastLm example in the Gallery
> http://gallery.rcpp.org/articles/fast-linear-model-with-armadillo/. I put
> the code directly into my package (after renaming it fastLmProto so I don?t
> mask the RcppArmadillo function by the same name). After building the
> package, I wanted to compare results:
>
>
>
>> require(datasets)
>
>> coef(lm(y1 ~ x1, data = anscombe))
>
> (Intercept) x1
>
> 3.0000909 0.5000909
>
>> coef(fastLmProto(anscombe$y1, as.matrix(anscombe$x1)))
>
> [,1]
>
> [1,] 0.7968032
>
>> coef(fastLm(anscombe$y1, as.matrix(anscombe$x1)))
>
> [1] 1.208169
>
>
>
> Should I expect the results to match? Why do fastLmProto and fastLm produce
> a single fitted parameter (I would expect two)? Why are they different? Am I
> doing something wrong here, or just being na?ve in my assumptions?
Hint:
> coef(lm(y1 ~ x1 - 1, data = anscombe))
x1
0.7968032
Hadley
--
Chief Scientist, RStudio
http://had.co.nz/