Description Usage Arguments Details Value See Also Examples
For type medslopes the median individual ratios response/explanatory is used as estimator of the slope. For version ratiomeds the ratio of the median crossproduct to the median of squares of the explanatory variable is used as the estimator of the slope. Survey weights may be used. Missing values are neglected.
1 | weighted_median_line(x, y = NULL, w, type = "slopes", na.rm = FALSE)
|
x |
a numeric vector (explanatory variable) |
y |
a numeric vector (response variable) |
w |
a numeric vector of weights |
type |
either "slopes" (default) or "products" |
na.rm |
a logical value indicating whether rows with |
Uses weighted_median()
. The median of slopes (type="slopes")
uses b1=M((y-M(y,w))/(x-M(x,w)), w). The median of crossproducts
by median of squares (type="products") uses
b1=M((y-M(y,w))(x-M(x,w)), w )/ M((x-M(x,w )^2), w ), where
M(x, w) is shorthand for the function weighted_median(x, w)
.
The function allows weights and missing values.
a vector with two components: intercept and slope
line
, weighted_line
,
weighted_median_ratio
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | x <- c(1, 2, 4, 5)
y <- c(3, 2, 7, 4)
weighted_line(y~x, w=rep(1, length(x)))
weighted_median_line(y~x, w=rep(1, length(x)))
weighted_median_line(y~x, w=rep(1, length(x)), type="prod")
data(cars)
with(cars, weighted_median_line(dist ~ speed, w=rep(1, length(dist))))
with(cars, weighted_median_line(dist ~ speed, w=rep(1, length(dist)), type="prod"))
# weighted
w <- c(rep(1,20), rep(2,20), rep(5, 10))
with(cars, weighted_median_line(dist ~ speed, w=w))
with(cars, weighted_median_line(dist ~ speed, w=w, type="prod"))
# outlier in y
cars$dist[49] <- 360
with(cars, weighted_median_line(dist ~ speed, w=w))
with(cars, weighted_median_line(dist ~ speed, w=w, type="prod"))
# outlier in x
data(cars)
cars$speed[49] <- 72
with(cars, weighted_median_line(dist ~ speed, w=w))
with(cars, weighted_median_line(dist ~ speed, w=w, type="prod"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.