[R] ordglm -- simple question

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Tue Jun 7 16:49:22 CEST 2005


On Tue, 7 Jun 2005 09:48:13 -0400 (EDT) Anders Schwartz Corr wrote:

> My attempt to test a model using ordglm code is running into problems,
> and I thought if you have a moment you might illucidate the situation.

Please indicate which package you are using, I guess you are referring
to ordglm() in Jim Lindsey's gnlm package.
 
> Here is the data:
> 
> http://www.people.fas.harvard.edu/~corr/6.4.05.RData

You are kidding, right? A 4.9M file with some 30 objects for an example
like the one below?? *Please* do read the posting guide.

> Here is the code:
> 
> # I coerce tcn8 matrix data to a vector, because ordglm will not
> # accept
> matrix data.
> y<-as.vector(tcn8[,62])
> x<-as.vector(tcn8[,60])
> wt<-as.vector(tcn8[,61])
> cbind(y,x,wt)->tc
> colnames(tc) <- c("y","x","wt")
> ordglm(y ~ x, weights=wt, data=tc, link = "logit")
> 
> Here is the output:
> 
> > y<-as.vector(tcn8[,62])
> > x<-as.vector(tcn8[,60])
> > wt<-as.vector(tcn8[,61])
> > cbind(y,x,wt)->tc
> > colnames(tc) <- c("y","x","wt")
> > ordglm(y ~ x, weights=wt, data=tc, link = "logit")
> Error in model.frame.default(mt, data, na.action = na.fail) :
>         `data' must be a data.frame, not a matrix or  array
> 
> Perhaps it is a problem of having NAs and NaNs in my data? I
> appreciate any pointers. Do I need to set model.frame first?

I think the error message is very explicit: `data' (in your case the
object `tc') needs to be a "data.frame", but it is a "matrix". So you
did a good job in replacing the matrix `tcn8' with the matrix `tc'.

You can coerce it relatively easy to a "data.frame" using
as.data.frame(). Then ordglm() will complain about NAs, which you could
for example na.omit(). But then ordglm() says that `y' has to be numeric
which made me realize that your variables `y', `x' and `wt' are in fact
"character"s.

In summary this means:
  1. Hold your variables in an appropriate format, e.g., numeric 
     vectors in a "data.frame". Maybe some basic R manuals like "An
     Introduction to R" can help here.
  2. Read the man page of ordglm() and also read the error messages,
     they are very informative.
  3. Read the posting guide before posting to the lists.

hth,
Z




More information about the R-help mailing list