[R] How to predict the mean and variance of the dependent variable after regression
Joshua Wiley
jwiley.psych at gmail.com
Mon Jun 21 20:34:28 CEST 2010
Hello,
If you just want the mean and variance of log(y) try:
mean(log(y))
var(log(y))
if there is missing data, you can add na.rm=TRUE to both of those. If
you want the mean and variance of the predicted ys
mean(predict(linmod))
var(predict(linmod))
see
?mean
?var
?predict.lm #the specific method being used for predict() with model
objects of class lm
HTH,
Josh
On Mon, Jun 21, 2010 at 11:24 AM, Yi <liuyi.feier at gmail.com> wrote:
> Hi, folks,
>
> As seen in the following codes:
>
> x1=rlnorm(10)
> x2=rlnorm(10,mean=2)
> y=rlnorm(10,mean=10)### Fake dataset
> linmod=lm(log(y)~log(x1)+log(x2))
>
> After the regression, I would like to know the mean of y. Since log(y) is
> normal and y is lognormal, I need to know the mean and variance of log(y)
> first. I tried mean (y) and mean(linmod), but either one is what I want.
>
> Any tips?
>
> Thanks in advance!
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
--
Joshua Wiley
Ph.D. Student
Health Psychology
University of California, Los Angeles
More information about the R-help
mailing list