Learn R Programming

WpProj (version 0.2.1)

WPR2: \(W_p R^2\) Function to Evaluate Performance

Description

[Experimental] This function will calculate p-Wasserstein distances between the predictions of interest and the projected model.

Usage

WPR2(
  predictions = NULL,
  projected_model,
  p = 2,
  method = "exact",
  base = NULL,
  ...
)

# S4 method for ANY,matrix WPR2( predictions = NULL, projected_model, p = 2, method = "exact", base = NULL, ... )

# S4 method for ANY,distcompare WPR2( predictions = NULL, projected_model, p = 2, method = "exact", base = NULL, ... )

# S4 method for ANY,list WPR2( predictions = NULL, projected_model, p = 2, method = "exact", base = NULL, ... )

# S4 method for ANY,WpProj WPR2( predictions = NULL, projected_model, p = 2, method = "exact", base = NULL, ... )

Value

\(W_p R ^2\) values

Arguments

predictions

Predictions of interest, likely from the original model

projected_model

A matrix of competing predictions, possibly from a WpProj fit, a WpProj fit itself, or a list of WpProj objects

p

Power of the Wasserstein distance to use in distance calculations

method

Method for calculating Wasserstein distance

base

The baseline result to compare to. If not provided, defaults to the model with no covariates and only an intercept.

...

Arguments passed to Wasserstein distance calculation. See wasserstein

Examples

Run this code
if (rlang::is_installed("stats")) {
# this example is not a true posterior estimation, but is used for illustration
n <- 32
p <- 10
s <- 21
x <- matrix( stats::rnorm(n*p), nrow = n, ncol = p )
beta <- (1:10)/10
y <- x %*% beta + stats::rnorm(n)
post_beta <- matrix(beta, nrow=p, ncol=s) + 
    matrix(rnorm(p*s), p, s) # not a true posterior
post_mu <- x %*% post_beta

fit <-  WpProj(X=x, eta=post_mu, power = 2.0)

out <- WPR2(predictions = post_mu, projected_model = fit, 
base = rowMeans(post_mu) # same as intercept only projection
)
}

Run the code above in your browser using DataLab