GithubHelp home page GithubHelp logo

Comments (7)

MaximilianPi avatar MaximilianPi commented on June 17, 2024

Hi François,
I cannot pinpoint the cause of this error, could please provide more information? Can you create a minimal example when this is happening, or at least the code of your analysis?

from s-jsdm.

frmunoz avatar frmunoz commented on June 17, 2024

Here we go:

model = sjSDM(train_X.samp, train_Y.samp, learning_rate = 0.01, iter = 50L, 
                biotic = bioticStruct(df = 10),
                step_size = 20, #as.integer(nrow(train_X)*0.1),
                device = "gpu") #cpu

for debug.zip

from s-jsdm.

MaximilianPi avatar MaximilianPi commented on June 17, 2024

Thanks, I found two issues:

  1. data formats: train_Y.samp was a table -> as.matrix , train_X.samp had also a weird format, class says it is a data.frame but only with data.frame(train_X.samp) it worked
  2. There are NA's in train_X.samp, model.frame removes them but the corresponding rows in Y are not removed

This works (I also switched X and Y because I assume that Y is your occurrence matrix:

library(sjSDM)
model = sjSDM(as.matrix(train_Y.samp), train_X.samp, learning_rate = 0.01, iter = 50L, 
              biotic = bioticStruct(df = 10),
              step_size = 20, #as.integer(nrow(train_X)*0.1),
              device = "cpu") #cpu

#This works:

no_na = complete.cases(data.frame(train_X.samp))
model = sjSDM(as.matrix(train_Y.samp)[no_na, ], data.frame(train_X.samp)[no_na, ], learning_rate = 0.01, iter = 50L, 
              biotic = bioticStruct(df = 10),
              step_size = 2, #as.integer(nrow(train_X)*0.1),
              device = "cpu") #cpu

reminder for me:

  • record NAs in linear and remove the rows in Y
  • check data types

from s-jsdm.

frmunoz avatar frmunoz commented on June 17, 2024

Thank you !
Does it mean that the function cannot manage predictors with different types (e.g., numeric and categorical)?

from s-jsdm.

MaximilianPi avatar MaximilianPi commented on June 17, 2024

No, it can handle all types. The difference to lm/glm is that they manage the data in one dataset (formula = y~temp + treatment, data = forest_data) and therefore rows with nas are removed in the predictors (tmp, treatment) and the response (y).
However, the model.frame does not support multiple responses (Y1+Y2), that is why sjSDM users have to provide an env object (env = matrix or linear(data=env, formula = ~temp + treatment) and the response (occ=matrix with Y1, Y2) separately. If there are now nas in temp or treatment, those rows are removed only in the predictors but not in the response (occ/Y).

By the way if you want to see how the model.frame parses your formula/predictors:

no_na = complete.cases(data.frame(train_X.samp))

env = linear(data = data.frame(train_X.samp)[no_na, ], formula = ~.) # which is equivalent to env = data.frame(train_X.samp)[no_na, ]
print(env$x)

model = sjSDM(as.matrix(train_Y.samp)[no_na, ], env = env, learning_rate = 0.01, iter = 50L, 
              biotic = bioticStruct(df = 10),
              step_size = 2, #as.integer(nrow(train_X)*0.1),
              device = "cpu") #cpu

from s-jsdm.

frmunoz avatar frmunoz commented on June 17, 2024

Ok, noted, thank you for your help Max. :-)

from s-jsdm.

MaximilianPi avatar MaximilianPi commented on June 17, 2024

No problem, quite the opposite. I have to thank you, you reveal a lot of weaknesses/bugs in the pkg ^^

Close for now, but the na and data format checker have to be implemented #35

from s-jsdm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.