HARPgroup / WUDR

0 stars 0 forks source link

Regression #16

Open laljeet opened 2 years ago

laljeet commented 2 years ago

Predictor Variables:

  1. Mean, max, Min Temperature
  2. Extreme temp days (Above 30 degrees C)
  3. PPT
  4. Number of dry days
  5. Gini Coeff
  6. Shannon Diversity Index

Response Variable:

Could be any of

  1. DEQ_Irrigation_withdrawals (Currently exploring) If meteorology affects reporting
  2. Unreported withdrawals
  3. All withdrawals

Equation used (confirm with Dr.Shortridge) :

_lmm2 <- lmer(DEQ_Irrigation_withdrawals ~ PPT + Irrigation+Min_Temp+Mean_Temp+Max_Temp+Zero_PPT_days+ Extremedays+SDI+GC+(1+YEAR|COUNTYFP), data=dat2, REML = FALSE)

The effect of YEAR will vary between COUNTYFP. Random intercepts for YEAR, random slopes for COUNTYFP influenced by YEAR.??

image

rburghol commented 2 years ago

@laljeet is the DEQ irrigation here the one normalized by median historic withdrawal? Is it by county total? Thanks!

laljeet commented 2 years ago

In the above equation (lmer), it is by county. No transformations.

rburghol commented 2 years ago

Cool. Can we see a plot of this? Can we test for leverage of big or small values?

laljeet commented 2 years ago

Log Transformation of Response variables

Log_transformed

Correlation plot for predictor variables.

Irrigation and precip are correlated, which is expected.

correlation

The same is confirmed by VIF.

vif.mer(lmm2) lmm2 here is: lmer(log(Total_irrigation_withdarwals_calculated) ~ PPT + Irrigation+Min_Temp+Mean_Temp+Max_Temp+Zero_PPT_days+ Extreme_days+SDI+GC+(YEAR|COUNTYFP), data=dat2)

image

rburghol commented 2 years ago

Thanks for sharing this.

laljeet commented 2 years ago

DEQ Reported vs predicted

image

julieshortridge commented 2 years ago

Model form comparison - as a best practice, we should use an AIC criteria (I believe you can either do this within lme4 or the MuMin package) to investigate model form and eliminate unnecessary variables. Model forms to compare:

Do this for the Total Withdrawals and VDEQ Reported models. We'll mainly use the VDEQ reported results but should keep total just so we're consistent with what we scoped to USGS. We don't need to do the full scatterplot visualization and variable significance test for each form, but as a first step just create a table showing AIC values for each combination of parameters (all, 4, 2, and 1) and response variable (total and VDEQ reported withdrawals)

We can also test forms where we replace log(W) as the response variable with (W_obs)/(W_mean), where W_mean is the long-term average value for a county. In this case, we probably can replace the mixed effects model form with a simple OLS regression because all of the intercept terms would be equal to 1.

rburghol commented 2 years ago

Thanks for laying these out @julieshortridge -- @laljeet I can't recall if you were computing deficit on the same rolling 2-day window as effective precip, or aggregating it seasonally. Or did you do a variation of Irr where you're adding daily deficit? If so, it can quite possibly be different math.

FWIW, daily adding is certainly more appropriate imo in that if plants get no precip for 6 weeks then double precip for 3 weeks they won't make up that deficit.

As I mentioned in the meeting, my preference would simply be to accumulate running total (ET-rain) and then have the irrigation facilities pump that value. To elaborate, I think the model would work best if we accumulate deficit on a 3-7 day frequency (for computing total), and have irrigators pump 1-2 days per week. This may or may not fit well with this approach but I wanted to lay out more detail on how I think of that process.

laljeet commented 2 years ago

Regression Parameters: Based on VIF (VIF < 3) for DEQ and Total WIthdarwals model Parameters selected:

  1. PPT
  2. Min_Temp
  3. Zero_PPT_days
  4. Extreme_days
  5. SDI
  6. GC

Selection of best model using AIC (lower AIC better model) Five models were used (mentioned by Dr.Shortridge above) (T min was used instead of Tmax)

