Search code examples
rscatter3d

How to find confidence interval in 3d plots in cran R?


I have this 3d plot that I draw in cran R

rb = rep(seq(0.1, 1, 0.1), 10)
ro = sort(rb)
lods = runif(100) #create a random LOD score

library(scatterplot3d)
lodsplot<- scatterplot3d(rb, ro, lods)

I found the maximum of the LOD score using max(lods) and thus, find the respective rb and ro. Now, I want to find the 95% CI of rb and ro. Assume max(lods) = 0.8 and respective rb and ro are 0.2 and 0.3, I thought of drawing a plane using:

lodsplot$plane3d(c(0.2, 0.3, 0.8))

and then find points above the plane (which I don't know how to do). Am I thinking correctly? Thank you!

Note:

If I just do a 2d plot, this is how i would do it:

plot(rb, lods, type = "l)
which(lods == max(lods))
limit = max(lods) - 1.92
abline(h = limit)
#Find intersect points:
above <- lr > limit
intersect.points <- which(diff(above) != 0)



    

Solution

  • You need to find the points that are above your plane defining the hypothesized 95% upper bound which you are suggesting has the equation:

     lods = 0.2+ 0.3*rb+ 0.8*ro
    

    So calculate the item numbers for the points satisfying the implicit inequality:

    high <- which(lods > 0.2+ 0.3*rb+ 0.8*ro)
    

    And plot:

    png()
    lodsplot<- scatterplot3d(rb, ro, lods)
    high <- which(lods > 0.2+ 0.3*rb+ 0.8*ro)
    lodsplot$plane3d(c(0.2, 0.3, 0.8))
    lodsplot$points3d( rb[high], ro[high], lods[high], col="red"); dev.off()
    

    enter image description here

    Notice that the plane3d function in scatterplot3d also accepts a result from lm or glm, so you could first calculate a model where lods ~ rb +ro and then calculate a 95% prediction surface using predict( ..., type="response") and color the points using this method. See: predict and multiplicative variables / interaction terms in probit regressions for a worked example on an equivalent procedure on an admittedly more complex model.

    You can also do a search on [r] prediction surface and find other potentially useful answers such as this BenBolker suggestion to use rgl: "A: scatterplot3d for Response Surface in R"