I'm in the very initial stage of expanding the formula processing in my quantile regression function rq() to handle additive nonparametric components, say qss(x), or qss(x,z). I need some advice about strategy for formula processing. My initial foray was to use: terms(formula,specials="qss") and then modify the components of the resulting terms.object. But in changing formula at factors to drop the qss columns and rows, I ran afoul of methodsPackageMetaName which claimed that it was "being abused" by this. if(!is.null(attr(formula,"specials"))){ qss.col <- pmatch("qss",attr(formula,"term.labels")) qss.row <- formula at specials$qss formula at factors <- formula at factors[-qss.row,-qss.col,drop=FALSE] } My eventual objective is to be able to make the model.matrix corresponding to the linear, parametric part of the formula specified, and then to cbind additional columns corresponding to the nonparametric components and pass the whole thing to rq.fit.xxx, where estimation will be handled. So the essential question at this point is: how should I go about stripping off the qss components for subsequent use. url: www.econ.uiuc.edu Roger Koenker Dept. of Economics UCL, email rkoenker at uiuc.edu Department of Economics Drayton House, vox: 217-333-4558 University of Illinois 30 Gorden St, fax: 217-244-6678 Champaign, IL 61820 London,WC1H 0AX, UK vox: 020-7679-5838
On Mon, 10 Mar 2003, Roger Koenker wrote:> I'm in the very initial stage of expanding the formula processing > in my quantile regression function rq() to handle additive > nonparametric components, say qss(x), or qss(x,z). I need some > advice about strategy for formula processing. My initial foray > was to use: > > terms(formula,specials="qss") > > and then modify the components of the resulting > terms.object. But in changing formula at factors to drop the qss > columns and rows, I ran afoul of methodsPackageMetaName > which claimed that it was "being abused" by this.That means it is being called with incorrect arguments (and you are using without saying so R-devel aka `1.7.0 Under development (unstable)', for which the R-devel is a more appropriate list). I am really puzzled though: formula and terms are not S4 classes, so why are you using formula at specials and formula at factors? A terms object is documented in ?terms.object, and it does not have slots. @ is *not* the operator to access attributes, and I think this is quite correctly termed "being abused".> > if(!is.null(attr(formula,"specials"))){ > qss.col <- pmatch("qss",attr(formula,"term.labels")) > qss.row <- formula at specials$qss > formula at factors <- formula at factors[-qss.row,-qss.col,drop=FALSE] > } > > My eventual objective is to be able to make the model.matrix > corresponding to the linear, parametric part of the formula specified, > and then to cbind additional columns corresponding to the > nonparametric components and pass the whole thing to rq.fit.xxx, > where estimation will be handled. So the essential question at > this point is: how should I go about stripping off the qss > components for subsequent use.Access the attributes with the correct accessor functions and this should be possible. -- 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
On Mon, 10 Mar 2003, Roger Koenker wrote:> I'm in the very initial stage of expanding the formula processing > in my quantile regression function rq() to handle additive > nonparametric components, say qss(x), or qss(x,z). I need some > advice about strategy for formula processing. My initial foray > was to use: > > terms(formula,specials="qss") > > and then modify the components of the resulting > terms.object.Another approach, which you can see in coxph() in the survival package, is to create a new formula without the qss terms. It's not very pretty but it seems to work portably. -thomas
Hi. I am writing a program to read in different types of files from a GUI. While it's easy to read different types of text files, I am stymied how to make R execute the input. Ideally I could get the command from input and dereference it like `command`(filename) where command would be read.dta or read.table or read.xport or any of the similar commands. Also, is there a way to make associative arrays? It would be nice to be able to get the format from input and then have command<-array[format] Otherwise, I guess I'll just do cascading if's. Thanks, Janet Rosenbaum jerosenb at fas.harvard.edu Center for Basic Research in the Social Sciences, Harvard University
> Also, is there a way to make associative arrays? > It would be nice to be able to get the format from input and then have > command<-array[format]Named lists might do what you want. For example, fruitcolor <- list(apple="red", grape="green", orange="orange") Then you could say, fruitcolor$apple or fruitcolor[["apple"]] to get "red". + seth