Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [categorical-encoding]

Representing categorical variables as sets of numerical variables. Necessary in many types of analysis for them to process categorical data. A common example is using a categorical predictor in regression/ANOVA via dummy coding, effect coding, Helmert coding, user-defined contrasts, etc.

11
votes
2answers
15k views

Regression based for example on days of week

I need a little help to move in the right direction. It's a long time since I studied any stats and the jargon seems to have changed. Imagine that I have a set of car-related data such as Journey ...
18
votes
2answers
40k views

Significance of categorical predictor in logistic regression

I am having trouble interpreting the z values for categorical variables in logistic regression. In the example below I have a categorical variable with 3 classes and according to the z value, CLASS2 ...
10
votes
2answers
48k views

Understanding dummy (manual or automated) variable creation in GLM

If a factor variable (e.g. gender with levels M and F) is used in the glm formula, dummy variable(s) are created, and can be found in the glm model summary along with their associated coefficients (e....
14
votes
2answers
19k views

Qualitative variable coding in regression leads to “singularities”

I have an independent variable called "quality"; this variable has 3 modalities of response (bad quality; medium quality; high quality). I want to introduce this independent variable into my multiple ...
11
votes
1answer
6k views

Dropping one of the columns when using one-hot encoding

My understanding is that in machine learning it can be a problem if your dataset has highly correlated features, as they effectively encode the same information. Recently someone pointed out that ...
45
votes
4answers
11k views

What is a contrast matrix?

What exactly is contrast matrix (a term, pertaining to an analysis with categorical predictors) and how exactly is contrast matrix specified? I.e. what are columns, what are rows, what are the ...
25
votes
7answers
35k views

Why is gender typically coded 0/1 rather than 1/2, for example?

I understand the logic of coding for data analysis. My question below is on the use of a specific code. Is there a reason why gender is often coded as 0 for female and 1 for male? Why is this coding ...
16
votes
3answers
24k views

Why do we need to dummy code categorical variables

I am not sure why we need to dummy code categorical variables. For instance, if I have a categorical variable with four possible values 0,1,2,3 I can replace it by two dimensions. If the variable had ...
14
votes
2answers
16k views

How to do regression with effect coding instead of dummy coding in R?

I am currently working on a regression model where I have only categorical/factor variables as independent variables. My dependent variable is a logit transformed ratio. It is fairly easy just to run ...
14
votes
1answer
904 views

What are the different types of codings available for categorical variables (in R) and when would you use them?

If you fit a linear model or a mixed model there are different types of codings available to transform a categorical or nominal varibale into a number of variables for which paramaters are estimated, ...
10
votes
3answers
102k views

How to deal with non-binary categorical variables in logistic regression (SPSS)

I have to do binary logistic regression with a lot of independent variables. Most of them are binary, but a few of the categorical variables have more than two levels. What is the best way to deal ...
8
votes
4answers
2k views

How to statistically prove if a column has categorical data or not using Python

I have a data frame in python where I need to find all categorical variables. Checking the type of the column doesn't always work because int type can also be ...
1
vote
1answer
2k views

Coding of categorical variables in logistic regression

I have to do a binary logistic regression. I have a set of 7 independent variables. 4 of them are binary variables and the other 3 are categorical variables. The categorical variables are divided into ...
14
votes
2answers
6k views

“Dummy variable” versus “indicator variable” for nominal/categorical data

"Dummy variable" and "indicator variable" are labels frequently used terms to describe membership in a category with 0/1 coding; usually 0: Not a member of category, 1: Member of category. On 11/26/...
2
votes
2answers
2k views

Categorical variable coding to compare all levels to all levels

I am trying to determine the best coding system for my categorical variables to use in a regression with categorical and continuous variables. I have been using this page as a resource but none of the ...
4
votes
1answer
299 views

What is the appropriate zero-correlation parameter model for factors in lmer?

When one wants to specify a lmer model including variance components but no correlation parameters, as opposed to m1, for a ...
3
votes
1answer
49 views

Fitted values of a simple regression with intercept and dummy

Why are the fitted values of a simple regression with intercept and dummy, estimated by OLS, just the group means belonging to the two groups of observations? I.e., why do we have that the fitted ...
1
vote
1answer
1k views

Simple effects of categorical interaction

I have two two-level categorical variables, IV1 and IV2. I want to fit a linear model in R and find out the simple effect of IV1 on the DV at each level of IV2, separately. I'm not interested in the ...
17
votes
4answers
21k views

How to recode categorical variable into numerical variable when using SVM or Neural Network

To use SVM or Neural Network it needs to transform (encode) categorical variables into numeric variables, the normal method in this case is to use 0-1 binary values with the k-th categorical value ...
19
votes
3answers
25k views

When should one use multiple regression with dummy coding vs. ANCOVA?

I recently analyzed an experiment that manipulated 2 categorical variables and one continuous variable using ANCOVA. However, a reviewer suggested that multiple regression with the categorical ...
9
votes
1answer
7k views

R linear regression categorical variable “hidden” value

This is just an example that I have come across several times, so I don't have any sample data. Running a linear regression model in R: a.lm = lm(Y ~ x1 + x2) <...
8
votes
2answers
538 views

Why does treatment coding result in a correlation between random slope and intercept?

Consider a within-subject and within-item factorial design where the experimental treatment variable has two levels (conditions). Let m1 be the maximal model and <...
7
votes
1answer
6k views

Dummy coding for contrasts: 0,1 vs. 1,-1

I'm seeking your help in understanding the difference between two different contrasts for dichotomous variables. On this page: http://www.psychstat.missouristate.edu/multibook/mlt08.htm under "...
5
votes
2answers
670 views

Coding as a categorical or continuous variable?

I have a question/IV in my study which has been answered: 1- No 2- Do not know 3- Sometimes 4- Yes I was advised to remove the answer 2 (all do not know ...
2
votes
1answer
7k views

Binary Encoding vs One hot Encoding

what is the difference between binary Encoding and one-hot for categorical input variables for English Text and their impact on the neural network ? can anyone help me to find a scientific paper about ...
9
votes
4answers
14k views

How to implement dummy variable using n-1 variables?

If I have a variable with 4 levels, in theory I need to use 3 dummy variables. In practice, how is this actually carried out? Do I use 0-3, do I use 1-3 and leave the 4's blank? Any suggestions? ...
7
votes
2answers
4k views

Linearity Assumption in OLS with Dummy Variables

Let's say that I have a continuous response variable and have constructed a regression model with multiple predictors. Most of my predictors are continuous but I have one which is a dummy variable. ...
5
votes
3answers
2k views

Coding categorical variables for regression

I'm not sure of the best way to code my categorical predictor variable for use in a hierarchical regression in order to test my specific hypothesis. This categorical variable has 3 levels representing ...
2
votes
0answers
373 views

Fitting multilevel categorical variables with neural nets

Most of the neural net algorithms I'm aware of require multilevel, ANOVA-type categorical features to be preprocessed into a set of dummy (0,1) variables. So, if one has a single categorical feature ...
1
vote
1answer
53 views

changing the coding system from helmert coding to difference coding changes regression results?

EDIT: I think I have mistaken the names of the coding systems, so I changed it (in bold). The content has not changed at all, though, so I would still appreciate any answer. END EDIT I'm running ...
1
vote
1answer
29 views

Separate Models vs Flags in the same model

I have customer data from 2 brands. The data structure are the same, but I expected the customer behaviour to be different in different brand. So I could train 2 models, 1 for each brand, or I could ...
4
votes
1answer
466 views

Is there something called “mean coding” (like dummy coding & effect coding) in regression models?

When we perform a regression analysis with categorical predictors, we can use (1, 0), called "dummy coding". The coefficients in this case represent the deviation of the groups' means from the mean of ...
4
votes
1answer
146 views

Eicker-Huber-White Robust Variance Estimator

In a regression context, $$ Y_i = \alpha + \beta T_i + \varepsilon_i $$ my textbook defines EHW robust variance estimator as $$ \widehat{\mathbb{V}_{\rm EHW}}(\widehat{\alpha}, \widehat{\beta} | \...
1
vote
0answers
1k views

Using deviation coding (effect coding) of factors in glmnet LASSO in R

Various sources have instructed me how to use deviation coding (aka effects coding) in R (see here, here, and here). My question though, is how to go about doing this for LASSO regression using ...
1
vote
2answers
377 views

Dummy Coding for Regression?

I'm confused about which predictor should have the "0" and which should have the "1" when using dummy codes for regression. For example: Y: time spent at current job X: type of assessment --> ...
1
vote
3answers
118 views

Multiple regression with dummy variables and interaction term

We have done a multiple regression analysis to see how gender and experience affect salary. We used a dummy variable for gender and then we also added the interaction variable (female work experience)....
0
votes
0answers
31 views

interpretation of interaction term in regression

If you have a continuous outcome (Y where positive is favorable) and 3 predictors: ...
0
votes
1answer
4k views

Recoding a variable with three levels into a dummy variable

I need to recode the variable school setting (urban, sub-urban and rural settings) into a dummy variable. I know that when creating a dummy variable, there is one category less (so 2 rather than three ...
0
votes
1answer
36 views

Dummy Variable, Reference Group

My job is to create a dummy variable so that those who voted for the Labour Party are compared to a single reference group that includes all other voters. 1 = Conservative, 2 = Labour, 3 = Liberal ...