regress: Regresses one set of CRHM observations against another

View source: R/regress.R

regressR Documentation

Regresses one set of CRHM observations against another

Description

The purpose of this function is to generate the multiplier and an offset values (if required) used by the impute function. Therefore, it performs a linear (least-squares) regression of the primary dataset (the values to be produced by imputation) against the secondary dataset. The function removes missing values and merges the data sets together before doing the regression to ensure that the variables are aligned by datetime.

Usage

regress(
  primaryCRHM,
  primary.columns = 1,
  secondaryCRHM,
  secondary.columns = 1,
  forceOrigin = FALSE,
  plot = FALSE,
  quiet = TRUE,
  logfile = ""
)

Arguments

primaryCRHM

Required. The primary CRHMr data frame.

primary.columns

Optional. Optional. A vector containing the columns to be imputed in the primary data frame, not including the datetime. If not specified, defaults to the first column.

secondaryCRHM

Required. The secondary CRHMr data frame.

secondary.columns

Optional. A vector containing the columns to be imputed in the secondary data frame, not including the datetime. If not specified, defaults to the first column.

forceOrigin

Optional. If TRUE then the regressions will be forced through the origin. Note that in this case the values of r^2 and the intercept will not be calculated as they have no meaning.

plot

Optional. Set plot=TRUE if you want a plot for each regression. Default is FALSE. The function has to guess the axis units from the variable names and it may be mistaken; you can always change the labels.

quiet

Optional. Suppresses display of messages, except for errors. If you are calling this function in an R script, you will usually leave quiet=TRUE (i.e. the default). If you are working interactively, you will probably want to set quiet=FALSE.

logfile

Optional. Name of the file to be used for logging the action. Normally not used.

Value

If successful, and plot=TRUE, returns a plot of all of the regressions. If successful, and plot=FALSE, returns a data frame containing the regression parameters. If unsuccessful, returns FALSE.

Note

If successful, exports a data frame with the columns xvals (secondary data frame), yvals (primary data frame), first date (in common data frame), last date (in common data frame), and slope for each variable to the regression file. If forceOrigin=FALSE then the parameters intercept, and r2 will also be returned. This function will not permit regression on RH values, so convert these to Ea values first.

Author(s)

Kevin Shook

See Also

impute

Examples

# this would be used to get the regression coefficients used to impute data from Saskatoon
# to fill gaps in the Regina data
## Not run: 
reg <- regress(regina, c(1,2,3), saskatoon, c(1,2,3))
## End(Not run)

CentreForHydrology/CRHMr documentation built on April 6, 2024, 5:27 p.m.