john.maindonald@anu.edu.au
2004-Jan-04 03:05 UTC
[Rd] termplot; failure to subset non-dataframe carriers (PR#6327)
termplot() does not carry subsetting over to carriers that are in the environment but not in the data frame. This generates a "subscript out of bounds" error. > data(ToothGrowth) > logdose <- log(ToothGrowth$dose) > tooth.lm <- lm(len ~ logdose, data=ToothGrowth) > termplot(tooth.lm) ## Works fine > toothVC2.lm <- lm(len ~ poly(dose,2), data=ToothGrowth, + subset=ToothGrowth$supp=="VC") > termplot(toothVC2.lm) ## Works fine > toothVC.lm <- lm(len ~ logdose, data=ToothGrowth, + subset=ToothGrowth$supp=="VC") > termplot(toothVC.lm) Error in xy.coords(x, y, xlabel, ylabel, log) : subscript out of bounds > traceback() 4: xy.coords(x, y, xlabel, ylabel, log) 3: plot.default(xx[oo], tms[oo, i], type = "l", xlab = xlabs[i], ylab = ylabs[i], xlim = xlims, ylim = ylims, main = main[i], col = col.term, lwd = lwd.term, ...) 2: plot(xx[oo], tms[oo, i], type = "l", xlab = xlabs[i], ylab = ylabs[i], xlim = xlims, ylim = ylims, main = main[i], col = col.term, lwd = lwd.term, ...) 1: termplot(toothVC.lm) Because logdose is not in the data frame ToothGrowth, it was not subsetted. Pending better suggestions, I offer the following fix: Replace the lines: if (NROW(tms) < NROW(data)) data <- data[dimnames(tms)[[1]], ] by if (NROW(tms) < NROW(data)) { use.rows <- match(dimnames(tms)[[1]], dimnames(data)[[1]]) data <- data[use.rows, ] } else use.rows <- NULL Then following xx <- carrier(cn[[i]]) add: if(!is.null(use.rows))xx <- xx[use.rows] Alternatively, the (conditional) subsetting may be included within the function carrier() ------------------------------------------------------------------------ ------------- This may be a good time to mention that I'd like to be able to add a smooth to the points that appear when partial.resid=TRUE. One mechanism would be to allow as argument a panel function that can be set to panel.smooth. (The default might be NULL). I'll forward a more detailed suggestion to r-devel. --please do not edit the information below-- Version: platform = powerpc-apple-darwin6.8 arch = powerpc os = darwin6.8 system = powerpc, darwin6.8 status major = 1 minor = 8.1 year = 2003 month = 11 day = 21 language = R Search Path: .GlobalEnv, package:methods, package:ctest, package:mva, package:modreg, package:nls, package:ts, Autoloads, package:base John Maindonald email: john.maindonald@anu.edu.au phone : +61 2 (6125)3473 fax : +61 2(6125)5549 Centre for Bioinformation Science, Room 1194, John Dedman Mathematical Sciences Building (Building 27) Australian National University, Canberra ACT 0200.