fit_lgmr {baldur}R Documentation

Fit Latent Gamma Mixture Regression

Description

[Experimental]

See lgmr_model for model details.

Usage

fit_lgmr(
  data,
  id_col,
  model = lgmr_model,
  iter = 6000,
  warmup = 1500,
  chains = 5,
  cores = 1,
  return_stanfit = FALSE,
  simplify = FALSE,
  ...
)

## S3 method for class 'lgmr'
print(
  x,
  simplify = x$simplify,
  pars = c("auxiliary", "coefficients"),
  digits = 3,
  ...
)

## S3 method for class 'lgmr'
coef(object, simplify = FALSE, pars = c("coefficients", "auxiliary"), ...)

Arguments

data

A data.frame with mean-variance trends to use in the fitting. The columns need to have the following hard-coded names: mean and sd.

id_col

A character for the name of the column containing the name of the features in data (e.g., peptides, proteins, etc.). Has to be a unique identifier for each feature.

model

Defaults to lgmr_model (see it for details on the model), can also be an user supplied stan_model()

iter

Total number of samples to draw

warmup

Number of warm-up samples to draw

chains

Number of chains to run

cores

Number of cores to use per chain

return_stanfit

Should the stanfit object be returned with the model?

simplify

Should only the mean estimates of the posterior be returned?

...

Additional arguments to rstan's sampling. Does nothing for print or coef only for fit_lgmr.

x, object

An lgmr model.

pars

If you want to print/extract the regression coefficients, theta, auxiliary (alpha and NRMSE), or all

digits

Number of digits to print

Value

A fitted lgmr model.

Examples

# Define design matrix
design <- model.matrix(~ 0 + factor(rep(1:2, each = 3)))
colnames(design) <- paste0("ng", c(50, 100))


# Normalize data, calculate M-V trend, and fit LGMR model
yeast_lgmr <- yeast %>%
    # Remove missing values
    tidyr::drop_na() %>%
    # Normalize
    psrn("identifier") %>%
    # Add the mean-variance trends
    calculate_mean_sd_trends(design) %>%
    # Fit the model
    fit_lgmr("identifier")
# Print everything except thetas
print(yeast_lgmr, pars = c("coefficients", "auxiliary"))
# Extract the mean of the model parameters posterior
yeast_lgmr_pars <- coef(yeast_lgmr, pars = 'all', simplify = TRUE)



[Package baldur version 0.0.3 Index]