# targetIntervalResidual: targetIntervalResidual In penaltyLearning: Penalty Learning

## Description

Compute residual of predicted penalties with respect to target intervals. This function is useful for visualizing the errors in a plot of log(penalty) versus a feature.

## Usage

 ```1 2``` ```targetIntervalResidual(target.mat, pred) ```

## Arguments

 `target.mat` n x 2 numeric matrix: target intervals of log(penalty) values that yield minimal incorrect labels. `pred` numeric vector: predicted log(penalty) values.

## Value

numeric vector of n residuals. Predictions that are too high (above target.mat[,2]) get positive residuals (too few changepoints), and predictions that are too low (below target.mat[,1]) get negative residuals.

## Author(s)

Toby Dylan Hocking

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39``` ```library(penaltyLearning) library(data.table) data(neuroblastomaProcessed, envir=environment()) ## The BIC model selection criterion is lambda = log(n), where n is ## the number of data points to segment. This implies log(lambda) = ## log(log(n)), which is the log2.n feature. row.name.vec <- grep( "^(4|520)[.]", rownames(neuroblastomaProcessed\$feature.mat), value=TRUE) feature.mat <- neuroblastomaProcessed\$feature.mat[row.name.vec, ] target.mat <- neuroblastomaProcessed\$target.mat[row.name.vec, ] pred.dt <- data.table( row.name=row.name.vec, target.mat, feature.mat[, "log2.n", drop=FALSE]) pred.dt[, pred.log.lambda := log2.n ] pred.dt[, residual := targetIntervalResidual( cbind(min.L, max.L), pred.log.lambda)] library(ggplot2) limits.dt <- pred.dt[, data.table( log2.n, log.penalty=c(min.L, max.L), limit=rep(c("min", "max"), each=.N))][is.finite(log.penalty)] ggplot()+ geom_abline(slope=1, intercept=0)+ geom_point(aes( log2.n, log.penalty, fill=limit), data=limits.dt, shape=21)+ geom_segment(aes( log2.n, pred.log.lambda, xend=log2.n, yend=pred.log.lambda-residual), data=pred.dt, color="red")+ scale_fill_manual(values=c(min="white", max="black")) ```

penaltyLearning documentation built on July 1, 2020, 10:26 p.m.