r - R:来自 lm(y~x, data) 的 Abline 不适合我的数据
问题描述
我有两个向量,我正在尝试使用lm(y~x, data)
. 我得到的结果是:
Call:
lm(formula = y ~ x, data = data)
Coefficients:
(Intercept) x
0.5712 -0.1092
此外,在运行时,summary(lm(y~x, data=data))
我的 r 平方为 0.033。你可以在这里看到:
Call:
lm(formula = y ~ x, data = data)
Residuals:
Min 1Q Median 3Q Max
-3.856 -3.018 1.845 2.541 3.695
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.5712 0.8837 0.646 0.526
x -0.1092 0.1374 -0.794 0.437
Residual standard error: 3.033 on 18 degrees of freedom
Multiple R-squared: 0.03387, Adjusted R-squared: -0.0198
F-statistic: 0.631 on 1 and 18 DF, p-value: 0.4373
在绘制结果时,我abline(lm(y~x, data=data))
用我的数据来说明拟合模型。这是情节:
相关性(r 平方)对我来说似乎很好,但拟合线似乎不适合我的数据。我希望这条线更水平,因为现在它似乎代表了高于 0.033 的相关性。任何想法为什么会发生这种情况?
我提供了我正在使用的两个向量:
x <- c(0.000000, 3.731577, 7.159587, 0.000000, 0.000000, 7.525843, 15.890714, 1.122046, 0.000000, 4.517200, 16.086196, 0.000000, 5.091981, 3.285380, 9.600572, 0.000000, 0.000000, 2.253814, 6.190752, 0.000000)
y0 <- c(208.645, 232.990, -838.295, -649.825, -1926.875, -1290.235, -1320.595, -619.325, 1316.910, 787.470, 323.525, 843.570, 90.400, -2040.355, -2635.250, -1240.815, 1288.130, 915.360, 1035.425, 1289.135)
y <- sign(y0)*log10(abs(y0)) # To log both negative and positive values
解决方案
推荐阅读
- android - 多次设置实时数据值仅在最后一次触发观察者
- css - 带有 WebSecurity 的 Spring Boot 应用程序看不到 css
- mysql - 如何创建一个新列来保存具有相同值的所有行的所有主键值?
- python - 测试数据集的标准化
- java - Play 2.6 with Java - 添加环境依赖注入
- html - 为什么下拉列表位于粘性元素下方?
- swift - 点击 NavigationLink 后隐藏导航栏但保留后退按钮
- r - 可变长度不同
- scala - 如何从一个序列中创建两个序列,将一个自定义对象与该序列中的另一个进行比较?
- docker - 如何通过 docker 让 bash shell 访问 vernemq 映像?