[R] Problems with Durbin Watson and Partial Residual Plots

John Fox jfox at mcmaster.ca
Tue Nov 2 21:23:23 CET 2004


Dear Cal,

The functions that you mention are in the car package.

The problems that you've encountered seem very odd to me. For example, if
you take a look at durbin.watson.lm(), you'll see that the code producing
the errors is quite straight-forward; it just extracts residuals from the
model and checks for NAs:

    residuals <- residuals(model)
    if (any(is.na(residuals))) 
        stop("residuals include missing values") 

Likewise, what's going on inside of cr.plot.lm() is also pretty simple.

Can you send the data set on which this regression was based?

John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
-------------------------------- 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Cal Tate
> Sent: Tuesday, November 02, 2004 2:24 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Problems with Durbin Watson and Partial Residual Plots
> 
> I am trying to evaluate a model by using the commands 
> durbin.watson and cr.plot.
> However, I keep getting errors that I can't figure out. A 
> description follows. Does anyone have a hint as to what may be wrong?
>  
>  
> 1)The Durbin Watson Test. In running the command I kept 
> getting the message "residuals include missing values" when 
> actually this was NOT the case.
>  
> Example:
> >durbin.watson(hw8LM0)
> Error in durbin.watson.lm(hw8LM0) : residuals include missing values
> 
> (2)Partial Residual Plots: Here I kept getting that the 
> variables I choose are not in the model, i.e. "Time is not in 
> the model" when it clearly is.
> 
> Example:
> >cr.plot(hw8LM0,variable="Time")
> Error in cr.plot.lm(hw8LM0, variable = "Time") : 
>         Time is not in the model.
> 
> Here is the model and residuals:
>  summary(hw8LM0)
> Call:
> lm(formula = Sales ~ Time)
> Residuals:
>     Min      1Q  Median      3Q     Max 
> -516.32 -292.95  -29.15  238.48  895.09
> Coefficients:
>             Estimate Std. Error t value Pr(>|t|)    
> (Intercept) 1418.872    122.464   11.59 2.35e-14 ***
> Time          73.278      4.962   14.77  < 2e-16 ***
> ---
> Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 
> 1 Residual standard error: 389.8 on 40 degrees of freedom
> Multiple R-Squared: 0.845,      Adjusted R-squared: 0.8411 
> F-statistic: 218.1 on 1 and 40 DF,  p-value: < 2.2e-16 
> 
> hw8LM0$res
>           1           2           3           4           5   
>         6 
>  242.679535  679.531369  895.093204  442.975038 -237.443127  
> 245.868708 
>           7           8           9          10          11   
>        12 
>   82.540542  -13.347623 -209.325789  161.976046  -96.612120 
> -271.380285 
>          13          14          15          16          17   
>        18 
> -460.888451 -113.606616 -311.494782 -417.352947 -516.321113   
>  1.430722 
>          19          20          21          22          23   
>        24 
>  -18.407443 -328.425609 -476.743774    8.528060   67.849895 
> -298.548271 
>          25          26          27          28          29   
>        30 
> -478.826436  225.895398  110.617233 -226.800933 -487.939098  
> 281.782736 
>          31          32          33          34          35   
>        36 
>  -61.495429 -390.773595 -485.051760  431.670075  477.391909  
> -39.886256 
>          37          38          39          40          41   
>        42 
> -276.164422  732.557413  618.279247  -16.998918 -229.277084  
> 756.444751 
>  
> 
> 			
> ---------------------------------
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list