Hi:

On Wed, Jul 21, 2010 at 2:29 PM, Yi <liuyi.fe...@gmail.com> wrote:

> Hi, folks,
>
> Here are the codes:
>
> ##############
> y=1:10
> x=c(1:9,1)
> lin=lm(log(y)~x)  ### log(y) is following Normal distribution
> x=5:14
> prediction=predict(lin,newdata=x)  ##prediction=predict(lin)
> ###############
>

predict() needs a *data.frame* as the argument of newdata:

> d <- data.frame(x)
> prediction=predict(lin,newdata=d)
> prediction
       1        2        3        4        5        6        7        8
1.574308 1.733976 1.893643 2.053311 2.212979 2.372646 2.532314 2.691981
       9       10
2.851649 3.011316

1. The codes do not work, and give the error message: Error in
> eval(predvars, data, env) :
>  numeric 'envir' arg not of length one.  But if I use the code after the
> pound sign, it works. I mean the name of the newdata is x, why it does not
> work though?
>
>
> 2. Because the prediction is conducted for log(y). I need to get the
> expected value of y, which is LN distribution, for the new data sets. I
> need
> to know the expectation of log(y) and variance of log(y).
>
> #####
> mean=mean(prediction)
> sd=sd(prediction)
> mean_y=exp(mean+0.5*sd^2) ### formula from Normal to LN
> ######
>
> Is sd(prediction) the correct why to calculate the sigma of the prediction?
> Or should I just use the value of Residual standard error from
> summary(lin)?
>

The prediction variance is not the same as the residual variance; consult
your regression text. Which expected value do you want to transform: the
response, or the predicted response? Since the lognormal mean depends on
both the normal mean and variance, this is not an idle question.

HTH,
Dennis

>
> Answer to either question will be appreciated!
>
> Thanks
>
> Yi
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to