Hi all, I am just learning R and I am trying to work through the book "Applied Longitudinal Data Analysis" by Singer & Willett. I have some code for this book that supposedly works in S-Plus (I don't have S-Plus so I can't verify that) and I am trying to run the examples in R. Most of the examples run, but I have one plot that gives me an error message. I have provided a small dataset below and the problematic code. I don't know if the problem is a dissimilarity between R and S-Plus, or if I have done something wrong because I don't know R well enough yet (I am also working through MASS by Venables & Ripley, and the Pinheiro & Bates book on Mixed-Effect Models). I looked at the warnings and also did traceback() which just took me to the function listed in the error message. I can't determine where the NA/NaN/Inf is (are) coming from. Any help would be appreciated. I am using Rwin 1.8.1 (pre-compiled) on Win2000 Professional. Thanks, Dan Nordlund ## toy problem library(nlme) tolerance.pp <- as.data.frame( matrix(c( 9,11,2.23, 9,12,1.79, 9,13,1.90, 9,14,2.12, 9,15,2.66, 45,11,1.12, 45,12,1.45, 45,13,1.45, 45,14,1.45, 45,15,1.99, 268,11,1.45, 268,12,1.34, 268,13,1.99, 268,14,1.79, 268,15,1.34, 314,11,1.22, 314,12,1.22, 314,13,1.55, 314,14,1.12, 314,15,1.12 ), byrow = T, ncol = 3 )) names(tolerance.pp) <- c('id','age','tolerance') ## this plots out fine xyplot(tolerance~age | factor(id), data=tolerance.pp) ## this produces an error message xyplot(tolerance~age | factor(id), data=tolerance.pp, prepanel = function(x, y) prepanel.loess(x, y), panel = function(x, y){ panel.xyplot(x, y) panel.loess(x, y) }, ylim=c(0, 4), as.table=T) Error message is:>Error in simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE,:> NA/NaN/Inf in foreign function call (arg 1) >In addition: There were 16 warnings (use warnings() to see them)[[alternative HTML version deleted]]
You are trying to fit a loess curve to just five points: that is not sensible (and interpolates in S-PLUS, so I don't think it `works' there either). Loess in R is not the same as loess in S-PLUS. (The latter is proprietary, and loess in R was implemented as a wrapper for the released C/Fortran code from the same group of authors.) You could have tried looking at the warnings, the first four of which are 1: pseudoinverse used at 13 2: neighborhood radius 1 3: reciprocal condition number 0 4: There are other near singularities as well. 1 and indicate that there were problems in doing the loess fit. What did you (or the authors) want here? It is hard to think of a useful visualization of the pattern of 5 points beyond linear interpolation. BTW, you want library(lattice) and not library(nlme). In 1.8.1 nlme attaches lattice, but in the next release it will not do so. On Thu, 25 Dec 2003 DJNordlund at aol.com wrote:> Hi all, > > I am just learning R and I am trying to work through the book "Applied > Longitudinal Data Analysis" by Singer & Willett. I have some code for this book > that supposedly works in S-Plus (I don't have S-Plus so I can't verify that) and > I am trying to run the examples in R. Most of the examples run, but I have > one plot that gives me an error message. I have provided a small dataset below > and the problematic code. > > I don't know if the problem is a dissimilarity between R and S-Plus, or if I > have done something wrong because I don't know R well enough yet (I am also > working through MASS by Venables & Ripley, and the Pinheiro & Bates book on > Mixed-Effect Models). > > I looked at the warnings and also did traceback() which just took me to the > function listed in the error message. I can't determine where the NA/NaN/Inf > is (are) coming from. > > Any help would be appreciated. I am using Rwin 1.8.1 (pre-compiled) on > Win2000 Professional. > > Thanks, > > Dan Nordlund > > ## toy problem > library(nlme) > > tolerance.pp <- as.data.frame( > matrix(c( > 9,11,2.23, > 9,12,1.79, > 9,13,1.90, > 9,14,2.12, > 9,15,2.66, > 45,11,1.12, > 45,12,1.45, > 45,13,1.45, > 45,14,1.45, > 45,15,1.99, > 268,11,1.45, > 268,12,1.34, > 268,13,1.99, > 268,14,1.79, > 268,15,1.34, > 314,11,1.22, > 314,12,1.22, > 314,13,1.55, > 314,14,1.12, > 314,15,1.12 > ), byrow = T, ncol = 3 )) > > names(tolerance.pp) <- c('id','age','tolerance') > > ## this plots out fine > xyplot(tolerance~age | factor(id), data=tolerance.pp) > > ## this produces an error message > xyplot(tolerance~age | factor(id), data=tolerance.pp, > prepanel = function(x, y) prepanel.loess(x, y), > panel = function(x, y){ > panel.xyplot(x, y) > panel.loess(x, y) > }, ylim=c(0, 4), as.table=T) > > > Error message is: > > >Error in simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE, > : > > NA/NaN/Inf in foreign function call (arg 1) > >In addition: There were 16 warnings (use warnings() to see them) > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
In a message dated 12/25/2003 3:00:34 PM Pacific Standard Time, ripley@stats.ox.ac.uk writes:>You are trying to fit a loess curve to just five points: that is not >sensible (and interpolates in S-PLUS, so I don't think it `works' there >either). >Thanks for the quick reply.>Loess in R is not the same as loess in S-PLUS. (The latter is >proprietary, and loess in R was implemented as a wrapper for the released >C/Fortran code from the same group of authors.) You could have tried >looking at the warnings, the first four of which are > >1: pseudoinverse used at 13 >2: neighborhood radius 1 >3: reciprocal condition number 0 >4: There are other near singularities as well. 1 > >and indicate that there were problems in doing the loess fit.I looked at the warnings and saw that there was a problem, but wasn't sure if that was due to a syntax error, or some other problem. I assumed that the code had been run successfully before (obviously an incorrect assumption in this case).> >What did you (or the authors) want here? It is hard to think of a useful >visualization of the pattern of 5 points beyond linear interpolation.In looking at the textbook, it looks like all the authors wanted was to see some general profile of responses over time. It probably would be just as useful (maybe more so) to just join the points with line segments.> > >BTW, you want library(lattice) and not library(nlme). In 1.8.1 >nlme attaches lattice, but in the next release it will not do so.I was aware that nlme attaches lattice, but it is good to know that I will have to do that explicitly in the near future.. Thanks again, Dan Nordlund [[alternative HTML version deleted]]
This is in regard to Dan Norlund's post from December 2003 (available at https://stat.ethz.ch/pipermail/r-help/attachments/20031225/1bce02b8/attachment.pl ) While I agree with Prof. Ripley's warning against fitting so few observations per panel, this is not actually what causes the error. Instead, the culprit is the fact that panel.loess uses family='symmetric' by default; since the first iteration of fitting interpolates the data, the residuals are zero, hence the robustness weights are not defined for the next iteration. In the example Dan gave, a change to xyplot(tolerance~age | factor(id), data=tolerance.pp, type=c("p","smooth"), family="gaussian") avoids this. As family='gaussian' is the default outside of panel.loess, it is easy to forget this detail. Ben