All Questions
Tagged with categorical-encoding r
122 questions
2
votes
1
answer
471
views
Why is it necessary to "ignore" a level when applying sum contrasts?
I am confused about how sum contrasts are set up. As I understand, if I have some $K$-leveled factor, I can use sum contrasts to compare each level to the grand mean ($M_G$), effectively testing ...
2
votes
0
answers
1k
views
Dummy variables with dummyVars() - return to original columns [closed]
For building a machine learning model I used dummyVars() function to create the dummy variables for building a model.
...
2
votes
0
answers
710
views
Setting contrasts in lme4: contr.treatment vs contr.sdif [closed]
In my study, each participant completed the very same Reaction Time task 3 times in 3 Sessions. I am not entirely sure if I should code the variable "Session" using ...
2
votes
0
answers
57
views
Coding scheme for redundant levels in a linear model
I want to get the main effects of IV1, IV2 and IV3 as well as the interaction effect of IV2*IV3 on the outcome for the following three independent variables in a repeated measures anlysis:
IV1 ...
2
votes
0
answers
2k
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
1
answer
3k
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 ...
1
vote
1
answer
3k
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)...
1
vote
2
answers
356
views
Why the discrepancy between the classic definition of contrast and that in R
According to Wikipedia, contrast is defined as follows:
Let $\theta_1$,$\ldots$,$\theta_t$ be a set of variables, either
parameters or statistics, and $a_1$,$\ldots$,$a_t$ be known constants.
...
1
vote
1
answer
317
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
1
answer
180
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 ...
1
vote
1
answer
2k
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 ...
1
vote
1
answer
585
views
Why are variables in GLM being split into multiple output variables
I have input for glm that looks like
BMI $grp PRS age gene
24.2 1 3.0 77 0.0
33.8 1 4.0 89 0.0
30.3 1 7.0 58 0.0
I’m inputting this into ...
1
vote
2
answers
95
views
1
vote
1
answer
99
views
Book recommendations for Design and Contrast Matrices
I feel like I have come as far as I can in statistics while not understanding how design and contrast matrices work. Specifically I am interested in how to code custom contrasts like this and whether ...
1
vote
1
answer
2k
views
Interpreting non-orthogonal contrasts R
I'm having trouble finding information on helping me understand how to interpret non-orthogonal contrasts in a regression model.
I have simulated some data to show what I am working with:
...
1
vote
1
answer
366
views
Interpreting Logit Interaction Term Coefficients (continuous * categorical)
I have the following output from a logistic regression model.
...
1
vote
1
answer
504
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 ...
1
vote
1
answer
4k
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 ...
1
vote
1
answer
338
views
How to code non-exclusive variables for logistic regresion
I have a question about logistic regression in R. I want to study the influence of certain comorbidities in patients in predicting deceased status(Y/N). So far, I formatted all my comorbidities(17) ...
1
vote
1
answer
1k
views
Do I need to create a dummy variable?
Im running a multiple regression model and therefore need to create dummy variables for a categorical predictor variable. This variable is 'YSK87' and its values in the dataset correspond to the ...
1
vote
0
answers
82
views
Difference between using a categorical variable vs separate dummy variables
I have 2 drug treatment groups, namely Cis and RT. So, a cell is either exposed to none, Cis only, RT only, or a combination of Cis+RT. There is also another cancer modality group.
I would like to ...
1
vote
0
answers
2k
views
How to interpret SEM mediation analysis results (using Lavaan in R) with binary exposure and outcome variables
I have built SEM model in R using Lavaan. My aim is to report on the indirect effect.
The data I am using is confidential, so I will not be able to share it or provide a reproducible example. Since I ...
1
vote
0
answers
43
views
How can model be significant if no predictors are significant?
Here is my model and output:
...
1
vote
0
answers
380
views
How to code a contrast matrix for repeated contrasts (comparing adjacent levels) where the intercept corresponds with the grand mean?
In brief: How to code a contrast matrix for repeated contrasts (comparing adjacent levels) where the intercept corresponds with the grand mean?
Example-Problem:
A factor of 10 levels.
Each contrast ...
1
vote
1
answer
996
views
Impute missing values of dummy variables, using R's {caret} package: predicted values in between {0;1}?
I'm using {caret} to impute missing data resulting from non-response to survey questions. All of these variables are defined as numeric, though most are dummies. ...
1
vote
0
answers
70
views
Interpreting the covariate p-values in a multivariate generalized linear model?
If a covariate in a GLM is "significant" does that mean it is significantly different from the base case (the group not shown)?
Say we have three groups, Control, Exp1, Exp2. We are ...
1
vote
0
answers
368
views
Panel Data Regression in R with Dummy Variables [closed]
I am currently working on my thesis and thereby analyzing the effects of the increase of COVID-19 cases on the main stock indices of the G7 countries. For this purpose, I have divided the whole period ...
1
vote
0
answers
302
views
One Hot Encode and Logistic Regression [duplicate]
When using Logistic Regression, and the categorical variables are one hot encoded, do we always have to drop a variable to avoid the dummy variable trap? If I recall it correctly, I have seen ...
1
vote
0
answers
780
views
Country-year fixed effects when the instrument varies only by country year
Background
I have a pooled cross section with observations at the firm level in 10 countries over two time periods.
I am trying to estimate the following model:
$$sales=B_0 + B_1taxrate + ...
1
vote
1
answer
89
views
Can SAS Least Squares Means estimation algorithm be translated for a design matrix in Reference coding?
My question is whether it’s possible to compute lsmeans defined in this SAS algorithm if the design matrix is not in GLM form. In particular, in R, if one feeds that design to model.matrix(), then ...
1
vote
0
answers
950
views
Can you use multiple reference groups in a single logistic regression?
When performing logistic regression for a binary categorical variable (i.e. 'gender', being Male or Female in this simple ...
1
vote
0
answers
419
views
Can I include an 'industry dummy' in my Relative Weight analysis? Bootstrapping produces error message!
I am analyzing the impact of 7 different employee satisfaction variables(x1, x2,...,x7) on financial performance in 200 companies over 3 years. Since these 7 predictor variables are highly correlated ...
1
vote
1
answer
133
views
In the summary of output of the regression analysis in R, is there a way to display categorical variable with just one coefficient [closed]
I am doing a linear regression analysis in R with logarithmic dependent variable. One of the control variables is categorical and describes an industry. There are 6 industries and thereby R ...
1
vote
0
answers
2k
views
Random effects with dummy variables
In specification of a Linear Mixed Model (LMM) I encountered an issue with specifying the model, specifically the random effects. I fear I don't know whether the issue is about model specification in ...
1
vote
0
answers
170
views
R Auto.arima Function - Question About Xreg Covariates
I am using the auto.arima function in R. I'm using this to forecast daily sales and am loading a number of covariates (mostly holiday/seasonal dummy variables) with Xreg.
Question (I apologize if ...
1
vote
0
answers
112
views
Handling Infrequently Occurring Categorical Variables
I'm dealing with some data where there are some infrequently occuring categorical variables related to a binary prediction target.
For example marketing partners... some send 1000s of leads but many ...
0
votes
1
answer
2k
views
Multinomial logistic regression reference category function
Bit of background info on the data and methods that I've used. I have a forest road data that consists of one dependent variable which has 4 classes (0-3). The Dependent variable reflects possibility ...
0
votes
1
answer
1k
views
Time effects with dummy variable - regression
I am doing a multiple regression analysis and I wanted to inspect the time effect by using factor(Year) in R. However, I got the following summary results:
Do you ...
0
votes
1
answer
61
views
How to analyse count data that include 0 as a category?
I'm testing the yield of corn subject to two treatments: Temperature (Cold and Warm) and Light Color (Red, Blue, Natural.) The number of plants per plot that produced no cobs, one cob, two cobs and ...
0
votes
1
answer
644
views
Sum contrast model intercept for multiple factors
How is the intercept calculated for a linear model with multiple factors using contr.sum. From what I've read the intercept is equal to the "grand mean", which as ...
0
votes
1
answer
277
views
Linear Regression in R: factor or z-standardise dichotomous variables
How should one handle dichotomous variables in a linear regression? Is it better to z-standardise or is it better to use factors?
For example I have data of an Experiment with a 2x2 Design in which ...
0
votes
1
answer
2k
views
How can I one-hot encode a variable that has only 2 levels? [closed]
I'm trying to do OHC in R to convert categorical into numerical data. However R's caret package requires one to use factors with greater than 2 levels. Any idea how to go around this? I've searched ...
0
votes
1
answer
57
views
Indicator variables/treatment variables as an independent variable?
Can a dummy variable or treatment variable be an independent variable? My independent variable take the value 1 if a flood occurs in a specific country in a specific year and 0 if no flood happens. ...
0
votes
1
answer
32
views
Finding model for categorical Data
I'm trying to find out a model that adequately describes effects of gender and length on food choice. For gender; 0=Male and 1=Female, length; 0=Subadult 1=Adult, Choice; F=Fish I=Invertebrates and O=...
0
votes
1
answer
241
views
Regression in R - dummy variables
Hey I want to build a model in R and one of my idependent variable is categorical (it takes 10 different values). I change the type of this variable from "char" to factor and build a model ...
0
votes
1
answer
2k
views
How do I interpret the coefficients of the reference group for a linear regression with two dummy variables as regressors in R?
I'm using R to fit the following linear regression models with the popular "mtcars" dataset:
...
0
votes
0
answers
34
views
Why does removing the offset change the F-statistic of an anova model in R?
When a linear model with only a single categorical variables is defined without an offset, the F-statistic reported by summary() and ...
0
votes
0
answers
36
views
Opinion about conversion of factor to numeric variable during model development using caret package
caret package automatically converts factor variables to one-hot encoding. We can also convert the factor variable to a numeric variable before training any model. ...
0
votes
1
answer
34
views
Differences in Regression model for Dummy Coding (factor vs. recode) [closed]
I have the following problem: I generate Dummy Variables with the recode and the factor command. In my regression I got different output for the "lower middle" variable and couldn't explain ...
0
votes
1
answer
69
views
OLS model specification that includes all dummy variables with a predetermined coefficient
I'm working with a OLS model that includes dummy variables (quarters of year). Here's what I would specify it:
$$y = \beta X + \gamma_1Q_1 + \gamma_2Q_2 + \gamma_3Q_3 + \epsilon$$
However, in the ...