[R] error when using ps() function on categorical variables - re propensity score matching

Andrew Kemp andrewhaddonkemp at gmail.com
Wed Sep 25 16:29:35 CEST 2013


Dear List,

I am having difficulty running the ps() function when variables are stored
as factors and was hoping someone could provide some advice on how to
proceed.

I am running propensity score matching as outlined in:

	Greg Ridgeway, Dan McCarey, Andrew Morral, Lane Burgette and Beth Ann
Grin (May 3, 2013) Toolkit for Weighting and Analysis of Nonequivalent
Groups: A tutorial for the twang package

and have a question about using unordered categorical variables as a
covariates. The tutorial indicates that:

 "There is no need to Š create indicator, or dummy coded, variables to
represent categorical covariates, provided the categorical variables are
stored as a factor  or as orderedŠ "

However, when I run the ps() function after converting categorical
variables to factors using the factor() function, I return the following
warning:

 "Warning in model.matrix(glm.object) * resid(glm.object, "working") :
longer object length is not a multiple of shorter object length"

and followed by an error:

 "Error in x$fpc$sampsize[i, , drop = FALSE] :  (subscript) logical
subscript too long"

Interestingly, the code runs without warning or error when variables are
not converted to factors.

Thanks in advance!


ANDREW H. KEMP, PhD
Invited International Visiting Professor, University of São Paulo
Associate Professor, University of Sydney



More information about the R-help mailing list