[R] (-1 as index) OR (envelope for QQ)

Dan E. Kelley kelley at Phys.Ocean.Dal.CA
Thu Feb 24 20:43:11 CET 2000

I'm new to R (and to S) and am wondering about code from pages 72 and
83 of MASS (Venables+Ripley, 3rd edition), to draw an envelope on a QQ
plot.  Copying from the book, I've got:

  #... code whose gist is "a.fit <-  nls(..."
  num.points <- length(resid(a.fit))
  qqnorm(residuals(a.fit))     # illustrate data-model residuals
  samp <- cbind(residuals(a.fit), matrix(rnorm(num.points*19),num.points,19))
  samp <- apply(scale(samp), 2, sort)
  rs <- samp[,1] 
  xs <- qqnorm(rs, plot=FALSE)$x
  env <- t(apply(samp[,-1], 1, range))  ###########################3
  xyul <- par("usr")
  smidge <- min(diff(c(xyul[1], xs, xyul[2])))/2
  segments(xs-smidge,env[,1], xs+smidge, env[,1])
  segments(xs-smidge,env[,2], xs+smidge, env[,2])

where I've marked a confusing line with ########.  From what I gather
(from section 2.1, or page 5, of "R complements to MASS" by VR),
indexing is different in R than in S.  It's not clear to me whether
this R-to-S difference is giving me problems.  I'm such a newbie that
I'm not entirely sure what the 'samp[,-1]' is supposed to be doing.
(Confession: I'm such a newbie that I've spent much of the day typing
"?apply" and then "?par" etc, working through the program to try to
figure it out!)

In any case, my worry is visible in the QQ plot attached.  Why do I
have get so few "ledges" from the segments() calls?  It's not clear to
me how the scale of the data-model deviations come into this problem.

Q: should I first be standardizing the residuals from the data-model
comparison?  I would have guessed that something in this 'QQ envelope'
would be doing that.  

I'm guessing any replies will fit into one of three categories ...

1) You idiot!  QQ plots are supposed to have standardized residuals of
   the data-model misfit.  Do that and the QQ envelop is ok.

2) Don't copy S stuff into R code.  The S code "samp[,-1]" from VR
   should be written "..." for use in R.

3) Don't be so rude as to ask such questions (with length attachments,
   no less) on a group like this.  Give us a break!

... but I'm hoping that the mode won't be in the final category!

Many thanks in advance.

Dan E. Kelley                   internet:   mailto:Dan.Kelley at Dal.CA
Oceanography Department         phone:                 (902)494-1694
Dalhousie University            fax:                   (902)494-2885
Halifax, NS, CANADA, B3H 4J1    http://www.phys.ocean.dal.ca/~kelley
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Rplots.ps.gz
Type: application/octet-stream
Size: 2860 bytes
Url : https://stat.ethz.ch/pipermail/r-help/attachments/20000224/7d190b34/Rplots.ps.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fit.R.gz
Type: application/octet-stream
Size: 1657 bytes
Url : https://stat.ethz.ch/pipermail/r-help/attachments/20000224/7d190b34/fit.R.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fbox.dat.gz
Type: application/octet-stream
Size: 380 bytes
Url : https://stat.ethz.ch/pipermail/r-help/attachments/20000224/7d190b34/fbox.dat.obj

More information about the R-help mailing list