You *do* need to do na.omit() for ordinal logit.
----- Original Message -----
From: "Kosuke Imai" <kimai(a)Princeton.Edu>
To: "Olivia Lau" <olau(a)fas.harvard.edu>
Cc: <chakabry(a)ufl.edu>du>; <zelig(a)latte.harvard.edu>
Sent: Tuesday, November 30, 2004 8:49 AM
Subject: Re: [zelig] Zelig Help: invalid subscript error when
invoking "ologit"
Bryan,
To add one more note to Olivia's advice, you can check the
order of a
factor variable in the following manner.
levels(ethdata$meadd)
You can do this after making ethdata$meadd into a factor
variable by
as.factor() command. You should also check to see if it's
already a factor
varaible by is.factor().
Finally, zelig() will do the listwise deletion by default and
so you don't
need to do na.omit() on your own.
Kosuke
---------------------------------------------------------
Kosuke Imai Office: Corwin Hall 041
Assistant Professor Phone: 609-258-6601
Department of Politics eFax: 973-556-1929
Princeton University Email: kimai(a)Princeton.Edu
Princeton, NJ 08544-1012
http://www.princeton.edu/~kimai
---------------------------------------------------------
On Tue, 30 Nov 2004, Olivia Lau wrote:
Dear Bryan,
There are a few problems below:
1) You extract and recode each variable independently. You
need to
recode them in the context of the data frame to preserve the
indexing of
each variable against every other variable. When you use
as.ordered(),
you need to check to make sure that R is putting the factors
in the
order that you want them to be in. And I think you want
as.factor() --
which creates unordered factors -- rather than as.ordered().
R treats
an ordered factor as a helmert contrast matrix, and I think
you just
want matricies of indicator variables for each of the
factors.
2) The statement to run zelig is a bit confusing. Every
argument
except for the first requires a label, and you are specifying
some
arguments which are not necessary at all. Try instead:
ethdata <- na.omit(ethdata)
z.out <- zelig(meadd ~ q11 + q255 + ecinteg + q89 + q87 + q4
+ ethnicp + q66 + q94 + neighb, model = "ologit",
data=ethdata)
3) I never attach() my data. R will get confused between
variables in the attached data frame and variables in the
workspace of the same name.
Hope this helps!
Olivia Lau
----- Original Message -----
From: Bryan Williams
To: zelig(a)latte.harvard.edu
Sent: Tuesday, November 30, 2004 7:16 AM
Subject: [zelig] Zelig Help: invalid subscript error when
invoking "ologit"
I'm trying to do an ordered logistic regression and then
generate first differences, however I've run up against an
"invalid subscript error" that I can't figure out. I would
sincerely appreciate any help you could give me on this.
My data looks like this:
q4 q11 q255 q66 q87 q89 q94 ethnicp ecinteg
neighb
1 3 1 2 0 53 4 2 -1.11010 8
2
2 2 1 3 0 58 4 2 0.42035 8
2
3 3 1 3 0 56 4 2 -0.56365 8
2
4 2 1 3 0 75 3 2 -1.13594 6
2
5 4 1 2 0 51 4 2 -2.28052 7
2
6 3 1 3 0 33 4 2 1.13252 7
2
7 2 1 2 0 <NA> 4 2 1.13252 8
1
8 1 0 0 0 <NA> 4 2 0.14851 5
2
(the left-most numbers are the automatically assigned row
numbers)
And my commands look like (please remember that I'm new to
R so my procedure may look a bit sloppy):
#Load the sample data:
ethdata.r<-read.spss("C:/Documents and Settings/Bryan
Williams/My Documents/ethnicity paper/ethdata.r.sav",
to.data.frame=T)
attach(ethdata.r)
# OR IF LOADED ALREADY: >data(ethdata.r)
#Create ordered dependent & independent variables:
meadd<- as.ordered (MEADD)
ecinteg <- as.ordered(ECINTEG)
ethnicp <- as.numeric(ETHNICP)
q4 <- as.ordered(Q4)
q11 <- as.ordered(Q11)
q66 <- as.ordered(Q66)
q89 <- as.ordered(Q89)
q87 <- as.ordered(Q87)
q94 <- as.ordered(Q94)
q255 <- as.ordered(Q255)
neighb <- as.ordered(NEIGHB)
rm(ethdata.r)
ethdata<-data.frame(q4,q11,q255,q66,q87,q89,q94,ethnicp,ecinteg,neighb)
attach(ethdata)
#Estimate the model*******THIS IS THE PROBLEMATIC LINE-I've
used "options(error=recover) to step through the equation,
but don't understand what goes wrong: "[.data.frame",,by :
invalid subscript type
**********************************************************************
z.out <- zelig(meadd ~ q11 + q255 + ecinteg + q89 + q87 +
q4 + ethnicp + q66 + q94 + neighb , weight=WT, start=0,
na.exclude(ethdata), model = "ologit", data=ethdata)
#it never gets to the following line
summary(z.out)
Thank you for your consideration,
Bryan Williams
Doctoral Candidate
Department of Political Science
University of Florida
chakabry(a)ufl.edu
(352)392-0262 x290
- Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)latte.harvard.edu [un]subscribe Options:
http://lists.hmdc.harvard.edu/?info=zelig Zelig program
information:
http://gking.harvard.edu/zelig/
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)latte.harvard.edu
[un]subscribe Options:
http://lists.hmdc.harvard.edu/?info=zelig
Zelig program information:
http://gking.harvard.edu/zelig/
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)latte.harvard.edu
[un]subscribe Options: