Fits the power law \(Q = a (h - c)^b\) by nonlinear least squares on the
original scale of discharge, with the scatter of the gaugings modelled as
set by variance. The curve estimates the mean discharge at each stage.
Usage
rc_powerlaw(
discharge,
stage,
...,
data = NULL,
variance = var_none(),
offset = NULL,
control = stats::nls.control(maxiter = 1000, tol = 1e-06)
)Arguments
- discharge
<
data-masking> Discharge: a vector, or an expression evaluated indata, such as a column name.- stage
<
data-masking> Stage: a vector, or an expression evaluated indata, such as a column name.- ...
Must be empty. Present so that every argument after it has to be named in full.
- data
Optional data frame in which
dischargeandstageare evaluated.- variance
How the variance of the gaugings about the curve is modelled:
var_none()(or"none", the default),var_prop()(or"prop"),var_power()(or"power"), orvar_spec()with the variances. See variance.- offset
The offset, \(c\) in the formula:
NULL(the default) to estimate it, or a known value, below every gauged stage, to hold it fixed.- control
Settings for
stats::nls(), as fromstats::nls.control().
Value
An rc_powerlaw object; see rating_curve for its contents.
The offset
\(c\) is the offset: for a single power law, the stage at which the flow
would stop. It is estimated unless it is given, through offset, say from
a survey of the control. A given offset is held fixed, so the limits from
predict() carry no uncertainty in it. Fixing it at the value estimated by
a first fit treats an estimate as known: the curve is the same, but the
limits are narrower than they should be.
Examples
fit <- rc_powerlaw(discharge, stage, data = thompson)
predict(fit, new_stage = c(1, 3, 6), conflev = 0.95)
#> # A tibble: 3 × 4
#> stage fit ci_lwr ci_upr
#> <dbl> <dbl> <dbl> <dbl>
#> 1 1 243. 222. 264.
#> 2 3 832. 814. 850.
#> 3 6 2209. 2188. 2230.
# constant coefficient of variation instead of constant variance
fit_prop <- rc_powerlaw(discharge, stage, data = thompson, variance = "prop")
predict(fit_prop, new_stage = c(1, 3, 6), conflev = 0.95)
#> # A tibble: 3 × 4
#> stage fit ci_lwr ci_upr
#> <dbl> <dbl> <dbl> <dbl>
#> 1 1 252. 249. 255.
#> 2 3 816. 806. 826.
#> 3 6 2205. 2178. 2232.
# the offset known, say from a survey of the control
rc_powerlaw(discharge, stage, data = thompson, variance = "prop", offset = -1.3)
#> Rating curve model.
#> - Method: rc_powerlaw