The akima package has a problematic license (it doesn't allow commercial use), so it's been recommended that people use the interp package instead. When I use interp::interp instead of akima::interp, I get reasonable output from your example.

So that's another reason to drop akima...

Duncan Murdoch

On 26/01/2023 9:35 a.m., PIKAL Petr wrote:
Dear all

I have this table
dput(mat)
mat <- structure(c(2, 16, 9, 2, 16, 1, 1, 4, 7, 7, 44.52, 42.8, 43.54,
40.26, 40.09), dim = c(5L, 3L))

And I want to calculate result for contour or image plots as I did few years
ago.

However interp does not compute the z values and gives me zeros in z matrix.
library(akima)

interp(mat[,1], mat[,2], mat[, 3], nx=5, ny=5)
$x
[1]  2.0  5.5  9.0 12.5 16.0

$y
[1] 1.0 2.5 4.0 5.5 7.0

$z
      [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    0    0
[2,]    0    0    0    0    0
[3,]    0    0    0    0    0
[4,]    0    0    0    0    0
[5,]    0    0    0    0    0

With the example from help page if less than 10 values are used, the result
is also zero
interp(akima$x[1:9], akima$y[1:9], akima$z[1:9], nx=5, ny=5)

but with 10 or more values the result is correctly calculated
interp(akima$x[1:10], akima$y[1:10], akima$z[1:10], nx=5, ny=5)
$x
[1]  0.0000  6.1625 12.3250 18.4875 24.6500

$y
[1]  1.24  5.93 10.62 15.31 20.00

$z
      [,1]     [,2]     [,3]     [,4]     [,5]
[1,]   NA       NA       NA       NA 34.60000
[2,]   NA       NA 27.29139 27.11807 26.60971
[3,]   NA 19.81371 19.63614 19.12778 18.61943
[4,]   NA 14.01443 10.66531 11.13750 10.62914
[5,]   NA       NA       NA       NA       NA

Help page says
x, y, and z must be the same length (execpt if x is a
SpatialPointsDataFrame) and may contain no fewer than ***four*** points.

So my understanding was that 5 poins could be used but I am obviously wrong.
Is it a bug in interp or in the documentation or is it my poor understanding
of the whole matter.

Best regards
Petr


______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to