Title: | Statistical Quantification of Individual Differences |
---|---|
Description: | A simulation-based tool made to help researchers to become familiar with multilevel variations, and to build up sampling designs for their study. This tool has two main objectives: First, it provides an educational tool useful for students, teachers and researchers who want to learn to use mixed-effects models. Users can experience how the mixed-effects model framework can be used to understand distinct biological phenomena by interactively exploring simulated multilevel data. Second, it offers research opportunities to those who are already familiar with mixed-effects models, as it enables the generation of data sets that users may download and use for a range of simulation-based statistical analyses such as power and sensitivity analysis of multilevel and multivariate data [Allegue, H., Araya-Ajoy, Y.G., Dingemanse, N.J., Dochtermann N.A., Garamszegi, L.Z., Nakagawa, S., Reale, D., Schielzeth, H. and Westneat, D.F. (2016) <doi: 10.1111/2041-210X.12659>]. |
Authors: | Hassen Allegue [aut, cre], Yimen G. Araya-Ajoy [aut], Niels J. Dingemanse [aut], Ned A. Dochtermann [aut], Laszlo Z. Garamszegi [aut], Shinichi Nakagawa [aut], Denis Reale [aut], Holger Schielzeth [aut], David F. Westneat [aut] |
Maintainer: | Hassen Allegue <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.1.9000 |
Built: | 2025-03-12 05:18:14 UTC |
Source: | https://github.com/squidgroup/squid |
SQuID stands for Statistical Quantification of Individual Differences and is the product of the SQuID working group. The package aims to help scholars who, like us, are interested in understanding patterns of phenotypic variance. Individual differences are the raw material for natural selection to act on and hence the basis of evolutionary adaptation. Understanding the sources of phenotypic variance is thus a most essential feature of biological investigation and mixed effects models offer a great, albeit challenging tool. Disseminating the properties, potentials and interpretational challenges in the research community is thus a foremost goal of SQuID.
The SQuID package has two main objectives: First, it provides an educational tool useful for students, teachers and researchers who want to learn to use mixed-effects models. Users can experience how the mixed-effects model framework can be used to understand distinct biological phenomena by interactively exploring simulated multilevel data. Second, SQuID offers research opportunities to those who are already familiar with mixed-effects models, as SQuID enables the generation of datasets that users may download and use for a range of simulation-based statistical analyses such as power and sensitivity analysis of multilevel and multivariate data.
The phenotype of a trait in an individual results from a sum of genetic and environmental influences. Phenotypic variation is structured in a hierarchical way and the hierarchical modeling in mixed effect models is great tool to analyze and decompose such variation. Phenotypes vary across species, across populations of the same species, across individuals of the same population, and across repeated observations of the same individual. We focused on the individual level because it represents one of the most important biological levels to both ecological and evolutionary processes. Different sources of variation are at the origin of the phenotype of an individual. Individuals may differ in their phenotypes because they carry different gene variants (i.e. alleles). But individuals also experience different environments during their lifetime. Some environmental influences impose a lasting mark on the phenotype, while others are more ephemerous. The former tend to produce long-lasting, among-individual variation, while the latter causes within-individual variation. However, this depends on the time scale at which the measurements of the phenotypes are done relative that of the environmental influences. Furthermore, individuals differ not only in their average phenotypes but also in how they respond to changes in their environment (i.e. differences in individual phenotypic plasticity). This represents an interaction between the among- and the within-individual levels of variation. The patterns of variation can, thus, be very complex. Selection can act differently on these different components of variance in the phenotypes of a trait, and this is why it is important to quantify their magnitude.
Mixed models are very flexible statistical tools that provide a way to estimate the variation at these different levels, and represent the general statistical framework for evolutionary biology. Because of the progress in computational capacities mixed models have become increasingly popular among ecologists and evolutionary biologists over the last decade. However, fitting mixed model is not a straightforward exercise, and the way data are sampled among and within individuals can have strong implications on the outcome of the model. This is why we created the SQuID simulation tool that could help new users interested in decomposing phenotypic variance to get more familiar with the concept of hierarchical organization of traits, with mixed models and to avoid pitfalls caused by inappropriate sampling.
SQuID is a simulation-based tool that can be used for research and educational purposes. SQuID creates a world inhabited by individuals whose phenotypes are generated by a user-defined phenotypic equation, which allows easy translation of biological hypotheses into mathematically quantifiable parameters. The framework is suitable for performing simulation studies, determining optimal sampling designs for user-specific biological problems, and making simulation based inferences to aid in the interpretation of empirical studies. SQuID is also a teaching tool for biologists interested in learning, or teaching others, how to implement and interpret mixed-effects models, when studying the processes causing phenotypic variation. SQuID is based on a mathematical model that creates a group of individuals (i.e. study population) repeatedly expressing phenotypes, for one or two different traits, in uniform time. Phenotypic values of traits are generated following the general principle of the phenotypic equation (Dingemanse & Dochtermann 2013, Journal of Animal Ecology): phenotypes are assumed to be the summed effects of a series of components and the phenotypic variance (Vp) is the sum of the respective variances in theses causal components. The user has thus the flexibility to add different variance components that will form the phenotype of the individual at each time step, and to set up the relative importance of each component through the definition of environmental effects. SQuID then allows the user to collect a subsample of phenotypes for each simulated individual (i.e. operational data set), according to a specific sampling design. The major difference between SQuID and other R packages that also allow performance analysis through data simulation (e.g. pamm, odprism, simr), is that only SQUID allows separate steps for generating the world first and then model a sampling process from it. SQuID is subject to evolution and is designed to adapt to more complex scenarios in the future.
SQuID has two main functions; squidApp
and squidR
.
This function runs the SQuID application which is a browser-based interface created with the shiny package. SQuID is built up as a series of modules that guide the user into situations of increasing complexity to explore the phenotypic equation model and the dynamics between the way phenotypes are sampled and the estimation of parameters of specific interest; The last module is the full model simulation that allows the user to generate data sets that can then be used to run analyses in the statistical package of their choice for specific research questions. For most of the modules, the simulated data set is automatically fed into a statistical model in R and the main results of the analysis shown in an output. For the full model the user has the opportunity to download the operational data set for further analyses. The SQuID application also has a tab (Full model (Step by step)) describing in details the SQuID full model.
This function is a traditional R function that allows data generation and sampling without the browser-based interface. This function can be used for more advanced and efficient simulations once you understand how SQuID works. squidR can be easily included in R scripts.
Allegue, H., Araya-Ajoy, Y.G., Dingemanse, N.J., Dochtermann N.A., Garamszegi, L.Z., Nakagawa, S., Reale, D., Schielzeth, H. and Westneat, D.F. (2016) SQuID - Statistical Quantification of Individual Differences: an educational and statistical tool for understanding multi-level phenotypic data in linear mixed models. Methods in Ecology and Evolution, 8:257-267.
Dingemanse, N.J. and Dochtermann N.A. (2013) Quantifying individual variation in behaviour: mixed-effect modelling approaches. Journal of Animal Ecology, 82:39-54.
squidApp
runs SQuID application as a browser interface that has been developed with the package shiny.
SQuID web interface is made to help researchers to become familiar with multilevel phenotypic variation, and to design optimal sampling schemes for their studies. SQuID is built up as a series of modules that guide the user into situations of increasing complexity to explore the dynamics between the way phenotypes are sampled and the estimation of parameters of specific interest. The complete simulations the full model simulation tab provides functionality that allows the user to generate data sets that can then be used to run analyses in the statistical package of their choice and address specific research questions.
SQuID is based on a mathematical model that creates a group of individuals (i.e. study population) repeatedly expressing phenotypes, for one or two different traits, through time. Phenotypic values of traits are generated following the general principle of the phenotypic equation (Dingemanse & Dochtermann 2013, Journal of Animal Ecology): phenotypic variance (Vp) is assumed to be the sum of a series of components (see the full model tab on the web interface). The user has the flexibility to add different causal variance components that will form the phenotype of the individual at each time step, and to set up the relative importance of each component through the definition of environmental effects. SQuID then allows the user to collect a subsample of phenotypes for each simulated individual (i.e. operational data set), according to a specific sampling design. For most of the modules, the simulated data set is automatically fed into a statistical model in R and the main results of the analysis shown in an output. For the full model the user has the opportunity to download the operational data set for further analyses.
squidApp(...)
squidApp(...)
... |
any argument that could be passed to the function |
SQuID application will by default show up on your default web browser (we recommend to update your web browser to its latest version). In order to use properly the SQuID application, we encourage you to start by reading the documentation on the portal page. From there you will be guided through SQuID application according to your experience and knowledge of multilevel modelling.
For more advanced and efficient simulations, SQuID is also available as an R function squidR
.
Note that while the SQuID application is running, your R
session will be busy. Then, in order to exit the SQuID application mode, you have to press the "Esc" key while you are on your R
session window.
Allegue, H., Araya-Ajoy, Y.G., Dingemanse, N.J., Dochtermann N.A., Garamszegi, L.Z., Nakagawa, S., Reale, D., Schielzeth, H. and Westneat, D.F. (2016) SQuID - Statistical Quantification of Individual Differences: an educational and statistical tool for understanding multi-level phenotypic data in linear mixed models. Methods in Ecology and Evolution, 8:257-267.
Dingemanse, N.J. and Dochtermann N.A. (2013) Quantifying individual variation in behaviour: mixed-effect modelling approaches. Journal of Animal Ecology, 82:39-54.
# run SQuID application ## Not run: squidApp() # press the "Esc" key to exit SQuID application mode.
# run SQuID application ## Not run: squidApp() # press the "Esc" key to exit SQuID application mode.
The function simulates a world inhabited by individuals whose phenotypes are generated by a user-defined phenotypic equation and then samples from this world according to a user-defined sampling design. If this is your first experience with SQuID, we highly recommend to start with the interactive SQuID application with graphical interface in order to learn and get more familiarized with the SQuID model and its sampling design (use the function squidApp
).
squidR(input=list(), plot=FALSE, data=NULL, module=NULL, X_previsualization=NULL)
squidR(input=list(), plot=FALSE, data=NULL, module=NULL, X_previsualization=NULL)
input |
A |
plot |
|
data |
A |
module |
A |
X_previsualization |
A |
A detailed description of the SQuID model and its sampling design is provided on the SQuID app (run SQuID app with squidApp
). Reading the SQuID documentation on the SQuID app is prerequisite to use properly the SQuID R function.
The argument input
is a list that contains the different input parameters to the SQuID model. All the parameters are listed below including their default value and a short description. If a parameter is not declared within the input
list, the default value will be used.
Tmax
(default 1): positive integer
; the duration of the simulation (number of time steps).
NP
(default 1): positive integer
; the number of replicated populations. The replicated populations are generated independently using the same simulation design that has been initially inputted by the user. Note that data from different populations will be saved in the same output file that you could later use to run statistical analyses.
NI
(default 1): positive integer
; the number of individuals in each sampled population. NI
must be divisible by the number of higher-level groups (NG
).
NT
(default 1): positive integer
; the number of traits for each individual. SQuID allows a maximum of 2 traits.
NG
(default 1): positive integer
; the number of higher-level groups. NG
must be lower than the number of individuals NI
.
X1_state
(default FALSE
): logical
; if TRUE
, an environmental effect x1 will be added to the model equation.
X1_sto_state
(default FALSE
): logical
; if TRUE
, a stochastic environmental effect will be added to the environmental effect x1. The stochastic environmental effect values follow a normal distribution with a mean of 0 and a variance of X1_sto_V
.
X1_sto_shared
(default TRUE
): logical; if TRUE
, the stochastic environmental effect included in the environmental effect x1 will be shared between individuals. If FALSE
, each individual will experience a different stochastic environmental effect x1 (i.e. a new stochastic environmental effect is generated for each individual).
X1_sto_V
(default 1): numeric
; the variance used to generate the normally distributed stochastic environmental effect x1.
X1_sto_autocor_state
(default FALSE
): logical
; if TRUE
, an autocorrelation effect will be added to the stochastic environmental effect x1.
X1_sto_corr
(default 0): numeric
; the correlation value ranging from 0 to 1 that characterizes the magnitude of the temporal autocorrelation between two consecutive time steps.
X1_lin_state
(default FALSE
): logical
; if TRUE
, a linear trend will be added to the environmental effect x1.
X1_lin_shared
(default TRUE
): logical
; if TRUE
, the linear trend included in the environmental effect x1 will be shared between individuals. If FALSE
, each individual will experience a different linear trend within the environmental effect x1. A different linear trend is generated for each individual by varying the intercept and the slope of the linear equation. The variation in intercepts and slopes following a normal distribution with means X1_lin_intercept
, X1_lin_slope
and variance X1_lin_V
.
X1_lin_intercept
(default 0): numeric
; the intercept of the linear trend included into the environmental effect x1.
X1_lin_slope
(default 1): numeric
; the slope of the linear trend included into the environmental effect x1.
X1_lin_V
(default 1): numeric
; the variance used to generate different (unshared) linear trend effect for each individual within the environmental effect x1.
X1_cyc_state
(default FALSE
): logical
; if TRUE
, a cyclic trend will be added the environmental effect x1.
X1_cyc_shared
(default TRUE
): logical
; if TRUE
, the cyclic trend for environmental effect x1 will be shared between individuals. If FALSE
, each individual will experience a different cyclic trend for environmental effect x1. A new cyclic trend is generated for each individual by varying the amplitude, the period, the horizontal shift and the vertical shift of the cyclic equation following a normal distribution where the mean is the parameter value itself and the variance is X1_cyc_V
.
X1_cyc_amplitude
(default 10): positive numeric
; the amplitude of the cyclic trend for environmental effect x1.
X1_cyc_period
(default 10): positive numeric
; the period of the cyclic trend for the environmental effect x1.
X1_cyc_Hshift
(default 0): positive numeric
; the horizontal shift of the cyclic trend for environmental effect x1.
X1_cyc_Vshift
(default 0): positive numeric
; the vertical shift of the cyclic trend for environmental effect x1.
X1_cyc_V
(default 0): numeric
; the variance used to generate different (unshared) cyclic trends for each individual in the environmental effect x1.
X2_state
(default FALSE
): logical
; if TRUE
, an environmental effect x2 will be added to the model equation.
X2_sto_state
(default FALSE
): logical
; if TRUE
, a stochastic environmental effect will be added to the environmental effect x2. The stochastic environmental effect values follow a normal distribution with mean of 0 and a variance of X2_sto_V
.
X2_sto_shared
(default TRUE
): logical
; if TRUE
, the stochastic environmental effect included in the environmental effect x2 will be shared between individuals. If FALSE
, each individual will experience a different stochastic environmental effect x2 (i.e. a new stochastic environmental effect is generated for each individual).
X2_sto_V
(default 1): numeric
; the variance for the normally distributed stochastic environmental effect x2.
X2_sto_autocor_state
(default FALSE
): logical
; if TRUE
, an autocorrelation effect will be added to the stochastic environmental effect x2.
X2_sto_corr
(default 0): numeric
; the correlation value ranging from 0 to 1 that characterizes the magnitude of the temporal autocorrelation between two consecutive time steps.
X2_lin_state
(default FALSE
): logical
; if TRUE
, a linear trend will be added to the environmental effect x2.
X2_lin_shared
(default TRUE
): logical
; if TRUE
, the linear trend included in the environmental effect x2 will be shared between individuals. If FALSE
, each individual will experience a different linear trend within the environmental effect x2. A new linear trend is generated for each individual by varying the intercept and the slope of the linear equation. The variation in intercepts and slopes follow a normal distribution with means X2_lin_intercept
, X2_lin_slope
and variance X2_lin_V
.
X2_lin_intercept
(default 0): numeric
; the intercept of the linear trend for environmental effect x2.
X2_lin_slope
(default 1): numeric
; the slope of the linear trend for environmental effect x2.
X2_lin_V
(default 1): numeric
; the variance used to generate different (unshared) linear trend effect for each individual's environmental effect x2.
X2_cyc_state
(default FALSE
): logical
; if TRUE
, a cyclic trend will be added the environmental effect x2.
X2_cyc_shared
(default TRUE
): logical
; if TRUE
, the cyclic trend included in the environmental effect x2 will be shared between individuals. If FALSE
, each individual will experience a different cyclic trend for the environmental effect x2. A new cyclic trend is generated for each individual by varying the amplitude, the period, the horizontal shift and the vertical shift of the cyclic equation following a normal distribution where the mean is the parameter value itself and the variance is X2_cyc_V
.
X2_cyc_amplitude
(default 10): positive numeric
; the amplitude of the cyclic trend included into the environmental effect x2.
X2_cyc_period
(default 10): positive numeric
; the period of the cyclic trend for environmental effect x2.
X2_cyc_Hshift
(default 0): positive numeric
; the horizontal shift of the cyclic trend for environmental effect x2.
X2_cyc_Vshift
(default 0): positive numeric
; the vertical shift of the cyclic trend for environmental effect x2.
X2_cyc_V
(default 0): numeric
; the variance used to generate different (unshared) cyclic trend effect for each individual within the environmental effect x2.
X_Interaction
(default FALSE
): logical
; if TRUE
, the environmental effect x1*x2 representing the interaction between the environmental effect x1 and the environmental effect x2 will be added to the model equation.
B
(default c(0,0,0,0)
): numeric vector
; the population mean values. When the number of trait is set to 1, the length of the vector is 4. The vector elements are respectively the population intercept (b0), the population response to environmental influences x1 (fixed slope; b1), the population response to environmental influences x2 (fixed slope; b2) and the population response interaction between environmental influences x1 and x2 (fixed slope; b12). If the number of trait is set to 2, the length of the vector is doubled (len=8) and the second half corresponds to the population mean values associated with the second trait.
Vind
(default matrix(0, nrow=4, ncol=4)
): square, positive definite matrix
or lower triangular matrix
; the individual variance/correlation matrix. Variances are positive numeric
numbers and correlations are numeric
numbers ranged between -1 and 1. Variances are along the matrix diagonal and correlation values below the matrix diagonal. When the number of trait is set to 1, the dimension of the matrix is 4 rows by 4 columns (4x4) and the diagonal elements are respectively the individual-specific (random) intercept variance (VI), the individual-specific response to an environmental effect x1 (random slope) variance (VS1), the individual-specific response to an environmental effect x2 (random slope) variance (VS2) and the individual-specific response interaction to two environmental effects x1 and x2 (random slopes) variance (VS12). When the number of trait is set to 2, the dimension of the matrix is doubled (8x8) where the second half of the diagonal is the individual variances (intercept and slopes) of the second trait. Note that it is possible to set correlation relationships between random effects within and/or among traits.
Ve
(default 0): positive numeric
; the measurement error variance.
VG
(default 0): positive numeric
; the high-level grouping variance.
NR
(default 1): positive integer
; the average number of records sampled per individual.
Vhsi
(default 0): numeric
(between 0 and 0.95); the among-individual variance in timing of sampling.
NR_ind
(default TRUE
): logical
; if TRUE
, individuals will be sampled the same number of times.
NR_trait
(default TRUE
): logical
; if TRUE
, traits within individuals will be sampled the same number of times.
ST_ind
(default TRUE
): logical
; if TRUE
, individuals will be sampled at the same time (i.e. recorded simultaneously).
ST_trait
(default TRUE
): logical
; if TRUE
, traits within individuals will be sampled at the same times (i.e. recorded simultaneously).
When the full data of a previous squid simulation is passed to squidR
through the argument data
, squidR
does not generate a new world and samples directly into the already existing world.
squidR
returns a list
that includes a data.frame
of the full data generated (the "world"), a data.frame
of the sampled data and six ggplot2 plots of the results (only if plot
is set to TRUE
).
The full and the sampled data could be accessed respectively by output$full_data
and output$sampled_data
.
A description of the columns of the full and the sampled data.frame
is provided below:
Replicate
: (factor) the replicated population identifier.
Individual
: (factor) the individual identifier.
Group
: (factor) the high-level grouping identifier.
Individual_Trait
: (factor) the identifier of each individual/trait combination.
Trait
: (factor) the trait identifier.
Time
: (integer) the time step value.
Phenotype
: (numeric) the individual phenotype.
Beta0
: (numeric) the population phenotypic mean.
Beta1
: (numeric) the population mean response to environmental influences x1.
Beta2
: (numeric) the population mean response to environmental influences x2.
Beta12
: (numeric) the population mean response to environmental influences x1x2 (the interaction between the environmental effect x1 and the environmental effect x2).
I
: (numeric) the individual-specific deviations (random-intercepts) from the population phenotypic mean Beta0
.
S1
: (numeric) the individual-specific response to the environmental influence x1 (random-slope).
S2
: (numeric) the individual-specific response to the environmental influence x2 (random-slope).
S12
: (numeric) the individual-specific response to the environmental influence x1x2 (the interaction between the environmental effect x1 and the environmental effect x2; random-slope).
X1
: (numeric) the environmental gradient x1.
X2
: (numeric) the environmental gradient x2.
X1X2
: (numeric) the environmental gradient x1x2 (the interaction between the environmental effect x1 and the environmental effect x2).
G
: (numeric) the higher-level grouping value.
e
: (numeric) the measurement error.
squidR
returns a list that also includes a list (plots
) of six ggplot2 plots of the results. Note that the plots display only the data of the first trait, the first replicate and the first 20 individuals of the simulation.
$plots$X1
: a plot of the environmental gradient x1.
$plots$X2
: a plot of the environmental gradient x2.
$plots$X1X2
: a plot of the environmental gradient x1x2 (the interaction between the environmental effect x1 and the environmental effect x2).
$plots$totPhen
: a plot of the raw individual phenotype over time.
$plots$sampPhen
: a plot of the sampled individual phenotype over time.
$plots$sampTime
: a plot of the sampling time of each individual.
Allegue, H., Araya-Ajoy, Y.G., Dingemanse, N.J., Dochtermann N.A., Garamszegi, L.Z., Nakagawa, S., Reale, D., Schielzeth, H. and Westneat, D.F. (2016) SQuID - Statistical Quantification of Individual Differences: an educational and statistical tool for understanding multi-level phenotypic data in linear mixed models. Methods in Ecology and Evolution, 8:257-267.
Dingemanse, N.J. and Dochtermann N.A. (2013) Quantifying individual variation in behaviour: mixed-effect modelling approaches. Journal of Animal Ecology, 82:39-54.
If this is your first experience with SQuID, we highly recommend to start with the interactive SQuID application with graphical interface in order to learn and get more familiarized with the SQuID model (phenotypic equation) and its sampling design (use the function squidApp
).
squidApp
to run the SQuID app which includes detailed documentation on the SQuID model and its sampling design.
## create the input list ## input <- list() ## define the model input parameters ## input$Tmax <- 100 # 100 time steps input$NP <- 10 # 10 replicated populations input$NI <- 20 # 20 individuals per replicate population input$NT <- 1 # 1 trait per individual # in this simulation model, only one environmental gradient (x1) is added # turn on the environmental gradient x1 input$X1_state <- TRUE # add a stochastic environmental effect to the environmental effect x1 input$X1_sto_state <- TRUE # the stochastic environmental effect included # into the environmental effect x1 is not shared among individual. # Each individual will experience a different stochastic environmental effect. input$X1_sto_shared <- FALSE # add an autocorrelation effect to the stochastic # environmental effect within the environmental effect x1. input$X1_sto_autocor_state <- FALSE # define the autocorrelation value between two consecutive time steps. input$X1_sto_corr <- 0.5 # add a linear trend to the environmental effect x1. # the default parameters for the linear trend will be used # (an intercept of 0, a slope of 1 and the linear trend will be shared among individuals) input$X1_lin_state <- TRUE # define the population mean values vector. # the population mean (fixed intercept) and # the population mean response to environmental influences x1 (fixed slope) # are set to 0.1. input$B <- c(0.1, 0.1, 0, 0) # define the individual variance/correlation matrix (squared matrix; 4x4) # the individual-specific deviation (random intercept; VI) variance is set to 0.7. # the individual-specific response to an environmental effect x1 (random slope; VS1) is set to 0.5. # the correlation between the individual-specific deviation (I) # and the individual-specific response # to an environmental effect x1 # (S1) is set to -0.7. input$Vind <- matrix(c(0.7 , 0 , 0 , 0, -0.7 , 0.5 , 0 , 0, 0 , 0 , 0 , 0, 0 , 0 , 0 , 0), nrow=4, byrow=TRUE) input$Ve <- 0.05 # the measurement error variance ## define the sampling design ## # the mean number of records per individual input$NR <- 10 # the among-individual variance in timing of sampling input$Vhsi <- 0.2 # individuals are not sampled the same number of times. input$NR_ind <- FALSE # individuals are not sampled at the time input$ST_ind <- FALSE ## run the simulation ## output <- squidR(input, plot=TRUE) # plot the individual phenotype values over time print(output$plot$totPhen) # see first records of the simulated data set head(output$full_data) ## run a second simulation with the identical world but with a different sampling design ## where individuals are sampled the same number of times and at the same time input$NR_ind <- TRUE # individuals are sampled the same number of times. input$ST_ind <- TRUE # individuals are sampled at the time output2 <- squidR(input, plot=TRUE, data=output$full_data)
## create the input list ## input <- list() ## define the model input parameters ## input$Tmax <- 100 # 100 time steps input$NP <- 10 # 10 replicated populations input$NI <- 20 # 20 individuals per replicate population input$NT <- 1 # 1 trait per individual # in this simulation model, only one environmental gradient (x1) is added # turn on the environmental gradient x1 input$X1_state <- TRUE # add a stochastic environmental effect to the environmental effect x1 input$X1_sto_state <- TRUE # the stochastic environmental effect included # into the environmental effect x1 is not shared among individual. # Each individual will experience a different stochastic environmental effect. input$X1_sto_shared <- FALSE # add an autocorrelation effect to the stochastic # environmental effect within the environmental effect x1. input$X1_sto_autocor_state <- FALSE # define the autocorrelation value between two consecutive time steps. input$X1_sto_corr <- 0.5 # add a linear trend to the environmental effect x1. # the default parameters for the linear trend will be used # (an intercept of 0, a slope of 1 and the linear trend will be shared among individuals) input$X1_lin_state <- TRUE # define the population mean values vector. # the population mean (fixed intercept) and # the population mean response to environmental influences x1 (fixed slope) # are set to 0.1. input$B <- c(0.1, 0.1, 0, 0) # define the individual variance/correlation matrix (squared matrix; 4x4) # the individual-specific deviation (random intercept; VI) variance is set to 0.7. # the individual-specific response to an environmental effect x1 (random slope; VS1) is set to 0.5. # the correlation between the individual-specific deviation (I) # and the individual-specific response # to an environmental effect x1 # (S1) is set to -0.7. input$Vind <- matrix(c(0.7 , 0 , 0 , 0, -0.7 , 0.5 , 0 , 0, 0 , 0 , 0 , 0, 0 , 0 , 0 , 0), nrow=4, byrow=TRUE) input$Ve <- 0.05 # the measurement error variance ## define the sampling design ## # the mean number of records per individual input$NR <- 10 # the among-individual variance in timing of sampling input$Vhsi <- 0.2 # individuals are not sampled the same number of times. input$NR_ind <- FALSE # individuals are not sampled at the time input$ST_ind <- FALSE ## run the simulation ## output <- squidR(input, plot=TRUE) # plot the individual phenotype values over time print(output$plot$totPhen) # see first records of the simulated data set head(output$full_data) ## run a second simulation with the identical world but with a different sampling design ## where individuals are sampled the same number of times and at the same time input$NR_ind <- TRUE # individuals are sampled the same number of times. input$ST_ind <- TRUE # individuals are sampled at the time output2 <- squidR(input, plot=TRUE, data=output$full_data)