在R中对嘈杂的1/x数据进行建模,从摘要中获得本质上完美的拟合-为什么? [英] Modeling noisy 1/x data in R, getting "essentially perfect fit" from summary - why?

查看:22
本文介绍了在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
> 

这条"完美契合"消息的意义是什么?当然,在情节上,这个模型看起来并不"完美"--无论是对嘈杂的数据还是真正的生成源来说都是如此。

推荐答案

我只是在犯傻--评论者指出我在不同的模型上运行摘要。啊。

这篇关于在R中对嘈杂的1/x数据进行建模,从摘要中获得本质上完美的拟合-为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