# PAMM: Simulation function to assess power of mixed models In pamm: Power Analysis for Random Effects in Mixed Models

## Description

Given a specific varaince-covariance structure for random effect, the function simulate different group size and assess p-values and power of random intercept and random slope

## Usage

 ```1 2``` ```PAMM(numsim, group, repl, randompart, fixed, n.X, autocorr.X, X.dist, intercept, heteroscedasticity = c("null"), ftype="lmer", mer.sim=FALSE) ```

## Arguments

 `numsim` number of simulation for each step `group` number of group. Could be specified as a vector `repl` number of replicates per group . Could be specified as a vector `randompart` vector of lenght 4 or 5, with 1: variance component of intercept, VI; 2: variance component of slope, VS; 3: residual variance, VR; 4: relation between random intercept and random slope; 5: "cor" or "cov" determine if the relation 4 between I ans S is a correlation or a covariance. Default: `"cor"` `fixed` vector with mean, variance and estimate of fixed effect to simulate. Default: `c(0,1,0)` `n.X` number of different values to simulate for the fixed effect (covariate). If `NA`, all values of X are independent between groups. If the value specified is equivalent to the number of replicates per group, `repl`, then all groups are observed for the same values of the covariate. Default: `NA` `autocorr.X` correlation between two successive covariate value for a group. Default: `0` `X.dist` specify the distribution of the fixed effect. Only "gaussian" (normal distribution) and "unif" (uniform distribution) are accepted actually. Default: `"gaussian"` `intercept` a numeric value giving the expected intercept value. Default:0 `heteroscedasticity` a vector specifying heterogeneity in residual variance across X. If `c("null")` residual variance is homogeneous across X. If `c("power",t1,t2)` models heterogeneity with a constant plus power variance function. Letting v denote the variance covariate and s2(v) denote the variance function evaluated at v, the constant plus power variance function is defined as s2(v) = (t1 + |v|^t2)^2, where t1, t2 are the variance function coefficients. If `c("exp",t)`,models heterogeneity with an exponential variance function. Letting v denote the variance covariate and s2(v) denote the variance function evaluated at v, the exponential variance function is defined as s2(v) = exp(2* t * v), where t is the variance function coefficient. `ftype` character value "lmer", "lme" or "MCMCglmm" specifying the function to use to fit the model. Actually "lmer" only is accepted `mer.sim` simulate the data using simulate.merMod from lme4. Faster for large sample size but not as flexible.

## Details

P-values for random effects are estimated using a log-likelihood ratio test between two models with and without the effect. Power represent the percentage of simulations providing a significant p-value for a given random structure

## Value

data frame reporting estimated P-values and power with CI for random intercept and random slope

## Warning

the simulation is based on a balanced data set with unrelated group

Julien Martin

## References

Martin, Nussey, Wilson and Reale Submitted Measuring between-individual variation in reaction norms in field and experimental studies: a power analysis of random regression models. Methods in Ecology and Evolution.

`EAMM`, `SSF`, `plot.PAMM`
 ```1 2 3 4 5 6``` ```## Not run: ours <- PAMM(numsim=10,group=c(seq(10,50,10),100),repl=c(3,4,6), randompart=c(0.4,0.1,0.5,0.1),fixed=c(0,1,0.7)) plot(ours,"both") ## End(Not run) ```