I am getting an error that I don't understand, and wonder if anyone could explain what's going on. I call a function defined thus: clogit.rds<-function(formula,data,extra.data,response.prob, na.action=getOption("na.action"),subset=NULL, control=coxph.control()){ method="exact" # only option for now mf<-match.call() mf[[1]]<-as.name("model.frame") mf$method<-mf$control<-NULL mfn<-mf mfn$na.action<-"I" mfn$subset<-NULL nrows<-NROW(eval(mfn,parent.frame())) etc. At the eval on the last line, I get Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : variable lengths differ This is puzzling for two reasons. First, I don't understand where the arguments given in the error message are coming from. They are not in my function definition or call, and they do not seem to be the arguments to model.frame either. Second, I don't know why it's not working! This is modified from clogit in survival, and that works fine. I've added two arguments, extra.data (which is just a column of the data) and response.prob. The latter has different dimensions (response.prob = c(1, 1), in fact), but nothing in the description of model.frame suggests that should be a problem. model.frame itself is a wrapper on a primitive, so I can't really debug into it. Background: Running R 1.7.1-1 on Debian Gnu/Linux. In case it matters, the code I'm running was produced by hacking the survival package, running R CMD check, and then loading the package from the test directory that created: library("survival", lib.loc="/home/ross/src/survival.Rcheck") The clogit command seems to run fine. One of the variables in the data.frame is name proband, which I notice gets highlighted by ESS.
On Fri, 2003-08-15 at 16:03, Ross Boylan wrote:> I am getting an error that I don't understand, and wonder if anyone > could explain what's going on. I call a function defined thus: > > clogit.rds<-function(formula,data,extra.data,response.prob, > na.action=getOption("na.action"),subset=NULL, > control=coxph.control()){ > method="exact" # only option for now > mf<-match.call() > mf[[1]]<-as.name("model.frame") > mf$method<-mf$control<-NULL > mfn<-mf > > mfn$na.action<-"I" > mfn$subset<-NULL > nrows<-NROW(eval(mfn,parent.frame())) > etc. > At the eval on the last line, I get > > Error in model.frame(formula, rownames, variables, varnames, extras, > extranames, : > variable lengths differ >A clue: if I call this with response.prob set to an element of the clogit.rds argument data frame, I don't get the error. I assume that to fix this I must somehow exclude this variable. But I will need it back in when I make the next call. Suggestions? Insights into why this is necessary?
On Fri, 15 Aug 2003, Ross Boylan wrote:> I am getting an error that I don't understand, and wonder if anyone > could explain what's going on. I call a function defined thus: > > clogit.rds<-function(formula,data,extra.data,response.prob, > na.action=getOption("na.action"),subset=NULL, > control=coxph.control()){ > method="exact" # only option for now > mf<-match.call() > mf[[1]]<-as.name("model.frame") > mf$method<-mf$control<-NULL > mfn<-mf > > mfn$na.action<-"I" > mfn$subset<-NULL > nrows<-NROW(eval(mfn,parent.frame())) > etc. > At the eval on the last line, I get > > Error in model.frame(formula, rownames, variables, varnames, extras, > extranames, : > variable lengths differ > > This is puzzling for two reasons. First, I don't understand where the > arguments given in the error message are coming from. They are not in > my function definition or call, and they do not seem to be the arguments > to model.frame either.They are the arguments to .Internal(model.frame( )) inside model.frame.default. The traceback() function will list the call stack after an error to avoid confusions like this.> Second, I don't know why it's not working! This is modified from clogit > in survival, and that works fine. I've added two arguments, extra.data > (which is just a column of the data) and response.prob. The latter has > different dimensions (response.prob = c(1, 1), in fact), but nothing in > the description of model.frame suggests that should be a problem.Well, it is a problem. model.frame() requires all the variables to be the same length, as you can readily see for yourself R> x<-1:10 R> y<-1 R> model.frame(y~x) Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : variable lengths differ That's why the error message is "variable lengths differ" :) The way to stop this is to remove response.prob from the call to model.frame, ie, do mf$response.prob<-NULL as is already done for mf$method and mf$control.> model.frame itself is a wrapper on a primitive, so I can't really debug > into it. >An Internal, not a primitive (although that doesn't simplify your life any). Quite a lot of it is interpreted code, though the bit that checks variable lengths isn't. -thomas