Skip to content

Commit

Permalink
fix bug in use of predict() 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
MargaretSiple-NOAA committed Nov 15, 2024
1 parent ff7cef3 commit a3d24e6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions R/Functions_LoadMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ CrossValidateModel<-function(model,
species=NA,
folds=10,
group="random"){

if(model.type!="maxnet"){
species<-ifelse(model$family$family=="ziplss",as.character(stats::formula(model)[[1]])[[2]],as.character(stats::formula(model))[[2]])
}
Expand Down Expand Up @@ -244,16 +243,16 @@ CrossValidateModel<-function(model,
error.data$abund[start.vec[i]:end.vec[i]]<-test.data[,species]

if(model.type=="maxnet"){
preds<-exp(mgcv::predict.gam(object = model,newdata=test.data,response="link")+model$entropy)
probs<-mgcv::predict.gam(object = model,newdata=test.data,type="cloglog")
preds<-exp(predict(object = model,newdata=test.data,response="link")+model$entropy)
probs<-predict(object = model,newdata=test.data,type="cloglog")
# then on to the cv model
vars0<-names(model$samplemeans)
facs<-vars0[vars0%in%names(model$varmax)==F]

try(cv.model<-FitMaxnet(data = train.data,species = species,vars = names(model$varmax),facs = facs,regmult = regmult))
if(exists("cv.model")){
cvpreds<-exp(mgcv::predict.gam(object = cv.model,newdata=test.data,response="link")+cv.model$entropy)
cvprobs<-mgcv::predict.gam(object = cv.model,newdata=test.data,type="cloglog")
cvpreds<-exp(predict(object = cv.model,newdata=test.data,response="link")+cv.model$entropy)
cvprobs<-predict(object = cv.model,newdata=test.data,type="cloglog")
}else{
cvpreds<-rep(NA,times=nrow(test.data))
cvprobs<-rep(NA,times=nrow(test.data))
Expand Down

0 comments on commit a3d24e6

Please sign in to comment.