[R] Linear model and approx function

javad bayat j@b@y@t194 @end|ng |rom gm@||@com
Sat Dec 9 19:50:18 CET 2023


Dear all;

I have a dataframe with several columns. The columns are the elevation,
volume  and the area of the cells (which were placed inside a polygon). I
have extracted them from DEM raster to calculate the volume under polygon
and the elevation for a specific volume of the reservoir.

> head(x6,2)
  Elevation       Vol      Area     V_sum      A_sum
1 2145  13990.38  85.83053  13990.38   85.83053
2 2147  43129.18 267.88312  57119.56  353.71365

> tail(x6,2)
 Elevation      Vol      Area      V_sum    A_sum
158  2307 233.0276 233.02756 1771806968 15172603
159  2308   0.0000  71.65642 1771806968 15172674

I used a linear model to estimate the elevation for a specific volume, but
the codes do not work properly.

lm1 = lm(x6[,1]~x6[,4])
new_volume <- 3,000,000,000
pred_elev <- predict(lm1, newdata = data.frame(volume = new_volume))
pred_elev

The results just estimated for the 159 rows of the dataframe, not the new
volume.

> tail(pred_elev)
     154      155      156      157      158      159
2254.296 2254.296 2254.296 2254.296 2254.296 2254.296

Also I have used the approx function, but it does not work for the new
volume, too.

> a = x6[,1]
> b = x6[,4]
> estimate <- 3,000,000,000
> appro <- approx(b,a, xout = estimate)
> appro
$x
[1] 3e+09

$y
[1] NA

I do not know why it has happened.

Is there any way to do this?
Or maybe there is another way to do that.
I would be more than happy if anyone help me.

Sincerely

	[[alternative HTML version deleted]]



More information about the R-help mailing list