Learn R Programming

sommer (version 4.5.12)

binm: Binomial proportion response with its number of trials

Description

Builds a single proportion response for binomial mmes fits from counts of successes and failures (or trials). The number of trials travels with the proportion as an attribute and is used as the binomial prior weight, so the single-response interface of mmes is preserved.

Usage

binm(successes, failures = NULL, trials = NULL)

Value

A numeric vector of proportions of class "binm".

Arguments

successes

Numeric vector of successes.

failures

Numeric vector of failures. Provide either failures or trials.

trials

Numeric vector with the number of trials.

Details

The result is successes/trials with class "binm" and attribute "trials". Subsetting keeps the trials aligned, so the vector can be stored as a data-frame column. Missing counts give a missing response, handled by the naMethodY rules of mmes. Fitting a proportion without binm treats every value as one trial, which is wrong unless all trials equal one.

See Also

mmes

Examples

Run this code
set.seed(1)
d <- data.frame(x = rnorm(60), g = factor(rep(1:12, each = 5)))
d$n <- sample(5:10, 60, TRUE)
d$s <- rbinom(60, d$n, plogis(0.3 * d$x))
fit <- mmes(binm(s, trials = n) ~ x,
  random = ~ g,
  data = d,
  family = binomial(),
  control = mmes_control(update = list(blendWeight = 0),
  diagnostics = list(verbose = FALSE)))
fit$b

Run the code above in your browser using DataLab