response: response

View source: R/response.R

responseR Documentation

response

Description

This function takes a model object and extracts the responses from step_distributed_lag, step_lead_lag, step_harmonic and step_earthtide.

Usage

response(fit, rec, verbose = FALSE, ...)

## S3 method for class 'lm'
response(fit, rec, verbose = FALSE, ...)

## S3 method for class 'cv.glmnet'
response(fit, rec, verbose = FALSE, ...)

## S3 method for class 'numeric'
response(fit, rec, verbose = FALSE, ...)

Arguments

fit

A model object that has a coefficients method (e.g. lm)

rec

A prepped recipe

verbose

Print names of steps with no response methods

...

Currently not used

Details

step_distributed_lag and step_lead_lag result in impulse response functions and step_harmonic and step_earthtide result in harmonic components (amplitude and phase for each main frequency).

Value

A data.frame of impulse response functions, or harmonic components corresponding to each step.

Examples

data(transducer)
transducer$datetime_num <- as.numeric(transducer$datetime)

rec_toll_rasmussen <- recipe(wl~baro + datetime_num, transducer) |>
   step_lead_lag(baro, lag = log_lags(100, 86400 * 2 / 120)) |>
   step_ns(datetime_num, deg_free = 10) |>
   prep()

input_toll_rasmussen <- rec_toll_rasmussen |> bake(new_data = NULL)

fit_toll_rasmussen <- lm(wl~., input_toll_rasmussen)
resp <- response(fit_toll_rasmussen,
                 rec_toll_rasmussen)
plot(value~x, resp[resp$name == 'cumulative',], type = 'l')

hydrorecipes documentation built on June 27, 2022, 9:06 a.m.