gpt4 book ai didi

algorithm - John Tukey "median median"(或 "resistant line")R 和线性回归的统计检验

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:35:32 25 4
gpt4 key购买 nike

我正在搜索 John Tukey 算法,该算法使用 R 在我的线性回归上计算“阻力线”或“中值-中值线”。

邮件列表上的一位学生用这些术语解释了这个算法:

"The way it's calculated is to divide the data into three groups, find the x-median and y-median values (called the summary point) for each group, and then use those three summary points to determine the line. The outer two summary points determine the slope, and an average of all of them determines the intercept."

关于 John tukey 好奇中位数的文章:http://www.johndcook.com/blog/2009/06/23/tukey-median-ninther/

你知道我在哪里可以找到这个算法或 R 函数吗?在哪些包中,非常感谢!

最佳答案

里面有关于如何计算中线here的说明.一个 R 实现是

median_median_line <- function(x, y, data)
{
if(!missing(data))
{
x <- eval(substitute(x), data)
y <- eval(substitute(y), data)
}

stopifnot(length(x) == length(y))

#Step 1
one_third_length <- floor(length(x) / 3)
groups <- rep(1:3, times = switch((length(x) %% 3) + 1,
one_third_length,
c(one_third_length, one_third_length + 1, one_third_length),
c(one_third_length + 1, one_third_length, one_third_length + 1)
))

#Step 2
x <- sort(x)
y <- sort(y)

#Step 3
median_x <- tapply(x, groups, median)
median_y <- tapply(y, groups, median)

#Step 4
slope <- (median_y[3] - median_y[1]) / (median_x[3] - median_x[1])
intercept <- median_y[1] - slope * median_x[1]

#Step 5
middle_prediction <- intercept + slope * median_x[2]
intercept <- intercept + (median_y[2] - middle_prediction) / 3
c(intercept = unname(intercept), slope = unname(slope))
}

为了测试它,这里有一个例子:

dfr <- data.frame(
time = c(.16, .24, .25, .30, .30, .32, .36, .36, .50, .50, .57, .61, .61, .68, .72, .72, .83, .88, .89),
distance = c(12.1, 29.8, 32.7, 42.8, 44.2, 55.8, 63.5, 65.1, 124.6, 129.7, 150.2, 182.2, 189.4, 220.4, 250.4, 261.0, 334.5, 375.5, 399.1))

median_median_line(time, distance, dfr)
#intercept slope
# -113.6 520.0

请注意指定组的方式有点奇怪。这些说明对于如何定义组大小非常挑剔,因此更明显的方法 cut(x, quantile(x, seq.int(0, 1, 1/3))) 没有工作。

关于algorithm - John Tukey "median median"(或 "resistant line")R 和线性回归的统计检验,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3224731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com