aboutsummaryrefslogblamecommitdiff
path: root/R/lod.R
blob: 6562c04d0bf262e563cf16178e5fed6972d60d01 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                                                                          



                  

                                                               



                                                            
                                                                             

                    




                                                                    



                                                      
lod <- function(object, ..., alpha = 0.05, beta = 0.05, n = 1, w = "auto")
{
  UseMethod("lod")
}

lod.default <- function(object, ..., alpha = 0.05, beta = 0.05,
  n = 1, w = "auto")
{
  stop("lod is only implemented for univariate lm objects.")
}

lod.lm <- function(object, ..., alpha = 0.05, beta = 0.05, n = 1, w = "auto")
{
  f <- function(x) {
    y1 <- predict(object, data.frame(x = 0), interval="prediction", 
      level = 1 - alpha)
    y2 <- predict(object, data.frame(x = x), interval="prediction",
      level = 1 - beta)
    (y2[[1,"lwr"]] - y1[[1,"upr"]])^2
  }
  tmp <- optimize(f,interval=c(0,max(object$model$x)))
  return(tmp$minimum)
}

Contact - Imprint