All Questions
Tagged with categorical-encoding r
122 questions
28
votes
2
answers
57k
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 ...
21
votes
2
answers
22k
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 ...
20
votes
2
answers
29k
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 ...
16
votes
2
answers
63k
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....
13
votes
2
answers
21k
views
Why does the intercept column in model.matrix replace the first factor?
I'm trying to convert my factor column to dummy variables:
...
10
votes
4
answers
16k
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?
...
10
votes
1
answer
9k
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)
<...
9
votes
2
answers
986
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 <...
9
votes
1
answer
10k
views
Encoding of categorical variables (dummy vs. effects coding) in mixed models
The model based on the experiment looks like this:
...
8
votes
1
answer
1k
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 ...
7
votes
1
answer
1k
views
Collapsing categorical data easily for regression in R
I have read an article from Christopher Manning, and saw an interesting code for collapsing categorical variable in an logistic regression model:
...
7
votes
2
answers
5k
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 ...
6
votes
2
answers
11k
views
Decision Tree - Splitting Factor Variables
I'm new to decision trees and I have some confusion about how factor variables and non-ordered character/string variables get handled in a split.
Suppose I have a factor such as "tiny, small, medium, ...
5
votes
1
answer
8k
views
In a multilevel linear regression, how does the reference level affect other levels/factors and which reference level ought to be selected?
In the diagram, Heavy smoker is the reference level as it is not shown with summary. How and what other categorical level should be used instead? Why?
...
5
votes
2
answers
109
views
How to calculate the reference level interaction in regression in R?
I am very confused on calculating the reference level interaction in regression in R.
Here is the sample code:
...
4
votes
2
answers
2k
views
Why do we omit the intercept when applying LASSO to categorical data?
I have a data set with 16 multi-level categorical predictors and one response variable, in order to fit LASSO to the data set on glmnet I transformed the ...
4
votes
1
answer
278
views
Should I remove the intercept when I have one dummy variable that covers all the categories in a categorical variable?
I have a categorical variable that has $4$ categories, and I have two dummy variables, $x_1$ and $x_2$, that cover this categorical variable. The $x_1$ variable has values of only $1$ without any ...
4
votes
2
answers
183
views
Variable for logistic regression is categorical and continuous so creates “missingness” in R
I am doing a logistic regression analysis using the glm command in R. It is to identify causes of valve narrowing beyond a certain threshold; 0=no narrowing, 1=narrowed. One of my variables is the ...
3
votes
5
answers
2k
views
Multiple linear regression with lm() in R, why is the intersection dependent on the name of the "first" country
I have a question about the function lm() used for multiple linear regression analysis.
Context: We have a dataset (that I cannot share) where $y$ is the proportion ...
3
votes
1
answer
558
views
Does it make sense to convert a single dummy variable into a factor?
I have an R lecture script infront of me, where we are using logistic regression to try to predict the probability that an observation belongs to the target class (e.g. y_i = 1) or not (e.g. y_i = 0). ...
3
votes
2
answers
1k
views
Which groups are reference groups in a regression model with interaction?
What are the reference groups in a regression model where there are interaction categories? Using the iris dataset in R, I've created a category with three levels ...
3
votes
1
answer
3k
views
Difference between dummy and factor variable?
I've just learnt about dummy variables. Say this is my data:
Location
Nest
XXX
Yes
XXX
No
ZZZ
Yes
YYY
Yes
YYY
No
And I want to do multicolinearity tests/logistic regression in RStudio, so I don'...
3
votes
1
answer
4k
views
Results of Type-3 Wald Chi-Square Different for GLMM with Different Contrast Coding
I have just completed a multilevel, longitudinal logistic regression testing, at four different time points, whether participants in an experimental group are more likely to have committed any drug-...
3
votes
1
answer
3k
views
Why are results different when using aov_ez{afex} and Anova{car}, Type III SS in R?
Hopefully, the answer to this question is simple.
Why do I get different results when I am using Anova from the car package and the aov_ez from the afex package?
...
3
votes
1
answer
362
views
Categorical variable disappears in Poisson GLM summary?
For the variable SelfEthnicity there is meant to be 4 levels.
I have made it so there should not be a reference category, but the R output still only shows 3 Ethnicities.
...
3
votes
1
answer
45
views
Logistic regression in R: Handling mixed numerical and categorical variables
I'm attempting to fit a logistic regression model in R and need some guidance on handling both numerical and categorical variables simultaneously, especially when looking for significant explanatory ...
3
votes
1
answer
909
views
Interpreting the effects of dummy interactions
Warning
This question is quite long, and maybe a lot of you will think it is too long. I however thought, and hope, that if this question gets a proper answer, it will actually be a really good post ...
3
votes
1
answer
2k
views
Handling redundant factor variable levels for linear regressions in R
Say I have two factor variables, X and Y, each with 3 levels. However, X==3 if and only if Y==3, while such a connection doesn't hold for X,Y==1,2. In this case, while X and Y are not redundant, my ...
3
votes
1
answer
352
views
Helmert coding for mixed models in R
I am using R to analyse data from an experiment with six conditions. Condition has two dimensions: for cognitive load, I have two levels (load and ...
3
votes
1
answer
2k
views
Design matrix contrast coding for model selection and 'main effects' vs. 'simple main effects' interpretation in linear mixed effects model (R/Matlab)
My question is about contrast coding and planned contrasts in three-way interactions for a linear mixed effects model. Sample code is provided for R and Matlab as I can work in either one, but prefer ...
2
votes
1
answer
117
views
how to interpret classes dependence that are not the reference class in a linear model
If we run the three following codes:
...
2
votes
1
answer
8k
views
How to include dummy variables for year? [closed]
I have the following multiple linear regression:
reg <- lm(Y ~ x1 + x2 + d1 + d2, df)
and in my dataset I have a series called "year" which contains, you ...
2
votes
2
answers
94
views
Recreate `lm` Categorical Regression
Consider the code, which contains regression using lm of two categorical and one continuous variables without interaction using data from the correct model:
...
2
votes
1
answer
841
views
Adding a Dummy Variable to glm in R?
I'm running a glm in R with two categorical variables, one of which is binary, the other of which can take on five values. I would like it so that my model returns an intercept value that reflects the ...
2
votes
1
answer
2k
views
Interpretation of categorial predictor in poisson regression
I have performed a Poisson regression where my outcome/dependent variable is a count variable of how many technical devices someone ones (ranges from 1 to 9) and I have a bunch of predictor/...
2
votes
1
answer
178
views
Am I interpreting my lm() summary() results correctly in R?
(this question I originally posted in stack overflow)
I want to know if I am interpreting the factor() function in R correctly. Suppose I have a variable with 10 ...
2
votes
1
answer
68
views
Interpreting logistic regression coefficients of a variable overall and levelwise
Context
Let Y be a logical vector and X1 a factor with 3 levels.
Since Y is binary, logistic regression is used.
...
2
votes
1
answer
1k
views
Dummy Variables vs Factor Usage in R for building Cox Regression
I'm aware that factors are the proper way to handle categorical variables but the explanation gets a little confusing when we start having factors with multiple levels.
For example, let's say I have a ...
2
votes
1
answer
93
views
Is there any theory governing factors vs flags
I'm doing some work in R using the gbm package. I'm curious about the repercussions of treating categorical variables as ...
2
votes
1
answer
454
views
When I change my reference level on my GLMER in R, why do the p-values change and why don't the estimates add up? Emmeans solution in answer
I am new to this. My study has three conditions (between subjects - low coordination, high coordination, high coordination with ostensive cues) and three repetitions of a game (within subjects - Game ...
2
votes
1
answer
713
views
"Group mean centering" a dummy Variable in R for multilevel analysis: how can i do this?
have somebody an idea of how to group mean center a dummy Level 1 predictor in R?
Enders & Tofighi (2007) describe a method to center a dummy variable through substracting the proportion of the ...
2
votes
1
answer
2k
views
The difference in interpretation between a country and a year dummy, a country-year dummy and both
I am trying to expand my knowledge about the different interpretations of combinations of fixed effects.
I am using a pooled cross section dataset with observations at the firm level. The dataset ...
2
votes
1
answer
90
views
Setting contrasts for 10-level categorical variable
I have survey data on income and support for environmental protection. Income is a continuous variable that I have broken up into deciles. I have a hypothesis that support for protection ('Agree') ...
2
votes
1
answer
585
views
regression models and dummy variables
I have a output variable and 1 categorical predictor and 3 continuous predictors.
...
2
votes
1
answer
220
views
Model overall effect of predictor within categories
I'm trying to fit a generalized linear model in R, but am quite new to regression, and struggling to work out how to have predictors nested within categorical variables.
An example of my data:
<...
2
votes
1
answer
2k
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 ...
2
votes
1
answer
4k
views
Multiple Factor Analysis with FactoMineR: error with categorical and dummy variables
I'm interested in using multiple factor analysis to analyze data collected from ceramic sherds.
The data contains continuous variables (e.g., vessel rim diameter, vessel wall thickness) and ...
2
votes
0
answers
45
views
Dropped variable in regression output in R
I am running a linear regression trying to predict an outcome y that is a numeric, continuous variable based on a variable with three levels (A,B,C) and three more variables that represent the ...
2
votes
0
answers
29
views
Some Confusions Regarding Variable Importance Extraction of Several Machine Learning Models
I'm trying to apply several machine learning algorithms in R using caret (decision trees, ensemble methods (bagging, boosting, ...
2
votes
0
answers
395
views
Can we use as.factor to convert categorical variables having multiple levels for decision tree or we need to use model.matrix please help! [closed]
I am trying to build a decison tree model in R having both categorical and numerical variables.Some categorical variables have 3 levels , so can I just use as.factor and then use in my model? I tried ...