0

我正在尝试在 R 中运行基本的时间序列回归。

reg<-lm(y~x)
summary(reg)
Call:lm(formula = y ~ x)

Residuals:
     Min       1Q   Median       3Q      Max 
-100.188  -21.600    0.503   21.999   97.296 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 102.53835    4.66296  21.990   <2e-16 ***
x            -0.03687    0.04524  -0.815    0.415   

但是,我还想要 y 变量、模型的投影和下面的残差的可视化图。R中是否有能力进行这种回归?谢谢!

4

1 回答 1

2

我不完全确定你想要绘制什么。以下为您提供了两张图 - 一张带有数据和模型预测,另一张带有残差。

par(mfrow=c(2,1))  # Two plots in one window

plot(x,y)                # Your datapoints
lines(x,predict(reg))    # The model prediction

plot(x, residuals(reg), ylab='Residuals')    # x vs. residuals

R 的线性模型绘图工具相当不错。我强烈建议您查看 的输出plot(reg),如果解释正确,它可能会为您提供比绘图更多的信息。

于 2012-12-15T07:55:41.243 回答