Learn R Programming

robsurvey (version 0.7)

weighted_line: Weighted Robust Line Fitting

Description

weighted_line fits a robust line and allows weights.

Usage

weighted_line(x, y = NULL, w, na.rm = FALSE, iter = 1)

# S3 method for medline print(x, ...) # S3 method for medline coef(object, ...) # S3 method for medline residuals(object, ...) # S3 method for medline fitted(object, ...)

Value

intercept and slope of the fitted line

Arguments

x

[numeric vector] explanatory variable.

y

[numeric vector] response variable (default: NULL).

w

[numeric vector] weights (same length as x).

na.rm

[logical] indicating whether NA values should be removed before the computation proceeds (default: FALSE).

iter

[integer] number of iterations to use (default: 1).

object

object of class medline.

...

additional arguments passed to the method.

Details

weighted_line uses different quantiles for splitting the sample than stats::line().

See Also

Overview (of all implemented functions)

line

Examples

Run this code
head(cars)

# compute weighted line
weighted_line(cars$speed, cars$dist, w = rep(1, length(cars$speed)))
m <- weighted_line(cars$speed, cars$dist, w = rep(1:10, each = 5))
m
coef(m)
residuals(m)
fitted(m)

Run the code above in your browser using DataLab