# 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.

750 questions
Filter by
Sorted by
Tagged with
9 views

### how to select categorical variables for a multiclass logistic regression

i struggle to figure out how to turn something into a categorical variable. I have markov-chain-model with 10 states, so my transition matrix has 10 rows, 10 columns and 100 possible transitions To ...
1 vote
81 views

### Interaction between quadratic term and dummy variable

Suppose I have a linear regression: $Y=\beta_1+\beta_2X+\beta_3X^2+\beta_4D$ where $D$ is a dummy variable that takes value 0 and 1. If I want to examine if the effect of $X$ on $Y$ for $D=0$ and $D=1$...
• 13
85 views

### How to predict next occurrence in sequence where data has both numerical and categorical values?

Lets say we have the following prediction problem. Given data of the following form: Number HasProperty1 HasProperty2 1.5 0 1 1.5 0 1 2 1 0 2 1 0 Where ...
14 views

### How to select data and report a multinomial logistic regression for microbiome

recently I have been working with gut microbiome data, like abundance and its metabolic content (but for purposes of the question this may be indifferent). I'm inexpert in the field of multinomial ...
• 11
1 vote
38 views

### Too many categorical predictors in multinomial logistic regression

I am not familiar with multi-class prediction so I apologize in advance if this questions seem very basic. Here is my dataset: So within the dataset, I am trying to predict which fare product is ...
• 11
1 vote
122 views

### should I use n-1 dummies variables or all variables for a multinomial logistic regression?

Recently I have been working with gut microbiome data, like abundance and its metabolic content (but for purposes of the question this may be indifferent). I'm inexpert in the field of multinomial ...
• 11
1 vote
69 views

### Why does removing intercept not change predicition of linear model in the precence of factor predictors? [duplicate]

In a linear model that predicts birth rate (TFR) per country from per capita GDP, the country is encoded in "treatment coding", and there are several measurements (different years) per ...
• 3,211
105 views

### Missing outputs or coefficients from multiple linear regression?

I have a multiple linear regression I have completed below: ...
• 65
314 views

### Using dummy variables in a linear regression model in R - no need to manually encode when using factor or character string vector types?

A source of confusion that I often come across relates to when people want to use categorical data, where the number of categories is greater than 2, in a linear regression (simple or multiple) and ...
• 158
18 views

### Anova table for linear model, $3$ treatment groups with model $Y_i = 4+6 I_{1,i}-1 I_{2,i}$

Anova table for linear model, $3$ treatment groups with model $Y_i = 4+6 I_{1,i}-1 I_{2,i}$ where $4=B_0 = \bar Y_1$, $B_0+B_1=4+6=\bar Y_2, B_2=\bar Y_3$ and each group has a $5$ patients. The ...
24 views

### Addding a categorical variable to existing regression model generates strange coefficients

I have a regression model with numerical variables only. I created a new feature, categorical variable with options A, B, C. The means of the dependent variable are, by the categories from above are: ...
• 1
1 vote
18 views

### What is a word embedding approach that would work for these pre-labeled documents?

My Situation: I should start off with my end goal: I want to get a distance metric between each document and all of the other documents To get there, I first need to encode these topic labels so that ...
• 595
31 views

### Best way to combine categorical variables

I have two categorical variables measuring outdoor time during winter and summer. As I am interested in the overall outdoor time during the whole year, I am thinking about combining the variables. ...
424 views

### How can I mathematically represent the one-hot encoding?

If we have 5 classes and 3 inputs, let's say [C1, C2, C3, C4, C5] and [X1, X2, X3] then, If ...
1 vote
85 views

### Categorical variable with too many categories. Should I group them according to frequency or according to the target?

I am working with a dataset of flight records and I model the flight delay. I have variables for the origin and destination airport , but each of them has about 300 categories. I think about grouping ...
• 137
1 vote
54 views

### Custom-define contrast - mix between dummy and Helmert coding

