This function produces a list of data.frames for predicting the partial effect of a focal.predictor current included in a species_mix model.

effects_data(focal.predictors, mod, ngrid, ...)

Arguments

focal.predictors

A character or string of characters which represent covariates in the model.

mod

The fitted species_mix or regional_mix model.

ngrid

The length of the prediction vector.

...

other arguments

Value

This function should return a list of data.frames one for each focal.predictor. This will enable user to predict marginal effects or plot the partial response plots.

Details

Generate data for plotting or predicting partial effects of covariates

This function produces a list of data.frames for predicting the partial effect of a focal.predictor current included species_mix or regional_mix models.

Examples

# \donttest{
library(ecomix)
set.seed(42)
sam_form <- stats::as.formula(paste0('cbind(',paste(paste0('spp',1:20),
collapse = ','),")~x1+x2"))
sp_form <- ~ 1
beta <- matrix(c(-2.9,-3.6,-0.9,1,.9,1.9),3,2,byrow=TRUE)
dat <- data.frame(y=rep(1,100),x1=stats::runif(100,0,2.5),
x2=stats::rnorm(100,0,2.5))
dat[,-1] <- scale(dat[,-1])
simulated_data <- species_mix.simulate(archetype_formula = sam_form,species_formula = sp_form,
data = dat,beta=beta,family="bernoulli")
#> Random alpha from normal (-1,0.5) distribution
fm1 <- species_mix(archetype_formula = sam_form,species_formula = sp_form,
data = simulated_data, family = 'bernoulli',  nArchetypes=3)
#> SAM modelling
#> There are 3 archetypes
#> There are 100 site observations for 20 species
#> The model for the archetype (grouping) is ~x1 + x2
#> The model for the species is ~1
#> You are implementing a bernoulli Species Archetype Model.
#> This model uses a logit link function.
#> Using ECM algorithm to find starting values; using 1 refits
#> ECM restart 1 of 1
#> Initialising starting values
#> Initial groups parameter estimates by K-means clustering
#> Iteration: 1 | New loglik -950.728 | Ratio loglik 0
#> Iteration: 2 | New loglik -829.843 | Ratio loglik 0.8728
#> Iteration: 3 | New loglik -820.246 | Ratio loglik 0.9884
#> Iteration: 4 | New loglik -819.839 | Ratio loglik 0.9995
#> initial  value 819.837517 
#> iter  10 value 819.706573
#> final  value 819.703416 
#> converged
effects_data("x1",fm1)
#> $x1
#>             x1           x2
#> 1  -1.73619885 3.295975e-17
#> 2  -1.66937720 3.295975e-17
#> 3  -1.60255555 3.295975e-17
#> 4  -1.53573391 3.295975e-17
#> 5  -1.46891226 3.295975e-17
#> 6  -1.40209062 3.295975e-17
#> 7  -1.33526897 3.295975e-17
#> 8  -1.26844733 3.295975e-17
#> 9  -1.20162568 3.295975e-17
#> 10 -1.13480403 3.295975e-17
#> 11 -1.06798239 3.295975e-17
#> 12 -1.00116074 3.295975e-17
#> 13 -0.93433910 3.295975e-17
#> 14 -0.86751745 3.295975e-17
#> 15 -0.80069581 3.295975e-17
#> 16 -0.73387416 3.295975e-17
#> 17 -0.66705252 3.295975e-17
#> 18 -0.60023087 3.295975e-17
#> 19 -0.53340922 3.295975e-17
#> 20 -0.46658758 3.295975e-17
#> 21 -0.39976593 3.295975e-17
#> 22 -0.33294429 3.295975e-17
#> 23 -0.26612264 3.295975e-17
#> 24 -0.19930100 3.295975e-17
#> 25 -0.13247935 3.295975e-17
#> 26 -0.06565771 3.295975e-17
#> 27  0.00116394 3.295975e-17
#> 28  0.06798559 3.295975e-17
#> 29  0.13480723 3.295975e-17
#> 30  0.20162888 3.295975e-17
#> 31  0.26845052 3.295975e-17
#> 32  0.33527217 3.295975e-17
#> 33  0.40209381 3.295975e-17
#> 34  0.46891546 3.295975e-17
#> 35  0.53573711 3.295975e-17
#> 36  0.60255875 3.295975e-17
#> 37  0.66938040 3.295975e-17
#> 38  0.73620204 3.295975e-17
#> 39  0.80302369 3.295975e-17
#> 40  0.86984533 3.295975e-17
#> 41  0.93666698 3.295975e-17
#> 42  1.00348862 3.295975e-17
#> 43  1.07031027 3.295975e-17
#> 44  1.13713192 3.295975e-17
#> 45  1.20395356 3.295975e-17
#> 46  1.27077521 3.295975e-17
#> 47  1.33759685 3.295975e-17
#> 48  1.40441850 3.295975e-17
#> 49  1.47124014 3.295975e-17
#> 50  1.53806179 3.295975e-17
#> 
#> attr(,"class")
#> [1] "species_mix_effects_data"

# }