sim.morph: Conduct a Simulation Study for Morphometric Models

View source: R/simulate.R

sim.morphR Documentation

Conduct a Simulation Study for Morphometric Models

Description

Simulates multiple datasets and fits a model to each one.

Usage

sim.morph(
  n.sims,
  n.animals = NULL,
  n.photos = NULL,
  data = NULL,
  mus,
  sigmas,
  rhos,
  psis,
  phis,
  log.transform = FALSE,
  method = "REML",
  control = list(maxIter = 1e+05, msMaxIter = 1e+05),
  progressbar = TRUE,
  n.cores = 1
)

Arguments

n.sims

Integer. The number of data sets to simulate.

n.animals

Integer. The number of animals in the sample.

n.photos

Integer vector. If there are n.animals elements, each one specifies the number of photos for an individual. If there is one element, then that number of photos is used for all animals.

data

A data frame with columns animal.id, photo.id, and dim, provided instead of n.animals and n.photos. This provides the user with full control over which dimensions are measured in which photos from which animals.

mus

A vector with an element for each dimension, providing the means of the true dimension sizes in the population.

sigmas

A vector with an element for each dimension, providing the standard deviations for true dimension sizes in the population.

rhos

A vector, with one element for each pair of dimensions, providing the pairwise correlations between true dimension sizes in the population. See 'Details' for the correct order for the correlations.

psis

A vector with an element for each dimension, providing the standard deviations of measurement errors for the dimensions.

phis

A vector, with one element for each pair of dimensions, providing the pairwise correlations between measurement errors for the dimensions. See 'Details' for the correct order for the correlations.

log.transform

Logical. If TRUE, the parameters are considered to correspond to a model where the response was log-transformed. The data frame returned by this function will contain the back-transformed measurments.

method

A character string indicating the objective function used to fit the model. Either "ML" for maximum likelihood or "REML" for restricted maximum likelihood.

control

A list of control values for the estimation algorithm to replace the default values returned by the function nlme::lmeControl().

progressbar

Logical. If TRUE a progress bar will be displayed.

n.cores

Integer. The number of cores for parallel processing.

Value

An object of class lme.morph.sim. The best way to extract results from this object is to use extract.sim.morph(). See the example below.

See Also

extract.sim.morph() to extract results from the object returned by this function.

Examples

## Running a small simulation study.
sim.fits <- sim.morph(n.sims = 5,
                      n.animals = 10,
                      n.photos = 3,
                      mus = c(315, 150, 100),
                      sigmas = c(25, 15, 10),
                      rhos = c(0.85, 0.80, 0.75),
                      psis = c(10, 6, 4),
                      phis = c(0.5, 0.4, 0.3),
                      method = "REML",
                      progressbar = FALSE,
                      n.cores = 1)
## Extracting p-values from tests for isometry from each model
## fit.
iso.p <- function(x) summary(x, type = "isometric-pca")[, 3]
extract.sim.morph(sim.fits, FUN = iso.p)


morphErr documentation built on Aug. 30, 2026, 5:06 p.m.