I'm trying to use custom-defined contrasts. They are sort of a combination of traditional dummy coding and the last contrast produced by reversed Helmert coding. In short, I want to compare each of ...
• 153
17 views

### how to compare two variables with respect to the occurrence of an event

I have these two predictors and I want to know if individuals with predictor 1 are more likely to have the event (outcome = 1) than those with predictor 2. I want ...
• 505
91 views

### How to encode categorical data with a lot of unique values and streaming data for anomaly detection

I'm working on a Anomaly Detection problem with streaming data, where i use Robust Random Cut Forest (RRCF). I have 295.000+ rows to start with and there is more data coming in. The problem is when ...
702 views

### Target encoding in test data and target leakage

I understand target encoding, which is the average of the target value by category using out-of-fold mean within each fold. although you get slightly different means for the same value of a ...
• 243
1 vote
189 views

### Feature scaling of categorical and ordinal variables in Cox regression

I have a dataset with nominal (unorderable categories), ordinal (orderable categories), and continuous/numerical variables. I am performing Cox Proportional Hazard Regression using the scikit-survival ...
44 views

### One or multiple regression/s?

Say your equation in a paper has 6 coefficients, one being your main interest (dummy for Disability == Having at least one disability: coded 0/1). This estimation is done. BUT you want to dig deeper, ...
38 views

### Difference-in-Difference with temporary event

I am running a Diff-in-Diff analysis about the triggering of a policy that once triggered bans a certain action for 6 months. I have run the analysis considering only pre and post period, including in ...
• 143
619 views

### Is one-hot encoding required for categorical variables in R (logistic regression)?

I created a logistic regression model in R and fit the model using the MumIn package. I have several categorical variables that were coded as factors. For example, season (summer, fall, winter, spring)...
• 19
23 views

### One-way categorical vs. dummy-variable model: Same data, different coefficients and F-values

I am interested in seeing whether treatments interact in a fully factorial design with three treatments. Slinker 1998 recommends running a three-way ANOVA on a model that considers each treatment ...
36 views

### Does the 15:1 rule in multiple linear regression apply at the beginning, or to your final reduced model?

I've read that there are recommendations about how many outcome observations you need per predictor variable in multiple linear regression (often 15:1 or 10:1). I have a dataset with lots of different ...
11 views

### Dummy coding with overlapping categories

Spotify has a structured dataset which contains song tracks with its associated audio features such as energy, speechiness (numeric data), whether there is explicit language in the lyrics (boolean), ...
1 vote
26 views

### Categorical variable perfectly maps to continuous variable

