我已经在两项不同的视觉感知测试中对大量参与者进行了测试——现在,我想看看这两项测试的表现有多大程度的相关性。
为了可视化相关性,我使用 R 绘制了散点图ggplot()
我拟合了一条回归线(使用stat_smooth()
)。然而,由于我的两个x
and y
变量是性能指标,在拟合回归线时我需要考虑到它们——因此,我不能使用简单的线性回归(使用stat_smooth(method="lm")
),而是需要拟合正交回归(或总最小二乘法)。我该怎么做呢?
我知道我可以指定formula
in stat_smooth()
,但我不知道该使用什么公式。据我了解,没有任何预设方法(lm, glm, gam, loess, rlm
) 均适用。
事实证明,您可以从 (x,y) 的主成分分析中提取斜率和截距,如图所示here。这只是稍微简单一点,在基础 R 中运行,并给出与使用相同的结果Deming(...)
in MethComp
.
# same `x and `y` as @user20650's answer
df <- data.frame(y, x)
pca <- prcomp(~x+y, df)
slp <- with(pca, rotation[2,1] / rotation[1,1])
int <- with(pca, center[2] - slp*center[1])
ggplot(df, aes(x,y)) +
geom_point() +
stat_smooth(method=lm, color="green", se=FALSE) +
geom_abline(slope=slp, intercept=int, color="blue")
![](https://i.stack.imgur.com/eCRRx.png)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)