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

Indirect coefficients omitted when predicting networks with bootstrapped MRF models #33

Open
lawwt opened this issue Nov 23, 2021 · 0 comments

Comments

@lawwt
Copy link

lawwt commented Nov 23, 2021

predict_MRFnetworks.R has inconsistencies in handling indirect coefficients with bootstrapped MRF models, resulting in indirect coefficients omitted from the predicted networks when a bootstrapped model is used.

For example, within code chunk 119-133, line 126 checks if the length of MRF_mod$indirect_coefs is greater than 0

# Create an MRF_mod object to feed to the predict function
MRF_mod_booted <- list()
MRF_mod_booted$graph <- MRF_mod$direct_coef_means[ , 2:(n_nodes + 1)]
MRF_mod_booted$intercepts <- as.vector(MRF_mod$direct_coef_means[ , 1])
MRF_mod_booted$direct_coefs <- MRF_mod$direct_coef_means
MRF_mod_booted$mod_family <- MRF_mod$mod_family
MRF_mod_booted$mod_type <- 'MRFcov'
if(length(MRF_mod$indirect_coefs) > 0){
  for(i in seq_along(MRF_mod$indirect_coef_mean)){
    MRF_mod_booted$indirect_coefs[[i]] <- list(MRF_mod$indirect_coef_mean[[i]],"")[1]
    }
  names(MRF_mod_booted$indirect_coefs) <- names(MRF_mod$indirect_coef_mean)
} else {
  MRF_mod_booted$indirect_coefs <- NULL
}

However, MRF_mod$indirect_coefs does not exist for booted models, so length will always = 0. It should be MRF_mod$indirect_coef_mean. This means that MRF_mod_booted$indirect_coefs is never created, causing downstream problems (i.e. predicted networks will not change with the environment)

The same issue occurs again on line 189

 # If covariates exist, incorporate their modifications to species' interactions 
 if(length(MRF_mod$indirect_coefs) > 0){

Checking MRF_mod$indirect_coefs for booted models will always result in FALSE.

lawwt added a commit to lawwt/MRFcov that referenced this issue Nov 30, 2021
Changed check for if boostrapped model has covariates so that it matches the bootstrap object.
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

1 participant