Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Z values- categorical covariates with multiple levels #20

Open
RohitThakur01 opened this issue Feb 21, 2018 · 1 comment
Open

Z values- categorical covariates with multiple levels #20

RohitThakur01 opened this issue Feb 21, 2018 · 1 comment

Comments

@RohitThakur01
Copy link

Hi,
Thanks for creating this package.
My question is about how to deal with the categorical covariates in Z.
Some of the covariates that I am dealing with have multiple levels. Should I dummy code this covariate? When I did this, I kept getting this error:

Error in solve.default(t(Z) %*% (Z * d)) :
system is computationally singular: reciprocal condition number = 3.99987e-19

Thanks in advance for the reply.

@pcarbo
Copy link
Owner

pcarbo commented Feb 22, 2018

@RohitThakur01 Here's an example of how to create binary covariates from a categorical variable (factor) with three categories (levels):

data(iris)
Z <- model.matrix(~Species - 1,iris)
Z <- Z[,1:2]

Note that if a factor has 3 levels, you only need 2 binary variables, not 3. If you get an error message about a singular matrix, it must be because the rank of cbind(1,Z) is less than 1 + the number of columns of Z. You can check this with qr(cbind(1,Z)). (Here, the 1 is the intercept, which is always included in varbvs.)

Does that help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants