sim.measurements: Simulate Morphometric Measurements

View source: R/simulate.R

sim.measurementsR Documentation

Simulate Morphometric Measurements

Description

Simulates morphometric data from a photogrammetry survey, with observations subject to measurement error, under the model described by Stevenson, Smit, and Setyawan (2026).

Usage

sim.measurements(
  n.animals = NULL,
  n.photos = NULL,
  data = NULL,
  mus,
  sigmas,
  rhos,
  psis,
  phis,
  log.transform = FALSE
)

Arguments

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.

Details

For arguments rhos and phis, the elements must be ordered so that all m - 1 correlations involving dimension 1 appear first in ascending numerical order, followed by all remaining m - 2 correlations involving dimension 2, and so on, where ⁠eqn{m}⁠ is the number of dimensions.

For example, if m = 4, then the first three elements are the correlations between dimension 1 and dimensions 2, 3, and 4, respectively. The following two elements are correlations between dimension 2 and dimensions 3 and 4, respectively. The final element is the correlation between dimension 3 and 4.

Value

A data frame with four columns:

animal.id

An individual identification number. Rows with the same animal.id correspond to measurements of the same individual.

photo.id

A photo identification number. Rows with the same photo.id correspond to measurements taken from the same image.

dim

An integer indicating the dimension the measurement is for.

measurement

The observed measurement value.

References

Stevenson, B. C., Smit, E., and Setyawan, E. (2026) Measurement error models for morphometric data. Annals of Applied Statistics, 20: 945–962.

See Also

sim.morph() to conduct a simulation study by simulating multiple data sets and fitting a model to each one.

Examples

## Simulating data for ten animals, with two photos each, measuring
## three dimensions.
sim.data <- sim.measurements(n.animals = 10, n.photos = 2,
                             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))
head(sim.data)

## Simulating data for two animals, with different numbers of
## photos for each, and different measurements available from
## different photos.
data <- data.frame(animal.id = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2),
                   photo.id = c(1, 1, 2, 2, 2, 1, 2, 3, 3, 4, 4),
                   dim = c(1, 3, 1, 2, 3, 1, 1, 1, 3, 2, 3))
sim.data <- sim.measurements(data = data,
                             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))
sim.data


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