Title: | Bias, Precision, and Power for Multi-Level Random Regressions |
---|---|
Description: | Calculates bias, precision, and power for multi-level random regressions. Random regressions are types of hierarchical models in which data are structured in groups and (regression) coefficients can vary by groups. Tools to estimate model performance are designed mostly for scenarios where (regression) coefficients vary at just one level. 'MultiRR' provides simulation and analytical tools (based on 'lme4') to study model performance for random regressions that vary at more than one level (multi-level random regressions), allowing researchers to determine optimal sampling designs. |
Authors: | Yimen G. Araya-Ajoy |
Maintainer: | Yimen G. Araya-Ajoy <[email protected]> |
License: | GPL-2 |
Version: | 1.1 |
Built: | 2025-01-26 17:18:19 UTC |
Source: | https://github.com/cranhaven/cranhaven.r-universe.dev |
Calculates bias, precision, and power for multi-level random regressions. Random regressions are types of hierarchical models in which data are structured in groups and (regression) coefficients can vary by groups. Tools to estimate model performance are designed mostly for scenarios where (regression) coefficients vary at just one level. 'MultiRR' provides simulation and analytical tools (based on 'lme4') to study model performance for random regressions that vary at more than one level (multi-level random regressions), allowing researchers to determine optimal sampling designs.
Package: | MultiRR |
Type: | Package |
Version: | 1.0 |
Date: | 2015-05-11 |
License: | GPL -2 |
Use the function Sim.MultiRR
to simulate n data sets, then use the function Anal.MultiRR
to perform a multi-level random regression to n simulated data sets. You can view the results using the function Summary
or Plot.Sim
, estimate bias using the function Bias
, imprecision using the function Imprecision
, and power using the function Power
.
Yimen Araya: <[email protected]>
Araya-Ajoy Y.G., Mathot, K. J., Dingemanse N. J. (2015) An approach to estimate short-term, long-term, and reaction norm repeatability. Methods in Ecology and Evolution.
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim) #Example 2: Unbalanced sampling design. #Define sample sizes. n.ind <-40 ##Numbers of individuals to simulate. SeriesPerInd <- 4 ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Define the proportion of individuals that were sampled in all the series. #All individuals were assayed at least once, 0.9 of individuals twice... prop.ind<-c(1, 0.9, 0.8, 0.7) #Define the total number of observations n.obs=300 #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define the individual level parameters. VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the series level parameters. VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd= VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=n.sim, unbalanced=TRUE, prop.ind=c(1, 0.9, 0.8, 0.7), complete.observations=FALSE, n.obs=n.obs) #Analyze simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim) #Example 2: Unbalanced sampling design. #Define sample sizes. n.ind <-40 ##Numbers of individuals to simulate. SeriesPerInd <- 4 ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Define the proportion of individuals that were sampled in all the series. #All individuals were assayed at least once, 0.9 of individuals twice... prop.ind<-c(1, 0.9, 0.8, 0.7) #Define the total number of observations n.obs=300 #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define the individual level parameters. VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the series level parameters. VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd= VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=n.sim, unbalanced=TRUE, prop.ind=c(1, 0.9, 0.8, 0.7), complete.observations=FALSE, n.obs=n.obs) #Analyze simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
Performs multilevel random regressions to objects created with the function Sim.MultiRR.
Anal.MultiRR(x)
Anal.MultiRR(x)
x |
Object created with the function sim.MultiRR. |
A list of results from the multi-level random regression for n simulated data sets.
Yimen Araya
Araya-Ajoy Y.G., Mathot, K. J., Dingemanse N. J. (2015) An approach to estimate short-term, long-term, and reaction norm repeatability. Methods in Ecology and Evolution.
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim) #Example 2: Unbalanced sampling design. #Define sample sizes. n.ind <-40 ##Numbers of individuals to simulate. SeriesPerInd <- 4 ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Define the proportion of individuals that were sampled in all the series. #All individuals were assayed at least once, 0.9 of individuals twice... prop.ind<-c(1, 0.9, 0.8, 0.7) #Define the total number of observations n.obs=300 #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define the individual level parameters. VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the series level parameters. VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd= VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=n.sim, unbalanced=TRUE, prop.ind=c(1, 0.9, 0.8, 0.7), complete.observations=FALSE, n.obs=n.obs) #Analyze simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim) #Example 2: Unbalanced sampling design. #Define sample sizes. n.ind <-40 ##Numbers of individuals to simulate. SeriesPerInd <- 4 ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Define the proportion of individuals that were sampled in all the series. #All individuals were assayed at least once, 0.9 of individuals twice... prop.ind<-c(1, 0.9, 0.8, 0.7) #Define the total number of observations n.obs=300 #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define the individual level parameters. VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the series level parameters. VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd= VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=n.sim, unbalanced=TRUE, prop.ind=c(1, 0.9, 0.8, 0.7), complete.observations=FALSE, n.obs=n.obs) #Analyze simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
Calculates bias for an object created with anal.MultiRR.
Bias(x)
Bias(x)
x |
Object created with Anal.MultiRR. |
A list of data frames with the bias and relative bias for all the estimated variance components and repeatabilities.
Yimen Araya
Araya-Ajoy Y.G., Mathot, K. J., Dingemanse N. J. (2015) An approach to estimate short-term, long-term, and reaction norm repeatability. Methods in Ecology and Evolution.
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
Calculates imprecision for an object created with anal.MultiRR.
Imprecision(x)
Imprecision(x)
x |
Object created with Anal.MultiRR. |
A list of data frames with the imprecision for all the estimated variance components and repeatabilities.
Yimen Araya
Araya-Ajoy Y.G., Mathot, K. J., Dingemanse N. J. (2015) An approach to estimate short-term, long-term, and reaction norm repeatability. Methods in Ecology and Evolution.
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
Plots distributions of the estimated parameters from the simulations.
Plot.Sim(x)
Plot.Sim(x)
x |
Object created with Anal.MultiRR. |
Better use with only one combination of parameters (i.e., number of individuals and series per individual.
Yimen Araya
Araya-Ajoy Y.G., Mathot, K. J., Dingemanse N. J. (2015) An approach to estimate short-term, long-term, and reaction norm repeatability. Methods in Ecology and Evolution.
Sim.MultiRR
,
Anal.MultiRR
,
Summary
#Example: Unbalanced sampling design. #Define sample sizes. n.ind <-40 ##Numbers of individuals to simulate. SeriesPerInd <- 4 ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Define the proportion of individuals that were sampled in all the series. #All individuals were assayed at least once, 0.9 of individuals twice... prop.ind<-c(1, 0.9, 0.8, 0.7) #Define the total number of observations n.obs=300 #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define the individual level parameters. VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the series level parameters. VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd= VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=n.sim, unbalanced=TRUE, prop.ind=c(1, 0.9, 0.8, 0.7), complete.observations=FALSE, n.obs=n.obs) #Analyze simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim) #Plot the simulations Plot.Sim(ressim)
#Example: Unbalanced sampling design. #Define sample sizes. n.ind <-40 ##Numbers of individuals to simulate. SeriesPerInd <- 4 ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Define the proportion of individuals that were sampled in all the series. #All individuals were assayed at least once, 0.9 of individuals twice... prop.ind<-c(1, 0.9, 0.8, 0.7) #Define the total number of observations n.obs=300 #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define the individual level parameters. VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the series level parameters. VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd= VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=n.sim, unbalanced=TRUE, prop.ind=c(1, 0.9, 0.8, 0.7), complete.observations=FALSE, n.obs=n.obs) #Analyze simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim) #Plot the simulations Plot.Sim(ressim)
Power analysis for object created with anal.MultiRR.
Power(x)
Power(x)
x |
Object created with Anal.MultiRR. |
A list of data frames with the power to detect among-individual variation in intercepts and slopes in a multi-level random regression model.
Yimen Araya
Araya-Ajoy Y.G., Mathot, K. J., Dingemanse N. J. (2015) An approach to estimate short-term, long-term, and reaction norm repeatability. Methods in Ecology and Evolution.
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
Simulate n data sets to be analyzed with a multi-level random regression.
Sim.MultiRR(n.ind, SeriesPerInd, ObsPerLevel, EnvGradient, PopInt, PopSlope, VCVInd, VCVSeries, ResVar, n.sim, unbalanced = FALSE, prop.ind, complete.observations = TRUE, n.obs)
Sim.MultiRR(n.ind, SeriesPerInd, ObsPerLevel, EnvGradient, PopInt, PopSlope, VCVInd, VCVSeries, ResVar, n.sim, unbalanced = FALSE, prop.ind, complete.observations = TRUE, n.obs)
n.ind |
A vector consisting of the total individuals sampled. |
SeriesPerInd |
A vector consisting of the number of series sampled for each individual. |
ObsPerLevel |
The number of observations per series in each level of the environment. |
EnvGradient |
A vector consisting of the levels in the environmental gradient. |
PopInt |
Population level intercept. |
PopSlope |
Population level slope. |
VCVInd |
A positive definite variance covariance matrix of dimensions 2 X 2, defining the among-individual variance in intercepts and slopes in the diagonals and their covariance in the off diagonals. |
VCVSeries |
A positive definite variance covariance matrix of dimensions 2 X 2, defining the among-series variance in intercepts and slopes in the diagonals and their covariance in the off diagonals. |
ResVar |
Residual variance |
n.sim |
Number of data sets to simulate. |
unbalanced |
Optional argument determining whether not all the individuals were assayed the same number of series. The default is "FALSE". |
prop.ind |
When unbalanced = "TRUE", A vector that has the same length as the number of series per individual, with the proportion of individuals measured n times. All individuals should have been measured once (1,.,.,.). |
complete.observations |
Optional argument determining whether all the levels were assayed the same number of times. The default is "TRUE". |
n.obs |
The total number of observations, if complete.observartions = "FALSE". |
A list of data sets to be analyzed by Anal.MultiRR.
Yimen Araya
Araya-Ajoy Y.G., Mathot, K. J., Dingemanse N. J. (2015) An approach to estimate short-term, long-term, and reaction norm repeatability. Methods in Ecology and Evolution.
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim) #Example 2: Unbalanced sampling desing. #Define sample sizes. n.ind <-40 ##Numbers of individuals to simulate. SeriesPerInd <- 4 ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Define the proportion of individuals that were sampled in all the series. #All individuals were assayed at least once, 0.9 of individuals twice... prop.ind<-c(1, 0.9, 0.8, 0.7) #Define the total number of observations n.obs=300 #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define the individual level parameters. VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the series level parameters. VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd= VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=n.sim, unbalanced=TRUE, prop.ind=c(1, 0.9, 0.8, 0.7), complete.observations=FALSE, n.obs=n.obs) #Analyze simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim) #Example 2: Unbalanced sampling desing. #Define sample sizes. n.ind <-40 ##Numbers of individuals to simulate. SeriesPerInd <- 4 ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Define the proportion of individuals that were sampled in all the series. #All individuals were assayed at least once, 0.9 of individuals twice... prop.ind<-c(1, 0.9, 0.8, 0.7) #Define the total number of observations n.obs=300 #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define the individual level parameters. VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the series level parameters. VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd= VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=n.sim, unbalanced=TRUE, prop.ind=c(1, 0.9, 0.8, 0.7), complete.observations=FALSE, n.obs=n.obs) #Analyze simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
Summary of object created with anal.MultiRR.
Summary(x)
Summary(x)
x |
Object created with anal.MultiRR. |
A list of data frames with a summary of the model estimates for all the simulations.
Yimen Araya
Araya-Ajoy Y.G., Mathot, K. J., Dingemanse N. J. (2015) An approach to estimate short-term, long-term, and reaction norm repeatability. Methods in Ecology and Evolution.
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)
#Example 1: Balanced sampling design. #Define sample sizes. n.ind <-c(40, 50) ##Numbers of individuals to simulate. SeriesPerInd <- c(4, 5) ##Number of series per individual to simulate. ObsPerLevel <- 2 ##Number of observations per level in the environmental gradient. #Number of simulated data sets, use at least 10. n.sim=3 #Define the environmetal gradient. EnvGradient <- c(-0.5, 0.5) #Define the population level parameters. PopInt <- 0 ##Population level intercept. PopSlope <- -0.5 ##Population level slope. #Define individual level parameters VCVInd <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define series level parameters VCVSeries <-matrix(c(0.3, 0.15, 0.15, 0.3),2,2) ##Creates a variance-covariance matrix. #Define the residual variance. ResVar <- 0.4 #Simulate the data sets. sim.data <- Sim.MultiRR(n.ind=n.ind, SeriesPerInd=SeriesPerInd, ObsPerLevel=ObsPerLevel, EnvGradient=EnvGradient, PopInt=PopInt, PopSlope=PopSlope, VCVInd=VCVInd, VCVSeries=VCVSeries, ResVar=ResVar, n.sim=3) #Analyze the simulated data sets. This may take a while. ressim <- Anal.MultiRR(sim.data) #Summarize the results of the multi-level random regressions. Summary(ressim) #Estimate bias. Bias(ressim) #Estiamte imprecision. Imprecision(ressim) #Estimate power. Power(ressim)