# Data S2 for Tanentzap and Smith. 2018. Unintentional rewilding: lessons for trophic rewilding from other forms of species introductions. Phil Trans Roy Soc B # Prepared by AJ Tanentzap (ajt65@cam.ac.uk), 9 August 2018 # Stan model code to fit the meta-regression model described in the main text. # Please cite the paper if you re-use the code. # # # # # # equation2_1 <- " data{ // HERE WE DEFINE THE DATA THAT WE INPUT INTO STAN int N; // total number of observations associated with unintentional rewilding int N_inten; // total number of observations associated with intentional rewilding int Nbiomes; // number of study biomes int Nstudies; // number of studies int Nresptclass; // number of response type categories int Ndietbclass; // number of diet breadth categories int NTLbtwn; // number of categories for trophic levels between the cosnumer and response vector[N] logRR; // log response ratios associated with unintentional rewilding vector[N] logstudymths; // log study duration associated with unintentional rewilding vector[N] abslat; // absolute latitude associated with unintentional rewilding vector[N] weight; // regression weights associated with unintentional rewilding int biome[N]; // biome category associated with unintentional rewilding int studyID[N]; // study identity associated with unintentional rewilding int resp_type[N]; // response type category associated with unintentional rewilding int TL_btwn[N]; // number of trophic levels between the introduced species and response associated with unintentional rewilding int co_evol[N]; // binary values of whether response coevolved with species from same Order associated with unintentional rewilding int invasive[N]; // binary values of whether introduced species is classed as invasive associated with unintentional rewilding int indirect[N]; // binary values of whether interactions associated with unintentional rewilding when TL_betwen = 0 or 1 were indirect or not int dietb[N]; // dietary breadth associated with unintentional rewilding vector[N] npp; // net primary productivity of each site associated with unintentional rewilding vector[N_inten] logRR_inten; // log response ratios associated with intentional rewilding vector[N_inten] logstudymths_inten; // log study duration associated with intentional rewilding vector[N_inten] abslat_inten; // absolute latitude associated with intentional rewilding vector[N_inten] weight_inten; // regression weights associated with intentional rewilding int biome_inten[N_inten]; // biome category associated with intentional rewilding int studyID_inten[N_inten]; // study identity ratios associated with intentional rewilding int resp_type_inten[N_inten]; // response type category associated with intentional rewilding int co_evol_inten[N_inten]; // binary values of whether response coevolved with species from same Order associated with intentional rewilding int diet_strat_inten[N_inten]; // dietary breadth associated with unintentional rewilding vector[N_inten] npp_inten; // net primary productivity of each site associated with unintentional rewilding } parameters{ // HERE WE DEFINE THE PARAMETERS THAT WE ESTIMATE IN STAN real b_coef[13]; // estimate 12 beta coefficients matrix[Nbiomes,2] biome_ef; // matrix of change in effect of tj_i (column 1) and overall on R_i (column 2) associated with each biome type matrix[Nstudies,2] study_ef; // matrix of change in effect of tj_i (column 1) and overall on R_i (column 2) associated with each study ID matrix[Nresptclass,2] respt_ef; // matrix of change in effect of tj_i (column 1) and overall on R_i (column 2) associated with each response type matrix[Ndietbclass,2] dietb_ef; // matrix of change in effect of tj_i (column 1) and overall on R_i (column 2) associated with each diet strategy real TLbtn_ef[NTLbtwn]; // effect of the number of trophic levels between the response and introduced species real sd_p[7]; // estimate 7 standard deviations and ensure that they are positive real sd_pp[7]; // estimate 2 standard deviations and ensure that they are positive (we want seperate ones here to give the different priors) vector[N] theta; // 'true' (i.e. latent) response ratio associated with unintentional rewilding vector[N_inten] theta_inten; // 'true' (i.e. latent) response ratio associated with intentional rewilding } transformed parameters{ // HERE WE DEFINE THE PARAMETERS THAT WE CALCULATE IN STAN vector[N] mu; // mean of theta_i associated with unintentional rewilding vector[N_inten] mu_inten; // mean of theta_i associated with intentional rewilding for (i in 1:N) // calculate equation 2.1 from the main text for unintentional rewilding mu[i] = exp(b_coef[1]*co_evol[i]+ b_coef[2]*invasive[i] + b_coef[3]*abslat[i] + b_coef[4]*npp[i] + b_coef[5]*indirect[i] + b_coef[6]*logstudymths[i] + sd_p[1]*study_ef[studyID[i],1] + sd_p[2]*biome_ef[biome[i],1] + sd_p[3]*respt_ef[resp_type[i],1] + sd_pp[1]*dietb_ef[dietb[i],1])*TLbtn_ef[TL_btwn[i]] + b_coef[7]*co_evol[i]+ b_coef[8]*invasive[i] + b_coef[9]*abslat[i] + b_coef[10]*npp[i] + b_coef[11]*indirect[i] + b_coef[12]*logstudymths[i] + sd_p[4]*biome_ef[biome[i],2] + sd_p[5]*study_ef[studyID[i],2] + sd_p[6]*respt_ef[resp_type[i],2] + sd_pp[2]*dietb_ef[dietb[i],2]; for (i in 1:N_inten) // calculate equation 2.1 from the main text for intentional rewilding // there is no need to include invasive as = 0 for all observations of intentional rewilding // we also calculate a seperate effect of tj_i here that is represented by b_coef[13] mu_inten[i] = exp(b_coef[1]*co_evol[i] + b_coef[3]*abslat[i] + b_coef[4]*npp_inten[i] + b_coef[6]*logstudymths[i] + sd_p[1]*study_ef[studyID[i],1] + sd_p[2]*biome_ef[biome[i],1] + sd_p[3]*respt_ef[resp_type[i],1] + sd_pp[1]*dietb_ef[diet_strat_inten[i],1])*b_coef[13] + b_coef[7]*co_evol[i] + b_coef[9]*abslat[i] + b_coef[10]*npp_inten[i] + b_coef[12]*logstudymths[i] + sd_p[4]*biome_ef[biome[i],2] + sd_p[5]*study_ef[studyID[i],2] + sd_p[6]*respt_ef[resp_type[i],2] + sd_pp[2]*dietb_ef[diet_strat_inten[i],2]; } model{ // HERE WE DEFINE THE PRIOR LIKELIHOODS THAT WE ESTIMATE IN STAN sd_p ~ normal(0,2); sd_p ~ normal(0,1); // weakly more informative prior on these SDs because we only have 3 groups (after Gelman 2006 Bayesian Analysis) to_vector(biome_ef) ~ normal(0,1); to_vector(study_ef) ~ normal(0,1); to_vector(respt_ef) ~ normal(0,1); to_vector(dietb_ef) ~ normal(0,1); TLbtn_ef ~ normal(0,2); b_coef ~ normal(0,2); theta ~ normal(mu,sd_p[7]); logRR ~ normal(theta, weight); theta_inten ~ normal(mu_inten,sd_p[7]); logRR_inten ~ normal(theta_inten, weight_inten); } "