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

Problem with formulas in ZIPLN? #126

Open
papayoun opened this issue Apr 10, 2024 · 1 comment
Open

Problem with formulas in ZIPLN? #126

papayoun opened this issue Apr 10, 2024 · 1 comment
Assignees

Comments

@papayoun
Copy link

I work with version 1.2.0 of the package, downloaded on github, and I have issue to use ZIPLN within (mc)lapply framework to parallelize treatment over different model formulas.

Basically, what I would like to do with ZIPLN is this, which works with the classical PLN function:

library(PLNmodels) # Version 1.2.0
data("barents")

# With PLN ----------------------------------------------------------------

pln_formulas <- c("Abundance ~ 1")
lapply(pln_formulas, function(form_){
  PLN(pln_formulas, data = barents)
}) # Works fine

I then define a new formula and I want to use ZIPLN, but this won't work within lapply.
It works if I do it within a loop:

# With ZIPLN --------------------------------------------------------------

ZIPLN("Abundance ~ 1 | 1", data = barents) # Works fine, just to check

# Creating vector of formulas
zi_pln_formulas <- c("Abundance ~ 1 | 1")

# Works fine within a loop using as.formula
for(x in zi_pln_formulas){
  ZIPLN(as.formula(x), data = barents)
} # Works fine

However, the following codes won't work (the error is shown in comment each time)

# Using the raw object
ZIPLN(zi_pln_formulas, data = barents) 
# Error in x$formula : object of type 'symbol' is not subsettable

# Within a lapply, first as a string
lapply(zi_pln_formulas, function(form_){
  ZIPLN(form_, data = barents)
})
 # Error in x$formula : object of type 'symbol' is not subsettable

# Within a lapply, with as.formula
lapply(zi_pln_formulas, function(form_){
  ZIPLN(as.formula(form_), data = barents)
}) 
# Error in as.formula(form_) : object 'form_' not found

My R session info is the following

platform       x86_64-pc-linux-gnu                        
arch           x86_64                                     
os             linux-gnu                                  
system         x86_64, linux-gnu                          
status         Patched                                    
major          4                                          
minor          2.2                                        
year           2022                                       
month          11                                         
day            10                                         
svn rev        83330                                      
language       R                                          
version.string R version 4.2.2 Patched (2022-11-10 r83330)
@mahendra-mariadassou mahendra-mariadassou self-assigned this Apr 10, 2024
@mahendra-mariadassou
Copy link
Collaborator

mahendra-mariadassou commented Apr 10, 2024

Hi @papayoun, thanks for finding the bug. I'll have a look into it (it's probably due to the "non standard" formulas used in ZIPLN).

Can you just check something for me: I get an error when I try to use as.formula() within ZIPLN within a loop but your reprex suggests it works for you (I have the same error as the one you get with lapply() or the raw object). Can you confirm this ?

library(PLNmodels)
#> This is package 'PLNmodels' version 1.2.0
#> Use future::plan(multicore/multisession) to speed up PLNPCA/PLNmixture/stability_selection.

# Creating vector of formulas
zi_pln_formulas <- c("Abundance ~ 1 | 1")

# Works fine within a loop using as.formula
for(x in zi_pln_formulas){
  ZIPLN(x, data = barents)
} # Works fine for @papayoun 
# but not for me
#> Error in x$formula: objet de type 'symbol' non indiçable 

Created on 2024-04-10 with reprex v2.1.0

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