I need to calculate values that are dependent on other values in their vicinity. Their location is known. In the given case the values are temepratures. Consider a standup freezer (aproximately 1m x 1m x 2m (width x depth x height)) whose temperature was measured at 15 points:
- top level (=5): 5 points, oriented as a square with a center point
- middle level (=3): 5 points, oriented as a 4 point star with a center point (i.e. the square is rotated by 45°)
- lowest level (=1): 5 points, oriented as a square with a center point So each point has 3 coordinates: x (1-5), y (1-5) and z (1,5). And each of the 15 points has a temperature as its value, e.g. -19.51°C. Now considering an article lay at position 2,2,5 (x, y, z), what was the temperature like at that postion?
Here is an example how the data may look like:
structure(list(x = c(1, 1, 3, 5, 5, 1, 3, 3, 3, 5, 1, 1, 3, 5,
5), y = c(1, 5, 3, 1, 5, 3, 1, 3, 5, 3, 1, 5, 3, 1, 5), z = c(5,
5, 5, 5, 5, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1), T_.C = c(-20.750182521983,
-19.04687, -19.5861606555542, -20.5691695760194, -20.6176610127199,
-16.4671828378447, -16.5713893044039, -23.6506737064773, -19.9124349790261,
-23.7875255615229, -26.0653073705183, -20.2412939002774, -21.0219350609566,
-21.8749485590661, -23.805990645601)), row.names = c("1", "2",
"21", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14"), class = "data.frame")
I looked into oce approx3d and pick.from.points in RSAGA. With apporx3d I was not able to wrap my head around, while with pick.from.points I was able to do lookup of nearest neighbour like so:
toKnow <- as.data.frame(list(x=2,y=2,z=2))
pick.from.points(data=toKnow, src=myresults, pick=c("T_.C"), method="nearest.neighbour")
x y z T_.C
1 2 2 2 -19.58616
However, "kriging" for calculating the missing value did not work:
pick.from.points(data=toKnow, src=myresults, pick=c("T_.C"), method="krige")
[using ordinary kriging]
x y z T_.C
1 2 2 2 NA
Warnmeldung:
In predict.gstat(g, newdata = newdata, block = block, nsim = nsim, :
Covariance matrix singular at location [2,2,0]: skipping...
Questions:
- Did I try a valid approach?
- What was wrong with the attempt? E.g. wrong function call?
- Was the dataset not suitable?
- Are there other (better suited) approaches?
Hint:
- measurement points are equally spaced but yet unknown locations and their values may not be equally spaced
Thank you so much!
Haven't tried to do this in R for a while, but the
GauPropackage seems to be actively maintained and easy to use.Given you said your temperatures are just random values I'm tempted to ensure there's some structure in there. Given your structure saved in
x, I'd do:to have temperatures in the "middle" (i.e. x,y,z = 3) have a temperature of -20 and distances further out get higher.
This can be fit, model summary info printed, and predictions displayed via:
This seems to do the right thing for me, in that predictions at the center coming near
-20while nearer the edge (x,y,z = 1.5) come out near the true value of18.7.