[R] Error in lm() with very small (close to zero) regressor
peter dalgaard
pdalgd at gmail.com
Sat Mar 28 16:33:23 CET 2015
> On 28 Mar 2015, at 00:32 , RiGui <raluca.gui at business.uzh.ch> wrote:
>
> Hello everybody,
>
> I have encountered the following problem with lm():
>
> When running lm() with a regressor close to zero - of the order e-10, the
> value of the estimate is of huge absolute value , of order millions.
>
> However, if I write the formula of the OLS estimator, in matrix notation:
> pseudoinverse(t(X)*X) * t(X) * y , the results are correct, meaning the
> estimate has value 0.
>
> here is the code:
>
> y <- rnorm(n_obs, 10,2.89)
> x1 <- rnorm(n_obs, 0.00000000000001235657,0.000000000000000045)
> x2 <- rnorm(n_obs, 10,3.21)
> X <- cbind(x1,x2)
>
> bFE <- lm(y ~ x1 + x2)
> bFE
>
> bOLS <- pseudoinverse(t(X) %*% X) %*% t(X) %*% y
> bOLS
>
>
> Note: I am applying a deviation from the mean projection to the data, that
> is why I have some regressors with such small values.
>
> Thank you for any help!
>
> Raluca
>
Example not reproducible:
> y <- rnorm(n_obs, 10,2.89)
Error in rnorm(n_obs, 10, 2.89) : object 'n_obs' not found
> x1 <- rnorm(n_obs, 0.00000000000001235657,0.000000000000000045)
Error in rnorm(n_obs, 1.235657e-14, 4.5e-17) : object 'n_obs' not found
> x2 <- rnorm(n_obs, 10,3.21)
Error in rnorm(n_obs, 10, 3.21) : object 'n_obs' not found
> X <- cbind(x1,x2)
Error in cbind(x1, x2) : object 'x1' not found
>
> bFE <- lm(y ~ x1 + x2)
Error in eval(expr, envir, enclos) : object 'y' not found
> bFE
Error: object 'bFE' not found
>
> bOLS <- pseudoinverse(t(X) %*% X) %*% t(X) %*% y
Error: could not find function "pseudoinverse"
> bOLS
Error: object 'bOLS' not found
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list