[R] predict.drm not generating confidence intervals

David Winsemius dwinsemius at comcast.net
Sun Nov 28 23:45:03 CET 2010


I interpreted the to be that predict.drc was expecting a third  
argument,  curveid, which had no default, and that creating a  
dataframe like this was going to solve the problem.

 > newdt <- data.frame( conc= seq(0.2, 9, 0.01) , CURVE=1)
 > prd.p <- predict(fit, newdata=newdt, curveid=CURVE,  
interval="confidence")
 > head(prd.p)
      Prediction    Lower    Upper
[1,]   7.790812 7.400131 8.181492
[2,]   7.790476 7.400161 8.180791
[3,]   7.790106 7.400185 8.180028
[4,]   7.789702 7.400203 8.179202
[5,]   7.789262 7.400213 8.178311
[6,]   7.788784 7.400215 8.177352

-- 
David


On Nov 28, 2010, at 5:19 PM, Peter Ehlers wrote:

> Brant,
> See below.
>
> On 2010-11-28 12:25, David Winsemius wrote:
>> Puzzled. Why are the data you offer to predict() for the independent
>> variable, conc, all NA's? Is there something reversed or inverted
>> about how drc functions handle formulas.
>>
>> -- David. On Nov 28, 2010, at 2:33 PM, Brant Inman wrote:
>>> >  R-helpers,
>>> >
>>> >  I recently submitted a help request for the predict.drm function
>>> >  found in the drc package.  I am still having issues with the
>>> >  function and I am submitting reproducible code hoping that  
>>> somebody
>>> >  can help me figure out what is going on.
>>> >
>>> >  --------
>>> >  library(drc)
>>> >
>>> >  # Fit a 4 parameter logistic model to ryegrass dataset
>>> >  fit<- drm(rootl ~ conc, data = ryegrass, fct = LL.4())
>>> >  summary(fit)
>>> >
>>> >  # Generate a fake dataset for prediction
>>> >  newdt<- data.frame( matrix(c(seq(0.2, 9, 0.01), rep(NA,881)),
>>> >  ncol=2))
>>> >  	colnames(newdt)<- c('rootl', 'conc')
>>> >
>>> >  # Generate prediction intervals and confidence intervals
>>> >  prd.p<- predict(fit, newdata=newdt, interval='prediction')
>>> >  prd.c<- predict(fit, newdata=newdt, interval='confidence')
>>> >
>>> >  # Check output
>>>> >>  head(prd.p)
>>> >       Prediction Lower Upper
>>> >  [1,]   7.790812    NA    NA
>>> >  [2,]   7.790476    NA    NA
>>> >  [3,]   7.790106    NA    NA
>>> >  [4,]   7.789702    NA    NA
>>> >  [5,]   7.789262    NA    NA
>>> >  [6,]   7.788784    NA    NA
>>> >
>>>> >>  head(prd.c)
>>> >       Prediction Lower Upper
>>> >  [1,]   7.790812    NA    NA
>>> >  [2,]   7.790476    NA    NA
>>> >  [3,]   7.790106    NA    NA
>>> >  [4,]   7.789702    NA    NA
>>> >  [5,]   7.789262    NA    NA
>>> >  [6,]   7.788784    NA    NA
>>> >
>>> >  --------
>>> >
>>> >  There appears to be a problem with the predict.drc function.   
>>> This
>>> >  code previous generated confidence and prediction intervals in
>>> >  columns 2 and 3 of the prediction matrices but now fails for  
>>> reasons
>>> >  unknown to me.  Anyone have an idea of what is going on and how I
>>> >  can remedy the situation?
>
> As David points out, you seem to have your dose and response
> mixed up. But even assuming that you mean to predict rootl
> from conc, the predict.drc function needs to be used in a
> certain way (and that is not clear in the documentation).
>
> Try this:
>
> fit <- drm(rootl ~ conc, data = ryegrass, fct = LL.4())
> newdat <- data.frame(conc = seq(0, 30, len=101), apples=1)
> ypred <- predict(fit, newdata=newdat, interval="confidence")
> head(ypred, 3)
>
>     Prediction    Lower    Upper
> [1,]   7.792958 7.399614 8.186303
> [2,]   7.785771 7.400046 8.171495
> [3,]   7.736545 7.380584 8.092505
>
> Wondering about the 'apples'? That's just to show that
> predict.drc doesn't care what you call your second column.
> It seems that predict.drc requires either *no* newdata
> or a *two*-variable data.frame in which the first column
> (it, too, can have *any* name) contains the dose at which
> to predict and the second column contains the 'curveid',
> aka the grouping variable (if you have one). In your
> case, the grouping reduces to a single group, i.e. a
> vector of all '1's.
>
> This could all be made considerably clearer in the documentation.
>
> Peter Ehlers
>
>>> >
>>> >  Brant Inman
>>> >

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list