Hi,
Try this:
# using the iris dataset
mydat <- iris
mymodel <- lm(Sepal.Length ~ Petal.Length + Species, data = mydat)
summary(mymodel)
newdat <- data.frame(Petal.Length = seq(1, 10, by = .1),
Species = factor(rep("virginica", 91)))
results <- predict(object = mymodel, newdata = newdat, se.fit = TRUE)
results
The main lesson is that generally newdata should be a data frame with
columns that have the same name as the predictors (IVs) in your model.
I'm not exactly sure what you mean by "variance of dependent variable
based on model". Do you want its total variance, residual variance,
_______ ?
Cheers,
Josh
On Mon, Sep 27, 2010 at 12:58 PM, Yi Du <abraham.du at gmail.com>
wrote:> Hi folks,
>
> I use lm to run regression and I don't know how to predict dependent
> variable based on the model.
>
> I used predict.lm(model, newdata=80), but it gave me warnings.
>
> Also, how can I get the variance of dependent variable based on model.
> Thanks.
>
> ? ? ? ?[[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
http://www.joshuawiley.com/