Warning: The dot-dot notation (`..rr.label..`) was deprecated in ggplot2 3.4.0.
i Please use `after_stat(rr.label)` instead.
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 74 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 74 rows containing non-finite outside the scale range
(`stat_poly_eq()`).
Warning: The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
Warning: Removed 74 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 41 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 41 rows containing non-finite outside the scale range
(`stat_poly_eq()`).
Warning: The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
Warning: Removed 41 rows containing missing values or values outside the scale range
(`geom_point()`).
2. Compare R^2’s between ALS and ULS at each radius
p =ggplot(df.allVegR2s, aes(x =as.numeric(radius), y =as.numeric(r2), color =factor(compType))) +geom_point(size =2, shape =21, stroke =1) +labs(x ="Radius", y ="R2", color ="Comparison Type") +theme_bw() +theme(panel.border =element_rect(color ="black", fill =NA, size =1))
Warning: The `size` argument of `element_rect()` is deprecated as of ggplot2 3.4.0.
i Please use the `linewidth` argument instead.
p
3. Radius 4 seems to have the best combination of ULS and ALS results
Radius 4 seems to have the best combination of ULS and ALS results based on 2.
4. Assess effects of OD and OH on model performance
for (vegType in vegTypes){ temp = out[out$veg_type == vegType & out$radius ==4, ] lm.temp.mlsals =lm(mls_vol_dens ~ als_nrd_under + als_ord_over + als_ht_over, data = temp) lm.temp.mlsuls =lm(mls_vol_dens ~ uls_nrd_under + uls_ord_over + uls_ht_over, data = temp) df.perVegR2s.mlsals[nrow(df.perVegR2s.mlsals)+1,] =c("MLS vs ALS", vegType, radius, summary(lm.temp.mlsals)$adj.r.squared, mean(temp$als_ord_over), quantile(temp$als_ht_over, 0.9)) df.perVegR2s.mlsuls[nrow(df.perVegR2s.mlsuls)+1,] =c("MLS vs ULS", vegType, radius, summary(lm.temp.mlsuls)$adj.r.squared, mean(temp$uls_ord_over), quantile(temp$uls_ht_over, 0.9))}p1 =ggplot(df.perVegR2s.mlsals, aes(x =as.numeric(od), y =as.numeric(r2), color =factor(vegType))) +geom_point(size =2, shape =21, stroke =1) +geom_smooth(aes(group =1), color="red", method ="lm", se =FALSE) +stat_poly_eq(aes(label =paste(..rr.label..),group=1),formula = y ~ x,parse =TRUE,size =4,label.x=0.05,label.y=0.05 ) +labs(x ="ALS OD", y ="R²", color ="Veg Type") +theme_bw() +theme(panel.border =element_rect(color ="black", fill =NA, size =1))p2 =ggplot(df.perVegR2s.mlsals, aes(x =as.numeric(ht), y =as.numeric(r2), color =factor(vegType))) +geom_point(size =2, shape =21, stroke =1) +geom_smooth(aes(group =1), color="red", method ="lm", se =FALSE) +stat_poly_eq(aes(label =paste(..rr.label..),group=1),formula = y ~ x,parse =TRUE,size =4,label.x=0.05,label.y=0.05 ) +labs(x ="ALS HT", y ="R²", color ="Veg Type") +theme_bw() +theme(panel.border =element_rect(color ="black", fill =NA, size =1))p3 =ggplot(df.perVegR2s.mlsuls, aes(x =as.numeric(od), y =as.numeric(r2), color =factor(vegType))) +geom_point(size =2, shape =21, stroke =1) +geom_smooth(aes(group =1), color="red", method ="lm", se =FALSE) +stat_poly_eq(aes(label =paste(..rr.label..),group=1),formula = y ~ x,parse =TRUE,size =4,label.x=0.05,label.y=0.05 ) +labs(x ="ULS OD", y ="R²", color ="Veg Type") +theme_bw() +theme(panel.border =element_rect(color ="black", fill =NA, size =1))p4 =ggplot(df.perVegR2s.mlsuls, aes(x =as.numeric(ht), y =as.numeric(r2), color =factor(vegType))) +geom_point(size =2, shape =21, stroke =1) +geom_smooth(aes(group =1), color="red", method ="lm", se =FALSE) +stat_poly_eq(aes(label =paste(..rr.label..),group=1),formula = y ~ x,parse =TRUE,size =4,label.x=0.05,label.y=0.05 ) +labs(x ="ULS HT", y ="R²", color ="Veg Type") +theme_bw() +theme(panel.border =element_rect(color ="black", fill =NA, size =1))(p1 | p2) /(p3 | p4)
`geom_smooth()` using formula = 'y ~ x'
Warning: The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
`geom_smooth()` using formula = 'y ~ x'
Warning: The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
`geom_smooth()` using formula = 'y ~ x'
Warning: The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
`geom_smooth()` using formula = 'y ~ x'
Warning: The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
5. Build LMs to predict MLS density with ALS and ULS NRD per vegetation type
Warning: Removed 74 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 74 rows containing non-finite outside the scale range
(`stat_poly_eq()`).
Warning: The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
Warning: Removed 74 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 41 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 41 rows containing non-finite outside the scale range
(`stat_poly_eq()`).
Warning: The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
The following aesthetics were dropped during statistical transformation:
colour.
i This can happen when ggplot fails to infer the correct grouping structure in
the data.
i Did you forget to specify a `group` aesthetic or to convert a numerical
variable into a factor?
Warning: Removed 41 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_smooth()`).
6.2 lmer(mls_vol_dens ~ (als_nrd_under | veg_type), data = df_train)
# read in the datadf = out# get list of plotsplot_ids =unique(df$plot)# loop through themfor (p in plot_ids){# split data into training and validation df_train = df[df$plot_id != p & df$radius==4, ] # all plots *except* the one left out df_valid = df[df$plot_id == p & df$radius==4,] # just data from the one plot left out# build a model with the training data mod.mlsals =lmer(mls_vol_dens ~ (als_nrd_under | veg_type), data = df_train) mod.mlsuls =lmer(mls_vol_dens ~ (uls_nrd_under | veg_type), data = df_train)# make predictions on the validation data pred.mlsals =predict(mod.mlsals, df_valid) pred.mlsuls =predict(mod.mlsuls, df_valid)# create data.frame of predictions and observations for this "fold" df_pred_obs_fold.mlsals =data.frame(pred = pred.mlsals, obs = df_valid$mls_vol_dens) df_pred_obs_fold.mlsuls =data.frame(pred = pred.mlsuls, obs = df_valid$mls_vol_dens)# compile data from all foldsif (p == plot_ids[1]){# on the first iteration, just copy the data.frame df_pred_obs.mlsals = df_pred_obs_fold.mlsals df_pred_obs.mlsuls = df_pred_obs_fold.mlsuls } else {# on subsequent iterations, combine the data by row df_pred_obs.mlsals =rbind(df_pred_obs.mlsals, df_pred_obs_fold.mlsals) df_pred_obs.mlsuls =rbind(df_pred_obs.mlsuls, df_pred_obs_fold.mlsuls) }}
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.00207738 (tol = 0.002, component 1)
# get r-squared and rmser2.mlsals =1-sum((df_pred_obs.mlsals$obs - df_pred_obs.mlsals$pred)^2) /sum((df_pred_obs.mlsals$obs -mean(df_pred_obs.mlsals$obs))^2)rmse.mlsals =sqrt(mean((df_pred_obs.mlsals$pred - df_pred_obs.mlsals$obs)^2))r2.mlsuls =1-sum((df_pred_obs.mlsuls$obs - df_pred_obs.mlsuls$pred)^2) /sum((df_pred_obs.mlsuls$obs -mean(df_pred_obs.mlsuls$obs))^2)rmse.mlsuls =sqrt(mean((df_pred_obs.mlsuls$pred - df_pred_obs.mlsuls$obs)^2))#plot out predicted vs observedp =ggplot(data=df_pred_obs.mlsals,aes(x=obs,y=pred)) +geom_point() +geom_smooth(color="red", method ="lm", se =FALSE) +stat_poly_eq(aes(label =paste(..rr.label..),group=1),formula = y ~ x,parse =TRUE,size =4 ) +theme_minimal() +scale_x_continuous(limits =c(0, .45)) +scale_y_continuous(limits =c(0, .45)) +geom_abline(slope =1, intercept =0, linetype ="dashed", color ="blue", linewidth =1) +annotate("text",x =0.0, y =0.45,label =paste0("RMSE: ", round(rmse.mlsals, 3)),hjust =0, vjust =5, size =4) +labs(x ="Observed", y ="Predicted") +theme(panel.border =element_rect(color ="black", fill =NA, size =1))plot(p)
`geom_smooth()` using formula = 'y ~ x'
p =ggplot(data=df_pred_obs.mlsuls,aes(x=obs,y=pred)) +geom_point() +geom_smooth( color="red", method ="lm", se =FALSE) +stat_poly_eq(aes(label =paste(..rr.label..),group=1),formula = y ~ x,parse =TRUE,size =4 ) +theme_minimal() +scale_x_continuous(limits =c(0, .45)) +scale_y_continuous(limits =c(0, .45)) +geom_abline(slope =1, intercept =0, linetype ="dashed", color ="blue", linewidth =1) +annotate("text",x =0.0, y =0.45,label =paste0("RMSE: ", round(rmse.mlsuls, 3)),hjust =0, vjust =5, size =4) +labs(x ="Observed", y ="Predicted") +theme(panel.border =element_rect(color ="black", fill =NA, size =1))plot(p)