[R] Problem with predict?
Peter Ehlers
ehlers at ucalgary.ca
Wed Jun 20 20:26:37 CEST 2012
On 2012-06-20 08:56, Petr PIKAL wrote:
> 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
Using list() instead of data.frame() should work, but
using 'time' instead of 'Time' should give an "object not found"
error, unless there's an object 'time' hanging around in
the workspace.
Peter Ehlers
[...]
More information about the R-help
mailing list