[R] problem with lm, and summary.lm

Tolga Uzuner tolga.uzuner at gmail.com
Sun Nov 16 13:32:59 CET 2008


Dear R Users,

I am having a weird problem. I have three zoo time series, foo, bar and 
baz. I run a simple linear regression with foo as the dependent and 
bar+baz as independents. Even though the regression runs fine, summary 
seems to fail.The code is below. I am happy to send the data along. I am 
on R 2.8.0 and Windows XP SP2. Traceback (below, a ton of numbers cut 
out to make it readable but I can provide the data). reveals the problem 
is in a function called gt. sessioninfo is at the bottom.

Any suggestions ? I upgraded to 2.8.0 this morning after replaced 2.7.1 
and I almost feel the new version is at fault but I could be inferring 
too much...

Thanks in advance,
Tolga

cooks.distance also reveals the same problem.

 > length(foo)
[1] 258
 > length(foo)
[1] 258
 > length(bar)
[1] 258
 > length(baz)
[1] 258
 > regrlm<-lm(foo~bar+baz)
 > regrlm

Call:
lm(formula = foo ~ bar + baz)

Coefficients:
(Intercept)          bar          baz 
    1082.39        12.72    -20176.67 

 > summary(regrlm)

Call:
lm(formula = foo ~ bar + baz)

Residuals:
Error in if (xi == xj) 0L else if (xi > xj) 1L else -1L :
  argument is of length zero
 > traceback()
19: .gt(c(145.181456007549, 118.279525850693, 111.250750147955, 
89.1393551953539,
MANY MANY NUMBERS
    -67.9948569260507, -146.080176235300), 250L, 246L)
18: switch(ties.method, average = , min = , max = .Internal(rank(x[!nas],
        ties.method)), first = sort.list(sort.list(x[!nas])), random = 
sort.list(order(x[!nas],
        stats::runif(sum(!nas)))))
17: rank(x, ties.method = "min", na.last = "keep")
16: as.vector(rank(x, ties.method = "min", na.last = "keep"))
15: xtfrm.default(x)
14: xtfrm(x)
13: FUN(X[[1L]], ...)
12: lapply(z, function(x) if (is.object(x)) xtfrm(x) else x)
11: order(x, na.last = na.last, decreasing = decreasing)
10: `[.zoo`(x, order(x, na.last = na.last, decreasing = decreasing))
9: x[order(x, na.last = na.last, decreasing = decreasing)]
8: sort.default(x, partial = unique(c(lo, hi)))
7: sort(x, partial = unique(c(lo, hi)))
6: quantile.default(resid)
5: quantile(resid)
4: structure(quantile(resid), names = nam)
3: print.summary.lm(list(call = lm(formula = foo ~ bar + baz), terms = 
foo ~
       bar + baz, residuals = c(145.181456007549, 118.279525850693,
MANY MANY NUMBERS   -97.6817272270226, -101.621851940748, 
-67.9948569260507, -146.080176235300
   ), coefficients = c(1082.39330190496, 12.7191319384837, 
-20176.6660075191,
   36.7646530199551, 0.752346859475059, 1097.00127070372, 29.4411401439708,
   16.9059414262171, -18.3925639343844, 5.30095123419022e-84, 
1.60626441787295e-43,
   1.15247513614373e-48), aliased = c(FALSE, FALSE, FALSE), sigma = 
90.0587318356495,
       df = c(3L, 255L, 3L), r.squared = 0.767559392535633, 
adj.r.squared = 0.765736328947677,
       fstatistic = c(421.027219021081, 2, 255), cov.unscaled = 
c(0.166651523684348,
       -0.00308410770161002, -3.08083131687658, -0.00308410770161002,
       6.9788613558326e-05, 0.0263943284503598, -3.08083131687658,
       0.0263943284503598, 148.375640597725)))
2: print(list(call = lm(formula = foo ~ bar + baz), terms = foo ~
       bar + baz, residuals = c(145.181456007549, 118.279525850693,
MANY MANY NUMBERS
   -97.6817272270226, -101.621851940748, -67.9948569260507, 
-146.080176235300
   ), coefficients = c(1082.39330190496, 12.7191319384837, 
-20176.6660075191,
   36.7646530199551, 0.752346859475059, 1097.00127070372, 29.4411401439708,
   16.9059414262171, -18.3925639343844, 5.30095123419022e-84, 
1.60626441787295e-43,
   1.15247513614373e-48), aliased = c(FALSE, FALSE, FALSE), sigma = 
90.0587318356495,
       df = c(3L, 255L, 3L), r.squared = 0.767559392535633, 
adj.r.squared = 0.765736328947677,
       fstatistic = c(421.027219021081, 2, 255), cov.unscaled = 
c(0.166651523684348,
       -0.00308410770161002, -3.08083131687658, -0.00308410770161002,
       6.9788613558326e-05, 0.0263943284503598, -3.08083131687658,
       0.0263943284503598, 148.375640597725)))
1: print(list(call = lm(formula = foo ~ bar + baz), terms = foo ~
       bar + baz, residuals = c(145.181456007549, 118.279525850693,
MANY MANY NUMBERS   -97.6817272270226, -101.621851940748, 
-67.9948569260507, -146.080176235300
   ), coefficients = c(1082.39330190496, 12.7191319384837, 
-20176.6660075191,
   36.7646530199551, 0.752346859475059, 1097.00127070372, 29.4411401439708,
   16.9059414262171, -18.3925639343844, 5.30095123419022e-84, 
1.60626441787295e-43,
   1.15247513614373e-48), aliased = c(FALSE, FALSE, FALSE), sigma = 
90.0587318356495,
       df = c(3L, 255L, 3L), r.squared = 0.767559392535633, 
adj.r.squared = 0.765736328947677,
       fstatistic = c(421.027219021081, 2, 255), cov.unscaled = 
c(0.166651523684348,
       -0.00308410770161002, -3.08083131687658, -0.00308410770161002,
       6.9788613558326e-05, 0.0263943284503598, -3.08083131687658,
       0.0263943284503598, 148.375640597725)))
 > sessionInfo()
R version 2.8.0 (2008-10-20)
i386-pc-mingw32

locale:
LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United 
Kingdom.1252;LC_MONETARY=English_United 
Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
 [1] lpSolve_5.6.4                leaps_2.7                  
 [3] nortest_1.0                  numDeriv_2006.4-1          
 [5] bcp_2.1                      snow_0.3-3                 
 [7] fArma_270.74                 fBasics_280.74             
 [9] timeSeries_280.78            timeDate_280.80            
[11] PerformanceAnalytics_0.9.7.1 tseries_0.10-16            
[13] quadprog_1.4-11              vars_1.4-0                 
[15] urca_1.1-7                   MASS_7.2-44                
[17] MSBVAR_0.3.2                 coda_0.13-3                
[19] lattice_0.17-15              xtable_1.5-4               
[21] KernSmooth_2.22-22           RODBC_1.2-3                
[23] corrgram_0.1                 nlme_3.1-89                
[25] lmtest_0.9-21                car_1.2-9                  
[27] strucchange_1.3-4            sandwich_2.1-0             
[29] zoo_1.5-4                  

loaded via a namespace (and not attached):
[1] grid_2.8.0  tools_2.8.0
 >



More information about the R-help mailing list