weitrix_calibrate_trend.Rd
Dispersions are estimated using weitrix_dispersions
.
A trend line is then fitted to the dispersions using a gamma GLM
with log link function.
Weitrix weights are calibrated based on this trend line.
weitrix_calibrate_trend(weitrix, design = ~1, trend_formula = NULL)
weitrix | A weitrix object, or an object that can be converted to a weitrix
with |
---|---|
design | A formula in terms of |
trend_formula | A formula specification for predicting log dispersion from columns of rowData(weitrix). If absent, metadata(weitrix)$weitrix$calibrate_trend_formula is used. |
A SummarizedExperiment object with metadata fields marking it as a weitrix.
Several columns are added to the rowData
:
deg_free Degrees of freedom for dispersion calculation.
dispersion_before Dispersion before calibration.
dispersion_trend Fitted dispersion trend.
dispersion_after Dispersion for these new weights.
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 )#> #> Call: #> glm2(formula = dispersion_before ~ log(total_weight), family = quasi(link = "log", #> variance = "mu^2"), data = data, weights = deg_free, mustart = rep(4.76135247187724, #> 7L), control = glm.control(maxit = 100)) #> #> Deviance Residuals: #> 1 2 3 4 5 6 7 #> 1.44877 -2.29771 0.09477 -1.78002 0.92857 -2.50202 1.42802 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 2.5919 3.3847 0.766 0.478 #> log(total_weight) -0.4208 1.2861 -0.327 0.757 #> #> (Dispersion parameter for quasi family taken to be 2.918346) #> #> Null deviance: 20.024 on 6 degrees of freedom #> Residual deviance: 19.717 on 5 degrees of freedom #> AIC: NA #> #> Number of Fisher Scoring iterations: 4 #># Information about the calibration is added to rowData rowData(cal)#> DataFrame with 7 rows and 5 columns #> total_weight deg_free dispersion_before dispersion_trend dispersion_after #> <numeric> <numeric> <numeric> <numeric> <numeric> #> 1 17 3 8.450213 4.05439 2.084216 #> 2 13 4 1.099683 4.53885 0.242282 #> 3 8 4 5.835569 5.56756 1.048138 #> 4 14 4 1.548783 4.39951 0.352036 #> 5 14 4 6.769756 4.39951 1.538754 #> 6 19 4 0.800404 3.86901 0.206875 #> 7 15 3 8.825060 4.27363 2.065005# 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)#> DataFrame with 7 rows and 5 columns #> total_weight deg_free dispersion_before dispersion_trend dispersion_after #> <numeric> <numeric> <numeric> <numeric> <numeric> #> 1 17 2 1.0079171 0.741661 1.359001 #> 2 13 3 0.5202573 0.477358 1.089869 #> 3 8 3 0.2363459 0.215038 1.099088 #> 4 14 3 0.7226663 0.539147 1.340387 #> 5 14 3 0.3295984 0.539147 0.611333 #> 6 19 3 1.0479446 0.890320 1.177043 #> 7 15 2 0.0992827 0.603841 0.164419