Skip to contents

Obtain predicted density ratio values from a lhss object

Usage

# S3 method for class 'lhss'
predict(
  object,
  newdata = NULL,
  sigma = c("sigmaopt", "all"),
  lambda = c("lambdaopt", "all"),
  ...
)

Arguments

object

A lhss object

newdata

Optional matrix new data set to compute the density

sigma

A scalar with the Gaussian kernel width

lambda

A scalar with the regularization parameter

...

Additional arguments to be passed to the function

Value

An array with predicted density ratio values from possibly new data, but otherwise the numerator samples.

See also

Examples

set.seed(123)
# Fit model (minimal example to limit computation time)
dr <- lhss(numerator_small, denominator_small,
           nsigma = 5, nlambda = 3, ncenters = 50, maxit = 100)
# Inspect model object
dr
#> 
#> Call:
#> lhss(df_numerator = numerator_small, df_denominator = denominator_small,     nsigma = 5, nlambda = 3, ncenters = 50, maxit = 100)
#> 
#> Kernel Information:
#>   Kernel type: Gaussian with L2 norm distances
#>   Number of kernels: 50
#>   sigma: num [1:5, 1:3] 0.00952 0.36681 1.30318 3.4202 10.53644 ...
#> 
#> Regularization parameter (lambda): num [1:3] 1e+03 1e+00 1e-03
#> 
#> Subspace dimension (m): 1
#> Optimal sigma: 0.3841266
#> Optimal lambda: 1
#> Optimal kernel weights (loocv): num [1:51] 0.2707 0.0121 0.097 0.0135 0.0836 ...
#>  
# Obtain summary of model object
summary(dr)
#> 
#> Call:
#> lhss(df_numerator = numerator_small, df_denominator = denominator_small,     nsigma = 5, nlambda = 3, ncenters = 50, maxit = 100)
#> 
#> Kernel Information:
#>   Kernel type: Gaussian with L2 norm distances
#>   Number of kernels: 50
#> 
#> Subspace dimension (m): 1
#> Optimal sigma: 0.3841266
#> Optimal lambda: 1
#> Optimal kernel weights (loocv): num [1:51] 0.2707 0.0121 0.097 0.0135 0.0836 ...
#>  
#> Pearson divergence between P(nu) and P(de): 0.2529
#> For a two-sample homogeneity test, use 'summary(x, test = TRUE)'.
#> 
# Plot model object
plot(dr)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Plot density ratio for each variable individually
plot_univariate(dr)
#> [[1]]

#> 
#> [[2]]

#> 
#> [[3]]

#> 
# Plot density ratio for each pair of variables
plot_bivariate(dr)
#> [[1]]

#> 
#> [[2]]

#> 
#> [[3]]

#> 
# Predict density ratio and inspect first 6 predictions
head(predict(dr))
#> , , 1
#> 
#>           [,1]
#> [1,] 0.8873535
#> [2,] 1.0458496
#> [3,] 0.8122089
#> [4,] 0.4962786
#> [5,] 1.3122394
#> [6,] 1.3092069
#>