stat_smooth function stopped working?

2,709 views
Skip to first unread message

Kevin

unread,
Jan 16, 2013, 10:48:58 PM1/16/13
to ggp...@googlegroups.com
This has always worked for me and I have various revisions of this same script saved but I now get this error:

geom_smooth: method="auto" and size of largest group is >=1000, so using gam with formula: y ~ s(x, bs = "cs"). Use 'method = x' to change the smoothing method.
geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.
Error in predLoess(object$y, object$x, newx, object$s, object$weights,  : 
  NA/NaN/Inf in foreign function call (arg 5)
In addition: There were 50 or more warnings (use warnings() to see the first 50)
Error in if (nrow(layer_data) == 0) return() : argument is of length zero

I tried uninstalling and reinstalling ggplot2

Code:
bpssc <- read.csv ("bp-join.csv", header = TRUE, sep = ",", quote="\"", dec=".",fill = FALSE,colClasses=c("Date"="Date")) 

ggplot<- ggplot(data=bpssc, aes(x=Date,y=BR.Score, group = Unit)) 

ggplot + geom_point(aes(color = BR.Region), size=3.5,alpha = I(.5)) + scale_colour_brewer(type="qual", palette="Dark2") 

last_plot() + stat_smooth(aes(group = 1),fill = "darkgray", se=TRUE,col="black", size = .9, level =.95,fullrange = FALSE,lty=2) #group 1 GAM all data

last_plot() + stat_smooth(aes(color = BR.Region),fill = "darkgray", se=F, size = 1.9, level =.95,fullrange = TRUE)#trends of individual regions

This last line of code is what breaks the plot and generates all the errors.

Here is the output from warnings()
warnings()
Warning messages:
1: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  span too small.   fewer data values than degrees of freedom.
2: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  pseudoinverse used at 15069
3: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  neighborhood radius 255.59
4: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  reciprocal condition number  0
5: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  There are other near singularities as well. 71604
6: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  span too small.   fewer data values than degrees of freedom.
7: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  pseudoinverse used at 15027
8: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  neighborhood radius 399.98
9: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  reciprocal condition number  0
10: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  There are other near singularities as well. 91794
11: In sqrt(sum.squares/one.delta) : NaNs produced
12: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  span too small.   fewer data values than degrees of freedom.
13: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  pseudoinverse used at 15083
14: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  neighborhood radius 336.91
15: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  reciprocal condition number  0
16: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  There are other near singularities as well. 1.4738e+05
17: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  span too small.   fewer data values than degrees of freedom.
18: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  pseudoinverse used at 15175
19: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  neighborhood radius 280.34
20: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  reciprocal condition number  0
21: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  There are other near singularities as well. 1.0979e+05
22: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  span too small.   fewer data values than degrees of freedom.
23: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  pseudoinverse used at 15180
24: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  neighborhood radius 301.51
25: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  reciprocal condition number  0
26: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  There are other near singularities as well. 1.3802e+05
27: In sqrt(sum.squares/one.delta) : NaNs produced
28: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  span too small.   fewer data values than degrees of freedom.
29: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  pseudoinverse used at 15236
30: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  neighborhood radius 283.97
31: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  reciprocal condition number  0
32: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  There are other near singularities as well. 93618
33: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  span too small.   fewer data values than degrees of freedom.
34: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  pseudoinverse used at 15081
35: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  neighborhood radius 366.87
36: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  reciprocal condition number  0
37: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  There are other near singularities as well. 1.2381e+05
38: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  span too small.   fewer data values than degrees of freedom.
39: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  pseudoinverse used at 15067
40: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  neighborhood radius 451.9
41: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  reciprocal condition number  0
42: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  There are other near singularities as well. 1.3315e+05
43: In sqrt(sum.squares/one.delta) : NaNs produced
44: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  span too small.   fewer data values than degrees of freedom.
45: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  pseudoinverse used at 15181
46: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  neighborhood radius 262.48
47: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  reciprocal condition number  0
48: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  There are other near singularities as well. 1.6523e+05
49: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  span too small.   fewer data values than degrees of freedom.
50: In simpleLoess(y, x, w, span, degree, parametric, drop.square,  ... :
  pseudoinverse used at 15285




Any help is appreciated!!

Dennis Murphy

unread,
Jan 17, 2013, 2:06:02 AM1/17/13
to Kevin, ggp...@googlegroups.com
Hi:

On Wed, Jan 16, 2013 at 7:48 PM, Kevin <skycon...@gmail.com> wrote:
> This has always worked for me and I have various revisions of this same
> script saved but I now get this error:
>

These are messages informing you that ggplot2 is using gam() to create
the smoothing rather than loess.
> geom_smooth: method="auto" and size of largest group is >=1000, so using gam
> with formula: y ~ s(x, bs = "cs"). Use 'method = x' to change the smoothing
> method.
> geom_smooth: method="auto" and size of largest group is <1000, so using
> loess. Use 'method = x' to change the smoothing method.

This is definitely an error, but it's informative:

> Error in predLoess(object$y, object$x, newx, object$s, object$weights, :
> NA/NaN/Inf in foreign function call (arg 5)

arg 5 is weights, and it's telling you that at least one of the
weights either blew up (Inf), generated an NaN or a missing value (not
uncommon along the extremes if the data in those regions is too
sparse).

> In addition: There were 50 or more warnings (use warnings() to see the first
> 50)
> Error in if (nrow(layer_data) == 0) return() : argument is of length zero

This warning appears to be indicating that at least one of your groups
has no data, but a traceback of the call may be more informative.
>
> I tried uninstalling and reinstalling ggplot2
>
> Code:
> bpssc <- read.csv ("bp-join.csv", header = TRUE, sep = ",", quote="\"",
> dec=".",fill = FALSE,colClasses=c("Date"="Date"))
>
> ggplot<- ggplot(data=bpssc, aes(x=Date,y=BR.Score, group = Unit))
>
> ggplot + geom_point(aes(color = BR.Region), size=3.5,alpha = I(.5)) +
> scale_colour_brewer(type="qual", palette="Dark2")
>
> last_plot() + stat_smooth(aes(group = 1),fill = "darkgray",
> se=TRUE,col="black", size = .9, level =.95,fullrange = FALSE,lty=2) #group 1
> GAM all data
>
> last_plot() + stat_smooth(aes(color = BR.Region),fill = "darkgray", se=F,
> size = 1.9, level =.95,fullrange = TRUE)#trends of individual regions

One guess is that because of the fullrange argument, at least one of
your groups had little or no data in the extremes of the x-range,
which causes the loess/gam algorithm to become sufficiently unstable
to generate NA/NaN/Inf weights. Remember that warning in intro stats
about extrapolating beyond the range of your data? When dealing with
adaptive estimation algorithms, this warning is especially true.

Dennis
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Kevin

unread,
Jan 17, 2013, 11:14:02 AM1/17/13
to ggp...@googlegroups.com, Kevin
Thank you for your thoughtful reply Dennis,
What's interesting about this situation is I'm using the same data set that for weeks has given 3 nice gam lines each colored by region. The Score range is from 0 to 100 but the majority of the scores are over 60 and there are three distinct regions. The score, date, and region columns do not have any NAs, negative values, or something egregiously wrong.

What did you mean by a traceback? I'm not sure how to evaluate the problem further.

Thanks again Dennis! 
Reply all
Reply to author
Forward
0 new messages