Skip to content

Commit

Permalink
correct 2D extrapolation method
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeBiessy committed Sep 7, 2023
1 parent 077a4b7 commit 6ede647
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions R/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ predict.WH_2d <- function(object, newdata = NULL, ...) {
n_sup <- map2(data, full_data, \(x,y) sum(y > max(x)), "integer")
n_tot <- n + n_inf + n_sup

prod_n <- prod(n)
prod_n_tot <- prod(n_inf + n + n_sup)

ind_rows <- c(rep(FALSE, n_inf[[1]]), rep(TRUE, n[[1]]), rep(FALSE, n_sup[[1]]))
Expand All @@ -515,10 +516,21 @@ predict.WH_2d <- function(object, newdata = NULL, ...) {
diag(P_pred[ind_fit, ind_fit]) <- diag(P_pred[ind_fit, ind_fit]) + c(object$wt)
Psi_pred <- P_pred |> chol() |> chol2inv() # unconstrained variance / covariance matrix

A_aux <- Psi_pred[,ind_fit] %*% (Psi_pred[ind_fit, ind_fit] |> chol() |> chol2inv())
Psi <- object$U %*% object$Psi %*% t(object$U)

y_pred <- A_aux %*% c(object$y_hat)
std_y_pred <- sqrt(rowSums(A_aux * (A_aux %*% (object$U %*% object$Psi %*% t(object$U)))))
Psi_11_m <- Psi_pred[ind_fit, ind_fit] |> chol() |> chol2inv()
Psi_21 <- Psi_pred[- ind_fit, ind_fit]

A_aux <- matrix(0, prod_n_tot, prod_n)
diag(A_aux[ind_fit,]) <- 1
A_aux[- ind_fit,] <- Psi_21 %*% Psi_11_m

y_pred <- c(A_aux %*% Psi %*% c(object$wt * object$z))

std_y_pred <- rowSums(A_aux * (A_aux %*% Psi))
std_y_pred[- ind_fit] <- std_y_pred[- ind_fit] +
diag(Psi_pred)[- ind_fit] - rowSums(Psi_21 * (Psi_21 %*% Psi_11_m))
std_y_pred <- sqrt(std_y_pred)

dim(y_pred) <- dim(std_y_pred) <- n_tot # set dimension for output matrices
dimnames(y_pred) <- dimnames(std_y_pred) <- full_data # set names for output matrices
Expand Down

0 comments on commit 6ede647

Please sign in to comment.