I have a feature vector X in a regression problem, where one of the features X1 is categorical (genre) with 47 categories. There is also another feature X2 which is continuous (# subscribers) but ...
25 views

### Coding independent variable for regression based on relationship with dependent variable and reducing dimensionality

I have a table where rows are dates and columns are values of a dependent and many independent variables. I want to create regression with a number of nominal and ordinal independent variables to ...
• 1
11 views

### Coding via vectors of $K$ dummy variables or bits: How exactly does this work? [duplicate]

Chapter 2.2 Variable Types and Terminology of the textbook The Elements of Statistical Learning, second edition, by Hastie, Tibshirani, and Friedman, says the following: Qualitative variables are ...
• 1,126
1 vote
63 views

### Interpretation of two dummies interacted with one continuous variable

I am currently looking at the following equation using Stata and unsure of how to interpret the interaction terms when there are three variables interacted together (2 binary variables and one ...
• 11
411 views

### Why are models based on coded (-1,1 etc) and non-coded variables (as they are) very different? What should I use for publications?

I am doing factorial experiments in R. I noticed when I use my variables as they are vs. coding them into -1,1, they are all very different. Here is my sample code. ...
327 views

### Dummy variables in a fixed effects model

I'm currently working on the correlation between sustainability and performance in the S&P500. I'm using a panel data model, with fixed effects for both, ime and firm. I wanted to insert a sector ...
145 views

### Missforest imputation algorithm and categorical variables

I am trying to implement MissForest imputation algorithm on a data set of mostly categorical variables. I've run into the problem however of not knowing whether to use one-hot-encoding or label ...
• 103
1 vote
259 views

### How to decide on encoding high cardinality variables for a small dataset?

I already referred the posts here, here, here, here, here etc. Don't mark as duplicate please. I have a dataset with 1008 rows with 16 input variables and 1 target variable. However, 14 of my input ...
• 1,932
1 vote
89 views

### Feature not applicable to some samples

I am working with a private medical dataset including categorical features coming from patients examinations. However, the problem is that some patients underwent MRI, others scanner, and some ...
• 31
45 views

### Comparing non-reference groups with each other in regression-based methods

I am running several multi-level models. The multilevel aspect is not that important here though, this question would be the same even if it was simple regression. Basically, randomly assigned ...
120 views

### Best practice for cyclical feature encoding for tree-based methods

Right now I'm facing a dataset of professional road cyclists which contains training data of the athletes at different dates over two years. For some tree-based methods I'm still looking for a 'best ...
• 218
77 views

### Dummy variable's p value interpretation

I have a question related to the significance of the dummy variable. Some background context: I am writing my thesis and I have hypothesized the following. My first hypothesis hypothesizes that the ...
30 views

### Panel regression rank variable instead of dummy set

Suppose I have the following (panel) regression equation: $$y_{i, t} = \alpha + \mathbf{x_{i,t}}'\mathbf{\beta} +\epsilon_{i,t},$$ where $y_{i,t}$ denotes the wealth of individual $i$ at time $t$, and ...
• 193
31 views

### How do I interpret price elasticity when using state specific dummies and price, dummy interaction

I have price volume data for 3 states for which I want to calculate price elasticity for each state. The model has the following setup:  \ln(Y)=A_1+ A_2\ln(P) +A_3D_1 +A_4D_2+ A_5\ln(P)D_1 +A_6\ln(P)...
• 1
1 vote
237 views

### Interaction effects in regression models - should I include reference category?

I have a question about coding interaction effects using dummy coding which I’d be really grateful for your advice on please. Imagine I want to design an experiment to measure the impact of amount of ...
70 views

### Outcome variable coding for multinomial logistic regression with "I don't know" choice option

I have a categorical outcome variable "Type of intervention" with 3 levels: "Type A", "Type B", & "cannot decide". The "cannot decide" option is ...
619 views

### Interpreting GLM output with categorical data

I am having trouble identifying which reference level R is using for my response variable matnew. I know it sometimes chooses alphabetically, which in this case is "Fail", but I'm not sure ...
• 21
50 views

### Can you combine multiple categories for the interaction terms to reduce the number of them?

I have been asked to a develop linear regression model for trip rates using a categorical variable with 5 levels, a continuous variable and an interaction between them. I've included the categorical ...
40 views

### Advice for how to approach encoding non-numerical data

I have a dataset where the task is to classify whether someone looking for a new job will leave their current job, based on a number of factors. (dataset: https://www.kaggle.com/arashnic/hr-analytics-...
• 361
71 views

### Dummy variables in LASSO

When doing OLS, we usually drop a dummy level in each category (if we are including the intercept) to avoid the dummy variable trap, i.e. multicollinearity, which would make the OLS estimator ill ...
• 353
221 views

### Difference-in-Difference with two control groups and one treatment group over the same period of time using RStudio

So I'm trying to run a regression for one of my economics classes with one treatment group and two control groups over a period of time. I'm currently trying to create a dummy (binary) variable to ...
35 views

### Can I just use one effect-coded variable instead of two dummy variables when I perform a regression, if there are 3 groups?

To make things simple, let say I ran a basic psychometric experiment and I want to test whether the response time (i.e. a continuous variable) can predict the performance score (i.e. a continuous ...
Assume that I am interested in performing a between group comparison for a given variable but I know that this $y$ variable is confounded by at least a couple of other variables. Say, \$y = Device_1 + ...