From 1531da7f19eac8575654865b81ff1b2e260fe2f6 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 9 Dec 2021 18:29:04 +0100 Subject: [PATCH] add: df and AIC/BIC to Reg. Matrix Regression --- tensorPredictors/R/RMReg.R | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tensorPredictors/R/RMReg.R b/tensorPredictors/R/RMReg.R index 8b9b9bb..0429518 100644 --- a/tensorPredictors/R/RMReg.R +++ b/tensorPredictors/R/RMReg.R @@ -149,8 +149,14 @@ RMReg <- function(X, Z, y, lambda = 0, a1 <- alpha(a1, iter) } - # ### Degrees of Freedom estimate - # df <- + ### Degrees of Freedom estimate (TODO: this is like in `matrix_sparsereg.m`) + sigma <- c(La.svd(A, 0, 0)$d, rep(0, max(shape) - min(shape))) + df <- if (!is.null(ZZiZ)) { ncol(Z) } else { 0 } + for (i in seq_len(sum(b1 > 0))) { + df <- df + 1 + sigma[i] * (sigma[i] - delta * lambda) * ( + sum(ifelse((1:shape[1]) != i, 1 / (sigma[i]^2 - sigma[1:shape[1]]^2), 0)) + + sum(ifelse((1:shape[2]) != i, 1 / (sigma[i]^2 - sigma[1:shape[2]]^2), 0))) + } # return estimates and some additional stats list( @@ -158,13 +164,10 @@ RMReg <- function(X, Z, y, lambda = 0, beta = if(is.null(ZZiZ)) { NULL } else { beta }, singular.values = b1, iter = iter, - df = "?", - AIC = "?", - BIC = "?", + df = df, + loss = loss1, + AIC = loss1 / var(y) + 2 * df, + BIC = loss1 / var(y) + log(nrow(X)) * df, call = match.call() # invocing function call, collects params like lambda ) } - -rmr.fit <- RMReg(X, NULL, y, lambda = 0) -rmr.fit$iter -rmr.fit$singular.values[rmr.fit$singular.values > 0]