winsrch_grid: Evaluate half-window width combinations

View source: R/winsrch_grid.R

winsrch_gridR Documentation

Evaluate half-window width combinations

Description

Evaluate a grid of half-window width combinations to use for weighted regression

Usage

winsrch_grid(dat_in, ...)

## Default S3 method:
winsrch_grid(dat_in, grid_in = NULL, ...)

Arguments

dat_in

input data object to use with weighted regression

...

arguments passed to or from other methods

grid_in

optional input matrix of half-window widths created with createsrch, a default search grid is used if no input

Details

Processing time can be reduced by setting up a parallel backend, as in the examples. Note that this is not effective for small k-values (e.g., < 4) because each fold is sent to a processor, whereas the window width combinations in grid_in are evaluated in sequence.

This function should only be used to view the error surface associated with finite combinations of window-width combinations. A faster function to identify the optimal window widths is provided by winsrch_optim.

Value

A data frame of the search grid with associated errors for each cross-validation result. Errors for each grid row are averages of all errors for each fold used in cross-validation.

See Also

createsrch, wrtdscv, winsrch_optim

Examples

## Not run: 
##
# setup parallel backend
library(doParallel)
ncores <- detectCores() - 2 
registerDoParallel(cores = ncores)

# run search function using default search grid - takes a while
res <- winsrch_grid(tidobjmean)

# view the error surface 
library(ggplot2)
ggplot(res, aes(x = factor(mos), y = factor(yrs), fill = err)) +
   geom_tile() + 
   facet_wrap(~ flo) + 
   scale_x_discrete(expand = c(0, 0)) +
   scale_y_discrete(expand = c(0,0)) +
   scale_fill_gradientn(colours = gradcols()) 

# optimal combo
res[which.min(res$err), ]

##
# create a custom search grid, e.g. years only
grid_in <- createsrch(mos = 1, yrs = seq(1, 10), flo = 1)

res <- winsrch_grid(tidobjmean, grid_in)


## End(Not run)

fawda123/WRTDStidal documentation built on Oct. 22, 2023, 11:28 p.m.