I want to interpolate the dataset below using lognormal distribution in R. As you can see from the data below, I have different land size classes (ha) and I would like to interpolate the data using the standard land size classes I will use for all countries.
This is the original land size classes
| Size classes (ha) | Area of holdings |
|---|---|
| Under 0.8 ha | 18012 |
| 0.8 - 1.6 | 66155 |
| 1.6 - 2.4 | 80224 |
| 2.4 - 3.2 | 61555 |
| 3.2 - 4.0 | 47754 |
| 4.0 - 6.0 | 56234 |
| 6.0 ha and over | 38257 |
| Total holdings | 368191 |
And the standard land sizes which I want to interpolate their data using the data above (area of holdings) are given as:
| size classes (ha) |
|---|
| 0 - 1 |
| 1 - 2 |
| 2 - 3 |
| 3 - 4 |
| 4 - 5 |
| 5 - 10 |
I have performed this calculation in Excel and I would like to create an R function to do this.
The code below is the function I am trying to create.
install.packages("assertthat")
library(assertthat)
interpolation <- function(x, x1, y1,x2, y2)
{
assert_that(is.numeric(x),
isTRUE(all(is.finite(x))),
is.scalar(x1),
is.scalar(y1),
is.scalar(x2),
is.scalar(y2),
x1< x2)
meanlog <- mean(log(y2)
SDlog <- sd(log(y2)
output <- rep(NA_real_, length(x))
output[x <= x1] <- y1
output[x >= x2] <- y2
btwpoints <- which(is.na(output))
output[btwpoints] <- stats::approx(
x = plnorm(c(x1, x2)),
y = c(y1, y2),
xoutput = plnorm(x[btwpoints]), method =
"linear")$y
return(output)
}
I have succeeded in setting up the four coordinates (x1,x2,y1, y2) which represent the lower and upper size classes. I am stuck in setting up the lognormal distribution in the function.

R. – whuber Aug 21 '22 at 16:17