Assess trajectory recovery performance for a single cell.
Source:R/assess_recov_traj.R
assess_recov_traj.Rd
Computes \(R^2\) metrics comparing observed trajectories with those recovered by Kernel ODE.
Value
A list containing:
R2
An overall \(R^2\) value (a scalar) as the average of the variable-specific \(R^2\) values (stored in
R2_per_var_vec
), representing the overall proportion of variance explained by the recovered trajectories.R2_per_var_vec
A numeric vector of length
p
giving the variable-specific \(R^2\) values.
Details
The \(R^2\) metric for variable \(j\) is defined as $$R_j^{2} = \max \left\{ 1 - \frac{\mathrm{MSS}_{j,\mathrm{res}}}{\mathrm{MSS}_{j,\mathrm{tot}}}, \; 0 \right\},$$ where $$\mathrm{MSS}_{j,\mathrm{res}} = \frac{1}{n}\sum_{i=1}^n \left( y_{ij} - \hat{y}_{ij} \right)^2,$$ $$\mathrm{MSS}_{j,\mathrm{tot}} = \frac{1}{n}\sum_{i=1}^n \left( y_{ij} - \bar{y}_j \right)^2.$$
The overall \(R^2\) is the average of the variable-specific \(R^2\) values: $$R^{2} = \frac{1}{p}\sum_{j=1}^{p} R_j^{2}.$$
Examples
set.seed(1)
obs_time <- seq(0, 1, length.out = 10)
Y <- cbind(sin(2 * pi * obs_time), cos(4 * pi * obs_time)) + 0.1 * matrix(rnorm(20), 10, 2) # each col is a variable
Y_est <- sapply(1:ncol(Y), function(j){lm(Y[,j] ~ obs_time)$fitted.values}) # linear regression
assess_recov_traj(Y = Y, Y_est = Y_est)
#> $R2
#> [1] 0.1927641
#>
#> $R2_per_var_vec
#> [1] 0.3852167627 0.0003113457
#>