Fit weighted regression and get predicted/normalized response variable from a data frame. This is a wrapper for multiple function used to create a weighted regression model and should be used rather than the individual functions.

modfit(dat_in, ...)

# S3 method for default
modfit(dat_in, ...)

# S3 method for tidal
modfit(dat_in, ...)

# S3 method for tidalmean
modfit(dat_in, ...)

# S3 method for data.frame
modfit(dat_in, resp_type = "quantile", ...)

Arguments

dat_in

input data.frame for fitting the model, see details

...

arguments passed to or from other methods

resp_type

chr string indicating the type of model response to use, quantile or mean model

Value

A tidal object with predicted and normalized response variable predictions, attributes updated accordingly.

Details

This function is used as a convenience to combine several functions that accomplish specific tasks, primarily the creation of a tidal or tidalmean object, fitting of the weighted regression models with wrtds, extraction of fitted values from the interpolation grids using respred, and normalization of the fitted values from the interpolation grid using resnorm. The format of the input should be a data.frame with response variable observations as rows and the first four columns as date, response variable, salinity/flow, and detection limits. The order of the columns may vary provided the order of each of the four critical variables is specified by the ind argument that is passed to the tidal or tidalmean function. The response variable data are also assumed to be in log-space, otherwise use reslog = FALSE which is also passed to the tidal or tidalmean function. The dataset described in chldat is an example of the correct format.

For quantile models, the default conditional quantile that is predicted is the median (tau = 0.5, passed to the wrtds function). Numerous other arguments affect the output and the default parameters may not be appropriate for all scenarios. Arguments used by other functions can be specified explicitly with the initial call. The documentation for the functions under `see also' should be consulted for available arguments, as well as the examples that illustrate common changes to the default values.

See also

See the help files for tidal, tidalmean, wrtds, getwts, respred, and resnorm for arguments that can be passed to this function.

Examples

if (FALSE) {
## load data
data(chldat)

## fit the model and get predicted/normalized data for response variable
# default median fit
# grids predicted across salinity range with ten values
res <- modfit(chldat)

# for mean models
res <- modfit(chldat, resp_type = 'mean')

## fit different quantiles and smaller interpolation grid
res <- modfit(chldat, tau = c(0.2, 0.8), flo_div = 5)

## fit with different window widths
# half-window widths of one day, five years, and 0.3 salinity
res <- modfit(chldat, wins = list(1, 5, 0.3))

## suppress console output
res <- modfit(chldat, trace = FALSE)
}