Learn R Programming

sommer (version 4.5.27)

familym: Different distribution families for the traits of a multi-trait model

Description

Assigns a stats::family() object to each trait of a long-format multi-trait mmes model, e.g. a binary disease score together with a Gaussian yield. PQL supports its existing working-model covariance structures; native Laplace supports a joint latent-effect likelihood with conditionally independent observations.

Usage

familym(by, ..., trials = NULL)

Value

An object of class "sommer_familym".

Arguments

by

Name (character string) of the column of data that identifies the traits, typically "trait" as created by stackTraits.

...

Family objects named by the levels of the by column, e.g. Disease = binomial(), Yield = gaussian(). Every level present in the data needs a family.

trials

Optional trials-column name for native Laplace fits. Binomial responses are then integer success counts, with positive integer trial totals in this column. All non-binomial rows must have a trial value of one. Omit this argument for binary responses or responses made with binm(). Do not declare trials both here and in a response attribute/matrix.

Details

The object is passed as the family argument of mmes. Each PQL iteration builds the working response and working weights of every row with the family of its trait, and fits a weighted Gaussian multi-trait model.

The residual variance of binomial, Poisson and negative binomial traits is not a free parameter (their dispersion is one), while that of Gaussian and other families is estimated. The residual structure must therefore allow individual trait variances to be fixed: use rcov = ~ vsm(corgm(trait, variance = "heterogeneous"), ism(record)) (trait correlations and heterogeneous variances, see corgm) or rcov = ~ vsm(dsm(trait), ism(units)) (uncorrelated residuals). The first level of the trait factor must be a fixed-dispersion trait, because its variance is the vsm scale; reorder the levels otherwise. mmes then fixes the residual variance of every fixed-dispersion trait to one and estimates the rest.

As for single-family PQL fits, the likelihood, AIC and BIC are NA. The fitted object has a named dispersion vector (one per trait: one for fixed-dispersion traits, the REML residual variance for the others), and fitted() and residuals() apply the inverse link and variance function of each trait to its rows. Random-effect variances are on the link scale of each trait.

For native Laplace, select method=mmes_method(objective="ml", integration="laplace"). Supported families are binomial with logit, probit or complementary log-log link; Poisson-log; zipoisson with an intercept-only or fixed-effects formula logit structural-zero component; nbinom2()-log; Gaussian-identity; and Gamma-log, alongside ordinal with cumulative logit/probit links and multinomial with a joint softmax likelihood. Categorical familym() requires a data frame and one plain numeric long-format response column: each categorical trait uses contiguous codes 1,...,K; probability columns are labelled with these codes. Categorical responses do not support PQL or non-ML objectives. Zero-inflated Poisson is not a hurdle model and its zero component has no random effects. Observations are conditionally independent given the shared random effects. A correlated usm(trait) random covariance can connect traits, but structured residual covariance is not supported on this route: omit rcov or use ~units. There is no requirement to place a fixed-dispersion trait first.

NB2 shape and Gaussian/Gamma dispersion are estimated separately for each declared trait by default; zero-inflated Poisson structural-zero probability is also estimated by default. Configure starting/fixed values under familyParameters, for example list(count=list(theta=2, estimate=FALSE), zeroCount=list(zeroInflation=0.2, estimate=TRUE), continuous=list(dispersion=0.7, estimate=TRUE)). Every declared family must retain observations. Missing trait/trials values participate in the fixed-covariate missing-data policy; unknown non-missing trait labels error. The trials column argument is currently Laplace-only; existing PQL trial responses use binm().

Native fits report an approximate marginal log likelihood, AIC/BIC with estimated shape, dispersion or zero-inflation parameters counted, a familyParameters table for scalar family parameters, zeroCoefficients for formula-based zero components, per-trait dispersion and observation-family indices. Zero-only missing covariates affect only their declared ZIP trait's rows. Fitted values and residuals apply each row's fitted family. New-data response-scale predictions require the declared trait column. Use re.form=NA for zero-random-effect means, re.form=NULL for conditional predictions at known random-effect levels, or re.form="population" for supported population means; see predict.mmes for restrictions.

When categorical traits are present, fitted() and response-scale predict() return a trait-named list: scalar traits have numeric vectors, and ordinal/nominal traits have labelled probability matrices. Link-scale output is also trait-named, with one vector per scalar/ordinal trait and \(K-1\) logits per nominal trait. Scalar-only output is unchanged. Residuals are trait-named; nominal traits support response, Pearson and unsigned deviance residuals, not working or quantile residuals.

Nominal fixed coefficients are expanded by non-reference category. Estimated ordinal cutpoint locations take precedence over aliased fixed location columns; fixed cutpoints retain identified formula intercepts. Cutpoint settings are nested by trait under familyParameters, for example list(rating=list(thresholds=c(-1,1),estimate=FALSE)). The thresholds table identifies each ordinal trait.

Random-effect formulas retain their explicit semantics: repeating nominal predictor rows shares existing random coefficients and never automatically creates independent effects. To request distinct coordinates, use .familyCoordinate in the random formula, for example ~vsm(ism(.familyCoordinate),ism(group)); its levels are "trait:location" for scalar/ordinal traits and "trait:category" for nominal non-reference categories. Correlated coordinates can use explicit covariance descriptors instead. .nominalCategory is reserved for the single-family nominal route and errors in categorical familym() rather than guessing an expansion.

The native mode solver retains full nominal off-diagonal curvature and one likelihood contribution per observation. Mixed nominal outer gradients use central differences of the native block Laplace likelihood; scalar/ordinal outer gradients remain analytic. Standard errors, parameter covariance, prediction uncertainty and PEV remain post-fit through summary(), vcov(), predict(se.fit=TRUE) and postPEV(). Simulation and boot_mmes() support the same categorical composition; simulations use the original numeric category codes and original row order.

See Also

mmes, corgm, stackTraits, covmatrix_mmes

Examples

Run this code
set.seed(12)
ng <- 100; nr <- 4
G <- matrix(c(1, 0.4, 0.4, 0.8), 2)
u <- matrix(rnorm(ng * 2), ng) %*% chol(G)
d <- data.frame(id = factor(rep(paste0("g", 1:ng), each = nr)))
d$disease <- rbinom(nrow(d), 1, plogis(-0.5 + u[as.integer(d$id), 1]))
d$yield <- 10 + u[as.integer(d$id), 2] + rnorm(nrow(d))
L <- stackTraits(d, traits = c("disease", "yield"))

# \donttest{
fit <- mmes(value ~ trait,
  random = ~ vsm(usm(trait), ism(id)),
  rcov = ~ vsm(corgm(trait, variance = "heterogeneous"), ism(record)),
  family = familym("trait", disease = binomial(), yield = gaussian()),
  data = L,
  control = mmes_control(diagnostics = list(verbose = FALSE)))
fit$dispersion
covmatrix_mmes(fit, 1)$correlation   # genetic correlation (link scale)
head(fitted(fit))                    # probabilities for disease rows
# }


Run the code above in your browser using DataLab