0

I am doing a MaxEnt modelling using "dismo". I am using a loop to give multiple runs. I wanted to save results from individual runs in separate objects and at the same time the results from individual runs in separate directories.

The loop I have created runs without error. But when I am trying potential options to save the results, I am getting errors. The loop is as follows -

run = 2
for(i in 1:run){
group.k1 <- kfold(loxA.4, 5)
loxTrain.L1 = loxData.L1[group.k1 != 1,]
loxTest.L1 = loxData.L1[group.k1 == 1,] 
background = randomPoints(predictor0, 10000)
pseudo_absence_values = extract(predictor0, background)
pseudo_absence_values <- as.data.frame(pseudo_absence_values)
pseudo_absence_values$africa_ecoregion <- as.factor(pseudo_absence_values$africa_ecoregion)  
train_y = c(rep(1,nrow(loxTrain.L1)), rep(0,nrow(pseudo_absence_values)))
train_sdm_data = cbind(pa = train_y, rbind(loxTrain.L1, pseudo_absence_values))
Model.MT1 = maxent(train_sdm_data[,-1], p = train_y, path = "maxent/set_2/output"
show(Model.MT1)
Loop.r = predict(predictor0,Model.MT1, progress='text')
}

closed as unclear what you're asking by Andre Silva, BERA, Mark Ireland, Hornbydd, user2856 Jul 5 '18 at 3:19

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Please always include the error that you get from running any presented code. Those errors should be presented as formatted text and not pictures. – PolyGeo Jun 19 '18 at 7:20
  • Sorry about that. I realised that after posting it. However, I was able to work on it over the day I am posting it in the answer section. Hope that would come handy for all too. – Partha Jun 19 '18 at 11:47
  • I think this question should be migrated to SE Cross Validated – blabbath Jul 1 '18 at 20:18
1

I worked on the problem through the day and came up with the following solution. I hope it will come handy for everyone.

# Creating the objects    
x <- stack()
    threshold.m <- vector("numeric", 2)
    auc.m1 <- vector("numeric", 2)
    l.T1 <- list()
    l.model <- list()

run = 2
for(i in 1:run){

  # Creating the k-fold data
   group.k1 <- kfold(loxA.4, 5)

   loxTrain.L1 = loxData.L1[group.k1 != 1,]
   loxTest.L1 = loxData.L1[group.k1 == 1,]


   # Creating the background points
   background = randomPoints(predictor0, 10000)
   pseudo_absence_values = extract(predictor0, background)
   pseudo_absence_values <- as.data.frame(pseudo_absence_values)
   pseudo_absence_values$africa_ecoregion <- as.factor(pseudo_absence_values$africa_ecoregion)


   # Creating the Analysis Data
   train_y = c(rep(1,nrow(loxTrain.L1)), rep(0,nrow(pseudo_absence_values))) # Main Training Data
   train_sdm_data = cbind(pa = train_y, rbind(loxTrain.L1, pseudo_absence_values)) # Main SDM Data

   Model.MT1 = maxent(train_sdm_data[,-1], p = train_y, args = c("-J", "-P"),path = "maxent/set_2/output")
   show(Model.MT1)
   l.model <- list(l.model, Model.MT1)


   # Doing Model Evaluation
   mod.evT1 <- evaluate(Model.MT1, p = loxTest.L1, a = pseudo_absence_values)
   l.T1 <- list(l.T1, mod.evT1)

   # Capturing the threshold values
   mod.thr <- threshold(mod.evT1, "spec_sens")
   threshold.m [i] <- mod.thr

   # Capturing the AUC values
   auc.T1 <- mod.evT1@auc
   auc.m1[i] <- auc.T1

   Loop.r <- predict(predictor0,Model.MT1, progress='text')
   x <- stack(x, Loop.r)
   }

The objects then can be used to analyse the relevant statistics.

There is only one problem that remains to be solved. How to save the results in a folder and how to display the Jackknife response curve.

Not the answer you're looking for? Browse other questions tagged or ask your own question.