Using builtin AIC command: Model 2 using four parameters gave the best results.

<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">

  | df | AIC -- | -- | -- Deq_withdrawals_model1 | 12 | 3329.54 **Deq_withdrawals_model2 | 10 | 3326.949** Deq_withdrawals_model3 | 8 | 3356.182 Deq_withdrawals_model4 | 7 | 3412.221 Deq_withdrawals_model5 | 7 | 3412.144

Total Withdrawals Model:

<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">

  | df | AIC -- | -- | -- Total_Withdrawals_Model_1 | 12 | 2641.302 **Total_Withdrawals_Model_2 | 10 | 2623.623** Total_Withdrawals_Model_3 | 8 | 2748.969 Total_Withdrawals_Model_4 | 7 | 2885.136 Total_Withdrawals_Model_5 | 7 | 2884.645

Also, I tried the dropt1 command it highlights the significant terms but doesn't provide AIC values. The significant model is the same four-parameter model.

image

I also found another function in lmerTest that uses backward reduction: Here, the best-selected model was (Four parameter model without the random effect of (1|County) log(DEQ_Irrigation_withdrawals) ~ PPT + Min_Temp + Zero_PPT_days + Extreme_days + (YEAR | COUNTYFP)

image

laljeet commented 2 years ago

Normalized model: I normalized DEQ withdrawals with long-term county averages The same model parameters were used for the normalized model: glm(Norm_DEQ_withdarwals ~ PPT +Min_Temp+Zero_PPT_days+ Extreme_days+SDI+GC, data=dat2)

used stepwise elimination for best fit Best fit model:

Norm_DEQ_withdarwals ~ PPT + Min_Temp + Extreme_days + GC

image

Modeled withdrawals over predicts in this case: image

laljeet commented 2 years ago

@rburghol Currently, here and before, we are using the crop water demand for the whole cropping season. We did look into it, but we didn't change methodology for the calculation of unreported withdrawals.

julieshortridge commented 2 years ago

Thanks Lal, and good work on the variable selection piece. To compare the lmer and normalized models, I'd suggest calculating an R2 value for each using the withdrawal values in MG (ie, don't calculate on the log values or the normalized values, and don't use the R2 values from the lmer or glm output directly). That will be a good complement to the scatterplots. Rob, thank you for clarifying what you were thinking regarding the accumulating deficit. I see what you're saying now, and you're right that if deficit is calculated that way, it wouldn't just be a linear transformation of rainfall. I can see what you're saying about that being a better estimate of actual growing season water demand. However, I do have concerns about the feasibility of accomplishing that given the time frame we have before the project ending and Lal's graduation. But we can discuss more tomorrow if you'd like.

rburghol commented 2 years ago

Thanks:

Looking forward to the 1 variable model as well.

laljeet commented 2 years ago

Last week's meeting notes: The best Liner mixed effects model: 4 parameter model lmer(log(DEQ_Irrigation_withdrawals) ~ PPT +Min_Temp+Zero_PPT_days+ Extreme_days+(YEAR|COUNTYFP)+(1|COUNTYFP), data=Deq_dat2)

R square = 0.87
DLMER_Modelled vs reported

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">

Parameter | VIF -- | -- PPT | 1.921367 Min_Temp | 1.157851 Zero_PPT_days | 1.810487 Extreme_days | 1.276739

____

Normalized Withdrawals Model: (Normalized by mean withdrawals) glm(Norm_DEQ_withdarwals ~ PPT + Min_Temp + Extreme_days + GC, data = dat2)

Predicted withdrawals in (mgd) dat2$predict = predict(Best_model)*dat2$Mean_DEQ_withdarwals

R Square = 0.91


Predicted normalized Model (Million gallons) Normlaised_predicted_withdarwals vs DEQ reported


Predict normalized coefficient dat2$predict =predict(Best_model) R Square = 0.04

One parameter model reduced this R square to 0.03


Normlaised_predicted_withdarwals_coeff vs normalised