% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/simcounts2.R
\name{simcounts2}
\alias{simcounts2}
\title{Simulate counts from a parallel groups design with three time-points}
\usage{
simcounts2(
  n1 = 5,
  n2 = 5,
  beta0 = c(2.3, 3),
  conditionB = c(0.2, 0.1),
  timet2 = c(0, 0),
  timet3 = c(0.5, 0.25),
  conditionB_timet2 = c(0.1, 0.2),
  conditionB_timet3 = c(0.5, 0.6),
  b0 = c(1, 1),
  b1 = c(0, 0),
  b2 = c(0, 0),
  phi_model = NULL,
  library_size = NULL,
  lib_size_mean = 1e+06,
  lib_size_cv = 0.3,
  max_prop = 0.02
)
}
\arguments{
\item{n1}{Number clusters in group 1 (control)}

\item{n2}{Number of clusters in group 2 (treatment)}

\item{beta0}{The intercept parameter on the log scale.}

\item{conditionB}{Baseline differences between conditions}

\item{timet2}{Changes from baseline to time-point 2 in the reference group}

\item{timet3}{Changes from baseline to time-point 3 in the reference group}

\item{conditionB_timet2}{Difference from reference group in changes from
baseline to time-point 2}

\item{conditionB_timet3}{Difference from reference group in changes from
baseline to time-point 3}

\item{b0}{Vector of SD of the between cluster variation in intercept}

\item{b1}{Vector of SD of the between cluster variation in timet1 effects}

\item{b2}{Vector of SD of the between cluster variation in timet2 effects}

\item{phi_model}{A model (lm or loess) of a dispersion ~ log_mu relationship}

\item{library_size}{A vector of library sizes with the length (n1 + n2) * 3
or NULL if library sizes are to be simulated}

\item{lib_size_mean}{Mean of the distribution of library sizes.}

\item{lib_size_cv}{Coefficient of variation for the distribution of library
sizes.}

\item{max_prop}{The maximum count for a single observation as a proportion
of the library size.}
}
\value{
A list of (1) simulated counts, (2) the eta, and (3) phi values used
for simulating data, and (4) the meta data data frame.
}
\description{
Simulate gene counts from a Negative Binomial distribution conditional
on a two-condition, repeated measures experiment with three time points. The
function is used for internal testing and tutorials.
}
\details{
Fixed effects parameter values are specified as vectors (\code{beta0},
\code{conditionB}, \code{timet2}, etc.) with the common vector length being the
number of genes simulated.

The function simulation of counts from a conditional Negative Binomial
distribution:
\deqn{y_{i[g]} \sim \text{NB}(\mu_{i[g]}, \phi_{[g]})}
\deqn{\text{log}(\mu_{i[g]}) = \beta_0 + \beta1 \text{condition}_B + \\
 \beta_2 \text{time}_{t2} + \beta_3 \text{time}_{t3} + \\
 \beta_4 \text{condition}_B \times \text{time}_{t2} + \\
 \beta_5 \text{condition}_B \times \text{time}_{t3} + \\
 \text{offset}(\text{library size}) + \\
 \text{b}_0 + \text{b}_1 \times \text{time}_{t2} +
 \text{b}_2 \times \text{time}_{t3} }
Varying effects are added as:
\deqn{\text{b}_l \sim \text{Normal}(0, \sigma_l)}
The library size is
used as an offset for simulating data. Library sizes are simulated from a
log-normal distribution or provided in library_size. In the simulation of
counts, the library size is entered as offset after scaling to the median
library size. Raw library sizes are included in the meta data.
The dispersion parameter can be simulated from a model (lm or loess)
provided to the function where the predictor variable should be
\eqn{\text{log}(\mu)} and
the outcome variable (dispersion) should be \eqn{\text{log}(\phi)}.
If no model is provided, values are simulated from
a log-normal distribution based on hard coded parameter values
from an observed mean-dispersion relationship.
}
\examples{
# Simulate n_genes number of genes
n_genes <- 1000

dat <- simcounts2(
  n1 = 5,
  n2 = 5,
  beta0 = rnorm(n_genes, mean = 5),
  conditionB =rnorm(n_genes),
  timet2 = rnorm(n_genes),
  timet3 = rnorm(n_genes),
  conditionB_timet2 = rnorm(n_genes),
  conditionB_timet3 = rnorm(n_genes),
  b0 = abs(rnorm(n_genes)),
  b1 = abs(rnorm(n_genes)),
  b2 = abs(rnorm(n_genes))
)

# Data are organized in counts
dat$counts
# .. and meta data
dat$metadata


}
