Skip to contents

This function processes a prediction grid by filtering and scaling its z values. It first sorts the grid by descending z, then cumulatively sums the values until a specified threshold is reached. All remaining z values beyond the threshold are set to zero. Finally, the remaining z values are linearly scaled to the range 0, 1, with the maximum value becoming 1. The original row order of the input grid is preserved in the output.

Usage

scale_z(grid, threshold = 0.95)

Arguments

grid

A data frame containing columns x, y, and z.

threshold

A numeric value between 0 and 1 specifying the cumulative proportion of z values to retain. Default is 0.95.

Value

A data frame with the same structure and row order as the input grid, with filtered and scaled z values.

Examples

if (FALSE) { # \dontrun{
grid <- expand.grid(x = seq(0, 1000, length.out = 50),
                    y = seq(0, 1000, length.out = 50))
grid$z <- with(grid, exp(-((x - 500)^2 + (y - 500)^2) / 1e5))
scaled_grid <- scale_z(grid, threshold = 0.95)
} # }