weitrix_calibrate_trend {weitrix} | R Documentation

## Adjust weights by fitting a trend to estimated dispersions

### Description

Dispersions are estimated using `weitrix_dispersions`. A trend line is then fitted to log dispersions using a linear model. Weitrix weights are calibrated based on this trend line. Any zero or very-near-zero dispersions are ignored when fitting this model.

### Usage

    weitrix_calibrate_trend(weitrix, design = ~1, trend_formula = NULL)

### Arguments

`weitrix` | A weitrix object, or an object that can be converted to a weitrix with `as_weitrix`.
`design` | A formula in terms of `colData(weitrix` or a design matrix, which will be fitted to the weitrix on each row. Can also be a pre-existing Components object, in which case the existing fits (`design$row`) are used.
`trend_formula` | A formula specification for predicting log dispersion from columns of rowData(weitrix). If absent, metadata(weitrix)$weitrix$trend_formula is used.

### Value

A SummarizedExperiment object with metadata fields marking it as a weitrix.

### Examples

    rowData(simwei)$total_weight <- rowSums(weitrix_weights(simwei))

    # To estimate dispersions, use a simple model containing only an intercept
    # term. Model log dispersion as a straight line relationship with log total
    # weight and adjust weights to remove any trend.
    cal <- weitrix_calibrate_trend(simwei,~1,trend_formula=~log(total_weight))

    # This dataset has few rows, so calibration like this is dubious.
    # Predictors in the fitted model are not significant.
    summary( metadata(cal)$weitrix$trend_fit )

    # Information about the calibration is added to rowData
    rowData(cal)

    # A Components object may also be used as the design argument.
    comp <- weitrix_components(simwei, p=1, verbose=FALSE)
    cal2 <- weitrix_calibrate_trend(simwei,comp,trend_formula=~log(total_weight))

    rowData(cal2)

[Package weitrix version 1.0.0 Index]