r - 在 R 中建模嘈杂的 1/x 数据,从摘要中获得“基本上完美的拟合” - 为什么?
问题描述
只是想通过以下玩具示例让自己了解如何将倒数函数拟合到数据中:
# includes
library(ggplot2)
library(forecast)
library(scales)
# make data
sampledata <- as.data.frame( .1 * seq(1, 20))
names(sampledata) <- c("index")
sampledata$truevalue <- (1/sampledata$index)
# make noisy data
sampledata$noise <- runif(20, .5, 1.5)
sampledata$noisyvalue <-sampledata$noise * (1/sampledata$index)
# linearize transformation
sampledata$invvalue <- 1/sampledata$noisyvalue
# linear model
samplemodel <- lm(sampledata$invvalue ~ sampledata$index)
# predict
sampledata$predictedValues_hat <- predict(samplemodel, newdata=as.data.frame(sampledata$index))
# de-transform
sampledata$predictedvalues <- 1/sampledata$predictedValues_hat
# plot
sampleplot <- ggplot(data = sampledata, aes(x = index, y = noisyvalue)) +
geom_point() +
geom_line(color = 'red', data = sampledata, aes(x = index, y = sampledata$truevalue)) +
ggtitle("1/x Modeling Example") +
theme(plot.title = element_text(color="black", size=14, face="bold", hjust = .5)) +
geom_line(color = 'blue', data = sampledata, aes(x = index, y = sampledata$predictedvalues)) +
scale_x_continuous(breaks=seq(0, 10))
show(sampleplot)
这似乎或多或少都可以,但是当我查看模型摘要时,我不明白发生了什么。每次运行,我都会得到相同的结果:
> summary(model)
Call:
lm(formula = sampledata$invvalue ~ sampledata$index)
Residuals:
Min 1Q Median 3Q Max
-3.211e-16 -2.215e-16 -1.218e-16 1.251e-16 6.001e-16
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 6.641e-01 1.879e-16 3.535e+15 <2e-16 ***
sampledata$index 1.000e+00 3.176e-17 3.149e+16 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.331e-16 on 9 degrees of freedom
Multiple R-squared: 1, Adjusted R-squared: 1
F-statistic: 9.916e+32 on 1 and 9 DF, p-value: < 2.2e-16
Warning message:
In summary.lm(model) : essentially perfect fit: summary may be unreliable
>
这个“完美契合”信息的意义是什么?它在图上看起来肯定不像模型是“完美的”——无论是嘈杂的数据还是真正的生成源。
解决方案
我只是愚蠢-评论者指出我正在对不同的模型进行摘要。啊。
推荐阅读
- c# - NSwag Wep Api 2 multipart/form-data 属性/文件上传
- php - 获取不包括失败的客户订单数 - WooCommerce
- amazon-web-services - 尝试使用 cloudformation 创建用户池时出现验证错误
- javascript - VUE JS 在点击时将数据添加到数据绑定
- java - Maven 错误 - 无法在 Eclipse 中创建 Maven 项目
- android - 在 React-Native 中使用 base64 编码的字符串播放视频
- unity3d - Сhange 渲染纹理分辨率(Resize)
- oracle11g - 从 CLOB 列中提取某些行
- php - PHP - 将相同长度的数组合并为关联
- sqlite - 如何在 Raspberry 上的 SQLite 中创建表