knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

jeksterslabRdata is a collection of functions that I find useful in studying data generation and sampling.

Installation

You can install the released version of jeksterslabRdata from GitHub with:

library(devtools)
install_github("jeksterslabds/jeksterslabRdata")

Main functions

library(jeksterslabRdata)

univ()

Generates an $n \times 1$ univariate data vector or a list of $n \times 1$ univariate data vectors of length R. The default data generating function is the normal distribution

\begin{equation} X \sim \mathcal{N} \left( \mu, \sigma^2 \right) . %(#eq:dist-X-norm) \end{equation}

Single Random Data Set

Run the function.

x <- univ(n = 100, rFUN = rnorm, mean = 100, sd = sqrt(225))

Explore the output.

str(x, list.len = 6)
hist(x, main = expression(italic(N)(list(mu == 100, sigma^2 == 225))))

Multiple Random Data Sets

Run the function.

xstar <- univ(n = 100, rFUN = rnorm, mean = 100, sd = sqrt(225), R = 100)

Explore the output.

str(xstar, list.len = 6)

mvn()

Generates an $n \times k$ multivariate data matrix or a list of $n \times k$ multivariate data matrices of length R from the multivariate normal distribution

\begin{equation} \mathbf{X} \sim \mathcal{N}_{k} \left( \boldsymbol{\mu}, \boldsymbol{\Sigma} \right) . %(#eq:dist-X-mvn) \end{equation}

\noindent This function is a wrapper around MASS::mvrnorm().

Single Random Data Set

Set mu and Sigma.

mu <- c(100, 100, 100)
Sigma <- matrix(
  data = c(225, 112.50, 56.25, 112.5, 225, 112.5, 56.25, 112.50, 225),
  ncol = 3
)

Run the function.

X <- mvn(n = 100, mu = mu, Sigma = Sigma)

Explore the output.

str(X)
pairs(X)
colMeans(X)
cov(X)
cor(X)

Multiple Random Data Sets

Run the function.

Xstar <- mvn(n = 100, mu = mu, Sigma = Sigma, R = 100)

Explore the output.

str(Xstar, list.len = 6)

mvnram()

Generates an $n \times k$ multivariate data matrix or a list of $n \times k$ multivariate data matrices of length R from the multivariate normal distribution

\begin{equation} \mathbf{X} \sim \mathcal{N}_{k} \left( \boldsymbol{\mu}, \boldsymbol{\Sigma} \right) . %(#eq:dist-X-mvn) \end{equation}

\noindent The model-implied matrices used to generate data is derived from the Reticular Action Model (RAM) Matrices.

Single Random Data Set

Set matrices.

mu <- c(100, 100, 100)
A <- matrix(
  data = c(0, sqrt(0.26), 0, 0, 0, sqrt(0.26), 0, 0, 0),
  ncol = 3
)
S <- diag(c(225, 166.5, 116.5))
F <- I <- diag(3)

Run the function.

X <- mvnram(n = 100, mu = mu, A = A, S = S, F = F, I = I)

Explore the output.

str(X)
pairs(X)
colMeans(X)
cov(X)
cor(X)

Multiple Random Data Sets

Run the function.

Xstar <- mvnram(n = 100, mu = mu, A = A, S = S, F = F, I = I, R = 100)

Explore the output.

str(Xstar, list.len = 6)


jeksterslabds/jeksterslabRdata documentation built on July 24, 2020, 5:49 a.m.