Re: [R] Linear model and approx function

2023-12-09 Thread Bert Gunter
1. You should regress Elevation on Volume, no?

2. You are calling lm incorrectly for prediction. Please read ?lm and
related links carefully and/or consult a tutorial. R-Help is really not the
first place you should look for this sort of detailed info.

3. I think this is what you want:

lm1 <- lm(Elevation ~ Vol, data = x6)  ## assuming (1) above is correct
d <- data.frame(Vol = 3000)  ## assuming (1) above is correct
predict(lm1, newdata = d)

Cheers,
Bert


On Sat, Dec 9, 2023 at 10:50 AM javad bayat  wrote:

> 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_sumA_sum
> 158  2307 233.0276 233.02756 1771806968 15172603
> 159  2308   0.  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]]
>
> __
> 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.
>

[[alternative HTML version deleted]]

__
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] Linear model and approx function

2023-12-09 Thread javad bayat
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_sumA_sum
158  2307 233.0276 233.02756 1771806968 15172603
159  2308   0.  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]]

__
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.