[R] Vector errors and missing values

jahughes81 jessica.hughes at acl.psych.toronto.edu
Fri Mar 2 15:49:47 CET 2012


Here is my code:


######Centering predictors#######
verbal.ability_C <- verbal.ability - mean(verbal.ability)
children_C <- children - mean(children)
age_C <- age - mean(age)
education_C <- education - mean(education)
work.from.home.frequency_C <- work.from.home.frequency -
mean(work.from.home.frequency)
religious.orientation_C <- religious.orientation -
mean(religious.orientation)
political.orientation_C <- political.orientation -
mean(political.orientation)
sexual.orientation_C <- sexual.orientation -mean(sexual.orientation)

########## Logistic Regression###########
logistic.model <- glm( fire.communist.teacher ~ age_C + sex + children_C +
currently.married + religious.orientation_C + political.orientation_C,
binomial(logit) )
summary( logistic.model )
exp( coefficients( logistic.model ) )

#######Probit/Binomial Regression#######

install.packages("MASS")
library(MASS)

probit.model <- polr( as.factor(verbal.ability) ~ education_C + children_C +
currently.married + work.from.home.frequency_C, method="probit") 
summary( probit.model)

Here is the output with I look at my data using the str(my.data) command:

'data.frame':	2044 obs. of  13 variables:
 $ sexual.orientation      : int  -1 -1 NA NA NA NA NA -1 NA NA ...
 $ political.orientation   : int  5 5 6 0 3 6 4 5 6 NA ...
 $ religious.orientation   : int  4 1 4 4 4 1 2 4 4 4 ...
 $ weekly.hours.on.internet: int  3 20 NA NA NA NA NA NA NA 0 ...
 $ verbal.ability          : int  6 9 NA 3 NA NA NA 8 NA NA ...
 $ work.from.home.frequency: int  3 4 NA NA NA NA 1 NA 1 1 ...
 $ fire.communist.teacher  : int  NA NA 1 NA 0 NA 0 0 0 1 ...
 $ currently.married       : int  -1 -1 -1 -1 1 -1 -1 -1 1 -1 ...
 $ children                : int  0 0 3 5 8 2 1 1 3 2 ...
 $ education               : int  16 16 8 10 0 6 16 15 14 14 ...
 $ partnrs5                : int  6 5 -1 99 -1 -1 -1 0 -1 -1 ...
 $ age                     : int  31 23 71 82 78 40 46 80 31 99 ...
 $ sex                     : int  1 -1 -1 -1 -1 1 -1 -1 -1 -1 ...

I tried using the na.action command by putting right after the 
'binomial(logit)' syntax, but it didn't work. I am not sure if I am using it
properly though.

So, I have tried this syntax to deal with the missing data:

logistic.model <- glm( fire.communist.teacher ~ age_C + sex + children_C +
currently.married + religious.orientation_C + political.orientation_C,
binomial(logit), na.action=na.exclude )

as well as:

logistic.model <- glm( fire.communist.teacher ~ age_C + sex + children_C +
currently.married + religious.orientation_C + political.orientation_C,
binomial(logit), na.action=na.exclude, data=na.omit(DataMiss) )



--
View this message in context: http://r.789695.n4.nabble.com/Vector-errors-and-missing-values-tp4437306p4438678.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list