SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: Looping Problem [ Reply ]
By: Katrina Pound on 2017-08-25 18:45
[forum:45295]
It worked! Thank you so much for your help.

I tried to use the same code to get the variable importance all in one file:
modOutFiles <- list.files(pattern = '.models.out$', recursive = TRUE)
variableimportance <- lapply(modOutFiles,
function(f){
cbind(species = dirname(f),
get_variables_importance(get(load(f)), as.data.frame = TRUE))
})

var_importance<- bind_rows(data.frame(variableimportance))
head(var_importance)

This gives me all 208 variable importance for each species (13 variables*4 models*4 runs). The only caveat is that the variables are not labeled by run, model, and variable name, but I am able to add columns with those labels in the csv file after I export it.

RE: Looping Problem [ Reply ]
By: Katrina Pound on 2017-08-25 13:38
[forum:45288]
Thanks Damien! I will try the code you suggested and let you know how it works.

Best,

Jatrina

RE: Looping Problem [ Reply ]
By: damien georges on 2017-08-25 06:54
[forum:45287]
Dear Katrina,

You got it! This is an ensemble modelling issue due to too poor single models fitting scores (alternatively to too high model selection criteria)
You can decrase the model selection threshold to give it a try.
If you want to get the evaluaion scored ofall your species models, you can try smth like:

library(dplyr)
modOutFiles <- list.files(pattern = '.models.out$', recursive = TRUE)
modScoresList <- lapply(modOutFiles,
function(f){
cbind(species = dirname(f),
get_evaluations(get(load(f)), as.data.frame = TRUE))
})

modScores <- bind_rows(modScoresList)
head(modScores)

Hope that helps,
Damien

RE: Looping Problem [ Reply ]
By: Katrina Pound on 2017-08-24 21:12
[forum:45286]
Also, I was able to get the loop to run after I removed the ensemble modeling and projection. Now I have 133 directories of species models saved on my hard drive. I have been trying all day to figure out a way to merge the files. Is there a way to merge or combine all the TSS and ROC results from all my species so that I can review my results efficiently?

RE: Looping Problem [ Reply ]
By: Katrina Pound on 2017-08-24 16:56
[forum:45285]
Hi Damien,

This is the message I get after the first species:

mergedAlgo_mergedRun_mergedData ensemble modeling
! No models kept due to treshold filtering... Ensemble Modeling was skip!Error in names(EM@em.models) <- EM@em.computed :
attempt to set an attribute on NULL

It looks like the first model does not meet the thresholds for the ensemble modeling. Then instead of moving onto the next species, the loop just stops after the first species.

Katrina

RE: Looping Problem [ Reply ]
By: damien georges on 2017-08-24 07:34
[forum:45282]
Dear Katrina,

Do you have any error/warning message poping up durin the modelling?

Best,
Damien

Looping Problem [ Reply ]
By: Katrina Pound on 2017-08-23 22:20
[forum:45281]
I need to use a looping function because I have multiple species. I tried following the multispecies vignette, but the code stops after the first species and the loop does not continue. Here is my code, similar to the vignette with modifications for my data:
species<-read.table("species.csv",head=T,sep=",",row.names=1)
landuse<-read.table("landuse_trans.csv",head=T,sep=",",row.names=1)
xy<-read.table("Long_lat.csv",head=T,sep=",",row.names=1)
sp.names<-colnames(species)
for(sp.n in sp.names){myRespName=sp.n
cat('\n',myRespName,'modeling...')
myResp <- as.numeric(species[,myRespName])
myRespCoord=xy
myBiomodData <- BIOMOD_FormatingData(resp.var = myResp,
expl.var = landuse,
resp.xy = xy,
resp.name = myRespName)
myBiomodOption <- BIOMOD_ModelingOptions()
myBiomodModelOut <- BIOMOD_Modeling(
myBiomodData,
models = c('GLM','GBM','GAM','RF'),
models.options = myBiomodOption,
NbRunEval=4,
DataSplit=70,
VarImport=10,
models.eval.meth = c('TSS','ROC'),
SaveObj = TRUE,
rescal.all.models = TRUE,
do.full.models = FALSE,
modeling.id = paste(myRespName,"FirstModeling",sep=""))
capture.output(get_evaluations(myBiomodModelOut),
file=file.path(myRespName,
paste(myRespName,"_formal_models_evaluation.txt", sep="")))
capture.output(get_variables_importance(myBiomodModelOut),
file=file.path(myRespName,
paste(myRespName,"_formal_models_variables_importance.txt", sep="")))
myBiomodEM <- BIOMOD_EnsembleModeling(
modeling.output = myBiomodModelOut,
chosen.models = 'all',
em.by='all',
eval.metric = c('TSS'),
eval.metric.quality.threshold = c(0.7),
prob.mean = T,
prob.cv = T,
prob.ci = T,
prob.ci.alpha = 0.05,
prob.median = T,
committee.averaging = T,
prob.mean.weight = T,
prob.mean.weight.decay = 'proportional' )
myBiomodProj <- BIOMOD_Projection(
modeling.output = myBiomodModelOut,
new.env = landuse,
proj.name = 'current',
selected.models = 'all',
binary.meth = 'TSS',
compress = 'xz',
clamping.mask = F,
output.format = '.grd')
myBiomodEF <- BIOMOD_EnsembleForecasting(
projection.output = myBiomodProj,
EM.output = myBiomodEM)
}

Thanks to:
Vienna University of Economics and Business Powered By FusionForge