Commit ce2cdfca authored by Daniel's avatar Daniel

Added log-log GBM models both to the 2_sf_modeling code and to the data dictionary.

parent 7286d383
......@@ -109,8 +109,8 @@ for(m in 1:nrow(models)){ for(i in 1:filter_iters){
, importance=TRUE
, data=subset(modeldata, filter_1>=filter_setting_1 & modeling_group==models$modeling_group[m])))
}
if(models$estimation_method[m]=="GBM"){
if(models$estimation_method[m]=="GBM"
& (models$type[m]=="lin-lin" | models$type[m]=="log-log")){
model <- try(gbm(as.formula(models$form[m])
,distribution="gaussian"
,interaction.depth=2
......@@ -220,6 +220,29 @@ for(m in 1:nrow(models)){ for(i in 1:filter_iters){
}
}
}
if (models$estimation_method[m]=='GBM' & models$type[m] == "log-log"){
predictions <- NA
TF <- modeldata$modeling_group==models$modeling_group[m] & modeldata$filter_1 >= 1
error <- try(exp(predict(model, newdata=modeldata[TF,], n.trees=ntree)))
if (class(error) != "try-error"){
predictions[TF] <- try(exp(predict(model, newdata=modeldata[TF,], n.trees=ntree)))
modeldata$fitted_value <- predictions
print("Values predicted")
}
else{
if(filter_setting_1==1){
print(error)
check<- paste0("Able to estimate all models with no trimming?")
msg<- paste0("Bad: failed to predict values for ",models$model_id[m], " at trim setting 1")
integrity_checks <- rbind(integrity_checks, data.frame(check=check, outcome=msg))
print(check); print(msg); rm( msg)
next
}else{
print(paste0("Error predicting values, skipping loop."))
next
}
}
}
rm(predictions)
......@@ -539,8 +562,7 @@ for(m in 1:nrow(models)){ for(i in 1:filter_iters){
}
r <- try(summary(model)$adj.r.squared)
if(is.null(r)|class(r)=="try-error"){r<-NA}
}
else if(holdout_switch == "n"){
}else if(holdout_switch == "n"){
hold_out_COD <- "NA"
median_hold_out_ratio <- "NA"
print(paste0(user, " chose to skip holdout"))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment