PIT_local {recalibratiNN} | R Documentation |
Obtain local PIT-values from a model
Description
Return local PIT-values. Centroids for localization is obtained by k-means method from stats package. The vicinity of such centroids are selected though a aproximate k-nearst neighboors method from RANN package.
Usage
PIT_local(
xcal,
ycal,
yhat,
mse,
clusters = 6,
p_neighbours = 0.2,
PIT = PIT_global
)
Arguments
xcal |
features/covariates from calibration set |
ycal |
observations of calibration set |
yhat |
predicted outputs from the calibrations et |
mse |
Mean Squared Error of the model |
clusters |
Number of partitions to create for local calibration. Centroids calculated by k-means method. Default set to 6. |
p_neighbours |
Proportion of xcal to localize neighboors in the KNN method. Default is 0.2. |
PIT |
function to return the PIT-values. Default set to PIT_global() from this package. |
Value
A tibble with five containing in the first column containing unique names for the partition, "y_cal", the second column containing the yhat the third the pit-values and the last the number of neighbors in each partition.
Examples
n <- 10000
split <- 0.8
mu <- function(x1){
10 + 5*x1^2
}
sigma_v <- function(x1){
30*x1
}
x <- runif(n, 1, 10)
y <- rnorm(n, mu(x), sigma_v(x))
x_train <- x[1:(n*split)]
y_train <- y[1:(n*split)]
x_cal <- x[(n*split+1):n]
y_cal <- y[(n*split+1):n]
model <- lm(y_train ~ x_train)
y_hat <- predict(model, newdata=data.frame(x_train=x_cal))
MSE_cal <- mean((y_hat - y_cal)^2)
PIT_local(xcal = x_cal, ycal=y_cal, yhat=y_hat, mse=MSE_cal)