首页 > 解决方案 > 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

标签: rstatistics

解决方案


推荐阅读