2

I am trying to use R to interpolate a response value v from irregularly placed 3-dimensional treatments x, y, z. In this case, I have 50 unique 3-dimensional points (treatments in my experiment), and one response variable. I have one value of v for each of the 50 points, but I want to interpolate the response between these 50 points. From my understanding, many interpolation codes like contour() need regularly spaced data, but my treatments are not at all regularly spaced in the 3D space.

the real data frame looks like this:

head(df)  

  x      y        z       v     
14.200 27.20250 8.057316 2.427  
13.675 37.98000 7.874447 1.740   
13.700 24.64750 7.760348 3.637   
13.800 32.93833 7.711711 2.175   
13.775 30.17500 8.040487 2.498   
14.125 18.65750 7.658253 3.246  

down to row 50. I have already used ploy_ly() to create a 3D scatter plot colored by v, but I want to interpolate into a functional response shape or 3D contour plot of sorts to fill in the spaces between points. This also means I'll have to color it with transparent colors, or contour plot in slices or something. Any ideas?

Reproducible dataset code:

df:

df <- data.frame(matrix(ncol = 4,nrow=50))
colnames(df) <- c("x", "y", "z","v")
set.seed(5)
df$x <- rep(1:25, each=2)
df$y <- sample(40, size = nrow(df), replace = TRUE)
df$z <- sample(30, size = nrow(df), replace = TRUE)
df$v <- c(c(1:25),c(25:1))

3D plot:

install.packages("plotly")
library(plotly)
plot_ly(x=df$x, y=df$y, z=df$z, type="scatter3d", mode="markers",color=df$v)%>%
  layout(
    scene = list(
      xaxis = list(title = "X"),
      yaxis = list(title = "Y"),
      zaxis = list(title = "Z")))

Thanks!

Jake L
  • 987
  • 9
  • 21
  • similar (no solution): https://stackoverflow.com/questions/34919891/r-how-to-use-approx-in-more-than-one-dimension-multidimensional-interpolation – Ben Bolker Feb 27 '19 at 02:04
  • 1
    this might be it: https://stats.stackexchange.com/questions/13510/fitting-multivariate-natural-cubic-spline – Ben Bolker Feb 27 '19 at 02:05

0 Answers0