[R] Problem with predict?
Petr PIKAL
petr.pikal at precheza.cz
Wed Jun 20 17:56:23 CEST 2012
Hi
>
> Hello,
>
> I am trying to fit a model to some "death over time" data that does not
> fit the criteria for the usual LD50 type models (the counts are too
> large). I am using a simple linear model in an attempt to plot a nice
line
> on a scatter plot and calculate some LD values to use in designing an
> experiment. Here is the basic idea of what I'm doing:
>
>
> head(mort)
>
> Time Density
> 0 2233333333
> 0 2100000000
> 0 1933333333
> 5 1900000000
> 5 1433333333
> 5 900000000
>
>
> plot(Density~Time)
>
> This plots something that looks a lot like a decay rate
>
> mod<-lm(log(Density)~Time)
>
> xv<-seq(0,60,0.1)
> yv<-exp(predict(mod,list(time=xv)))
>From help page
Usage
## S3 method for class 'lm'
predict(object, newdata, se.fit = FALSE, scale = NULL, df = Inf,
interval = c("none", "confidence", "prediction"),
level = 0.95, type = c("response", "terms"),
terms = NULL, na.action = na.pass,
pred.var = res.var/weights, weights = 1, ...)
Arguments
object Object of class inheriting from "lm"
newdata An optional data frame in which to look for variables with which
to predict. If omitted, the fitted values are used.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
yv<-exp(predict(mod, data.frame(time=xv)))
shall work.
Regards
Petr
> lines(xv,yv)
>
> Everything seems to work fine until I try to plot the lines, but then I
> get the error message:
>
> Error in xy.coords(x, y) : 'x' and 'y' lengths differ
>
> Checking the lengths of x and y confirms that somehow the object yv is
not
> using xv to predict the data, and is only predicting as many data points
> as there are rows in the data frame.
>
> Any ideas on why this might be would be very much appreciated.
>
> Thank you,
>
> Julie
>
>
>
>
>
> [[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.
More information about the R-help
mailing list