Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maxent do not works with factors #2

Open
FVFaleiro opened this issue Jun 5, 2020 · 1 comment
Open

Maxent do not works with factors #2

FVFaleiro opened this issue Jun 5, 2020 · 1 comment

Comments

@FVFaleiro
Copy link

FVFaleiro commented Jun 5, 2020

Hi Babak,

I make some tests and when maxent use categories of factors with letters it do not works, but if I use numbers as factors it works fine.
Check it bellow.

Cheers!

library(sdm)

data

train1 <- data.frame(sp = rep(0:1, each = 50), n1 = rnorm(100), n2 = rnorm(100), f1 = factor(rep(c("a", "b"), 50)))
train2 <- data.frame(sp = rep(0:1, each = 50), n1 = rnorm(100), n2 = rnorm(100), f1 = factor(rep(c(1, 2), 50)))
train3 <- data.frame(sp = rep(0:1, each = 50), n1 = rnorm(100), n2 = rnorm(100))

format

d1 <- sdmData(formula = ~., train = train1)
d2 <- sdmData(formula = ~., train = train2)
d3 <- sdmData(formula = ~., train = train3)

fit and test models

m1 <- sdm(~., data = d1, 
          methods = 'maxent',
          replication = 'cross-validation', cv.folds = 10)
m2 <- sdm(~., data = d2, 
          methods = 'maxent',
          replication = 'cross-validation', cv.folds = 10)
m3 <- sdm(~., data = d3, 
          methods = 'maxent',
          replication = 'cross-validation', cv.folds = 10)

check models

m1 # factors as letters
m2 # factors as numbers
m3 # only numeric predictors
@babaknaimi
Copy link
Owner

Hi, Thanks for reporting this.
My initial guess is that the factor variables should be defined as an argument (model setting) to the algorithm that is handled by the maxent function in the dismo package. I think if you define which variables are categorical as the model argument [by adding modelSettings=list(maxent=list(factors=c("f1"))) to the sdm function] it would fix the issue.

I will check to make this automatically handled.

Repository owner deleted a comment from Nega439 Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants