[R] Lm gives different results depending on x-bit architecture

Uwe Ligges ligges at statistik.tu-dortmund.de
Mon Aug 29 17:04:53 CEST 2011



On 29.08.2011 13:54, AdamMarczak wrote:
> Dear all,
>
> I have encountered problem when developing application. My linear regression
> does give different results depending on architecture.
>
> Following example describes my problem perfectly.
>
>      xxx<- data.frame(a=c(0.2,0.2,0.2,0.2,0.2),b=c(7,8,9,10,11))
>      lm(a~b,xxx)
>      summary(lm(a~b,xxx))$r.squared
>
> returns on 32-bit R:
>
>      Call:
>      lm(formula = a ~ b, data = xxx)
>
>      Coefficients:
>      (Intercept)            b
>        2.000e-01   -1.503e-18
>
>      >summary(lm(a~b,xxx))$r.squared
>      [1] 0
>
> and on 64-bit R:
>
>      Call:
>      lm(formula = a ~ b, data = xxx)
>
>      Coefficients:
>      (Intercept)            b
>         2.0e-01             0
>
>      >summary(lm(a~b,xxx))$r.squared
>      [1] NA
>
> It is very easy to notice slope should be 0 in the above case. I also
> understand it is related to the precision of 32 and 64 bit

Not necessarily, since the same precision is used by R. It may even be 
the result of using different compilers (or just compiler versions) for 
producing the 32-bit and the 64-bit version.

> and dependant on
> how those are internally written, but maybe someone had this problem and
> found any solution.

If you want to see if b is numerically equal to zero, use all.equal().

Uwe Ligges


>
> With regards,
> Adam.
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Lm-gives-different-results-depending-on-x-bit-architecture-tp3776027p3776027.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.



More information about the R-help mailing list