Questions tagged [categorical-data]
Statistical data type whose value is one of a fixed number of nominal categories.
1,771
questions
0
votes
0
answers
22
views
Collapsing categorical variables with many levels with respect to target
I am trying to apply a methodology to collapse/fuse (not just select part of them) some levels of categorical variables, considering their impact on a continuos target variable. I've come across this ...
0
votes
0
answers
35
views
Neat visualization of 3 categorical variables (up to even 5!)
A neat way to visualize 3 categorical variables (with more than 10 levels each) is to plot a stacked bar showing the (weighted) proportion of the levels in var1 for every combination of var2 and var3. ...
1
vote
0
answers
28
views
tbl_summary, is there a way to compare categorical data by row as well as column? (Fisher's exact test; Pearson's Chi-squared test)
There are multiple categories in the table. Below I describe one variable as an example with the hope it can be applied across variables.
Currently, my code compares the columns female and male Food ...
1
vote
1
answer
32
views
Order plotly figure by CategoricalDtype order
The goal is to visualize boxplots for each group in order. Group is ofpd.CategoricalDtype and ordered.
I do not manage to get plotly to respect the order. Instead, it only sorts alphabetically.
import ...
-1
votes
1
answer
29
views
Can I use cumsum in pandas when I want to cum sum ~5000 categories?
I'm looking for a way to get a cumulative summation of my PERIOD_BAL for each of the %Entity_Acc categories.
Can this be done with cumsum or is there another way of doing this?
I'm relatively new to ...
0
votes
2
answers
32
views
Significance tests across more than two levels of a categorical variable in R
I'm trying to determine if there are significant differences in frequencies of a categorial variable with 8 levels between two groups. In this case, two groups are asked their favorite colors with 8 ...
0
votes
1
answer
71
views
Efficient way to convert 4 billion hex integers to decimal integer in R or python
I have a csv file with about 4.4 billion rows. It has 25 categorical columns, all of which are hexadecimal encoded integers, such as EE6B2800 and 10642AC00.
I have a machine with 3TB of RAM and used ...
1
vote
1
answer
19
views
Test and Train Data have different cities, how to find and differences and encode using the same coding system on both columns from test & train data
I have a test set and train set. They have a city columns one (train) has 290 unique and the test has 30. I am hoping there is overlap i.e. London, Bristol are in both sets, but Gloucester might be on ...
3
votes
2
answers
47
views
Difference between pd.Categorical and pd.api.types.CategoricalDtype
EDITED
Based on the answers so far (thank you), I understand what the CategoricalDType is and what it's used for. What is the Categorical / categorical array for? Does it have a common use case?
--
I ...
0
votes
1
answer
66
views
reordering relabeled data on y axis
I have a dataset that x is a tuple integer:
[1,2,3,4,5,6,7,8,9,10,...40]
and y is a string tuple
['5', '2', '5', '2', '5', '2', '5', '2', '5', '2', '5', '2', '5', '2', '4', '2', '4', '2', '5', '1', '5'...
1
vote
2
answers
40
views
Comparing two elements of a categorical variable according to their ordered categorization
In Python, I create a categorical variable like this:
x = pd.Categorical(["Hi", "Lo", "Med", "Zer", "Lo", "Zer", "Lo", "Hi&...
-1
votes
1
answer
75
views
Handling categorical missing data in churn prediction model for telecom data [closed]
I am working on a telecom dataset where I need to fit a model to for predicting churn(yes or no). There are a lot of categorical data with missing values( total values 7043). What is the best way to ...
0
votes
0
answers
82
views
R: simulation of longitudinal data with an ordered categorical variable
I'm trying to simulate longitudinal data for my research. The data must contain a categorical variable and another ordered categorical variable. To do this, I'm using the simstudy R package, which can ...
0
votes
0
answers
30
views
Backward Difference Encoder
I'm trying to use Backward Difference Encoder in certain columns and then train a logistic regression model.
def train_model_v0(X, y, model, cat_enc_method):
# Applying Ordinal Encoding to the ...
0
votes
1
answer
30
views
How to add two columns in pivot table (Excel)
I am trying to find a way to have two categorical variables in a pivot table? (instead of a drop down within the same column)
The way that it automatically works is not really practical to futher ...
0
votes
0
answers
11
views
How to compare continuous data for a categorical response variable?
Apologies for an extremely basic question but I have an analysis block (analogous to writer's block). I have the following data:
Location<-c(Site1, Site2, Site 3)
Rainfall <-c(34.5,54.6,182.1,...
1
vote
1
answer
40
views
Shiny Dashboard Categorical Variables and Bar Charts
I'm trying to create an interactive chart to toggle between different variables. One of these variables is numerical (age) but the others are all categorical (gender, department, position). I used ...
0
votes
0
answers
17
views
Error: unexpected input in "fit<-glm(Y1 ∼"
Y1<- recode(Prostate_Cancer$Y,"8=1;c(6,7)=0")
X1 <- Prostate_Cancer$X1
X2 <- Prostate_Cancer$X2
X3 <- Prostate_Cancer$X3
X4 <- Prostate_Cancer$X4
X5 <- Prostate_Cancer$X5
...
0
votes
2
answers
94
views
What's the difference between astype("category), categorical() and factorize()?
Python offers many ways to convert a variable to categorical.
import numpy as np
import pandas as pd
mydata = pd.Series(['A', 'B', 'B', 'C'])
mydata
0 A
1 B
2 B
3 C
dtype: object
pd....
0
votes
0
answers
66
views
Stuart-Maxwell / marginal homogeneity test help in R
I believe I need to use a Stuart-Maxwell mh test for my data because it is paired (before/after responses) and all categorical. There are 5 possible responses which people answered in a survey. I only ...
0
votes
1
answer
126
views
Is there a function in R to create simulated categorical variables from logistic regression results?
I can create continuous and binary variables from a set of logistic regression results. However, I am struggling to create categorical variables from a set of logistic regression results.
For example, ...
1
vote
1
answer
45
views
Adding a 4th variable in a plot as the bar outline
I have a ggplot with 3 variables. I want to add a 4th variable "circumstances_bite_avoidability" which would be denoted by the coloured border of the bars. How do I do this? If it can be ...
1
vote
1
answer
28
views
Hide categories in legend
I have a graph with 3 variables. I have two legends. In the legend for "Intentional Human Engagement", I wish to only show "Threatening Engagement", "Friendly Engagement" ...
0
votes
1
answer
18
views
the legend categories in the graph itself and not on the legend
I want a graph where the "vacc_status_broad" variable categories show in the graph itself and not just on the legend.
this is my code
sur %>%
filter(species_broad == "Dog")%&...
1
vote
1
answer
30
views
SPSS Syntax: spliting one categorical variable into multiple yes/no variables
I have a categorical variable (v0) with options 1, 2 and 3. I want to split this into 3 yes or no variables (v1, v2, v3).
1,2 and 3 are not mutually exclusive, here is the logic:
if 1 is true then 2 &...
0
votes
0
answers
44
views
Is there an easy way to get the mapping of a categorical column from a pandas data frame?
For a project, I was given data in SPSS .sav-files that had previously been handled using R. I'm now trying to "translate" into Python and have been using pandas for that, more specifically ...
1
vote
3
answers
51
views
R: Merge several categorical of one variable into factor
My dataset is from a repeated measure design. Now I would like to create a subset with a new categorical variable. In this subset several factorial values of one meausred categorical variable should ...
0
votes
1
answer
33
views
Add Permutations with Unique New Categorical Variable to Dataset
I have a dataset (below) which has multiple categorical and numerical variables. There are a set of unique combinations of the categorical variables, but not all permutations are in the dataset (and ...
0
votes
0
answers
21
views
How to list predictive values of associated categorical variables identified via Goodman-Kruskal's tau?
I have a dataset with purely categorical variables and used the GKtauDataframe() function of the GoodmanKruskal package in R to produce a matrix of associated variables. The package does not seem to ...
0
votes
0
answers
8
views
Excel Pivot Chart with two Categorical Values and Timeline
I have data in the following format:
´´´
Name
Date
Method Used
"some other random data"...
Joe
Q1 21
Method A
....
Bob
Q1 21
Method B
....
Joe
Q2 21
Method A
....
Bob
Q2 21
Method C
...
...
0
votes
1
answer
55
views
How should I prepare the data for Lightgbm categorical_features?
The categorical_feature of the lightgbm library states that:
Note: all values will be cast to int32
But also that:
Note: all values should be less than Int32.MaxValue (2147483647)
Note: using large ...
0
votes
2
answers
37
views
add count and percentage in the y-axis
How to show the observed count, total count and percentage in the y-axis in brackets below the category name. The variable "sex_vic" is a categorical variable.
My code:
sur %>%
ggplot(...
0
votes
2
answers
56
views
In R, how to specify contrasts to compare weighted means of multiple groups in linear model?
I'm trying to use effects coding in a linear model to compare the weighted means of groups of unequal sample size against each other. In this dummy example, we have one group of 19 observations with ...
0
votes
0
answers
44
views
Handling Categorical Input Attributes in Classification with GBM (caret package / R)
How does the gbm function from the caret package in R handle categorical input attributes when dealing with a classification dataset? Can it handle them natively? Does it require any encoding (such as ...
1
vote
0
answers
16
views
Model specification for MNL model with multiple interactions between categorial variables
Background: (non-essential for question but should add context). I am conducting a discrete choice experiment. To determine my experimental design (which levels of attribute levels are presented to ...
1
vote
1
answer
56
views
Color tiles (triangles) of a categorical ternary/simplex plot according to numeric values
I have a data set with combinations of 3 categorical variables (each with 6 classes) and a continuous value (ranging from 0 to 1) that belongs to these class combinations. In R, this data looks like ...
1
vote
0
answers
41
views
How can I vizualize in a network or a map a matrix with count data from categorical variables?
I have a dataframe from an experiment with the stimuli on the columns and responses (in the form of one word) from participants in the rows. Each participant saw each one of the stimuli. The dataframe ...
0
votes
0
answers
50
views
How can I measure the similarity of sequential categorical data?
My data is a series of timestamps for sent and received messages from conversations. I have my original data as well as a variant sequence that I've generated.
Original: S---R--S-R----S
Variant: S-S--...
0
votes
0
answers
23
views
Nominal Categories: Cat and Dog Breeds - overlapping categories
I have some data, say pictures of dogs and cats, and labels for them. The vast majority of my samples are labeled by breed (German Shepherd, Domestic short hair, etc.), but a few just have a Cat or ...
1
vote
1
answer
33
views
Goodness of fit with one group but clustered data?
Let's say I have one group with a categorical variable with different frequencies of the levels, but the data is also clustered with unequal clusters - I am interested in whether some of the variable ...
0
votes
0
answers
12
views
Create DataFrame with Categorical Data Above or Below Average
i have a dataframe with monthly data and monthly averages in columns that Im showing below for each month and each variable that is separated by the column 'plant_name'. I need to assign a '1' if the ...
1
vote
1
answer
32
views
add "n" in the y-axis in bracket on a bar graph of proportion when looking at a single categorical variable
I am making a proportional bar graph with error bars. I need to have the number and percentage in the y-axis category name. For eg. Male (n=203/360, 56.38%).
variable_count_census %>%
ggplot(...
0
votes
0
answers
166
views
Single Season Occupancy Modeling in unmarked-How to create a model-averaged prediciton of occupancy and confidence interval with categorical values
I am fairly new to unmarked as a package, but I'm trying to estimate the occupancy of Cooper's Hawks across Denver considering a list of covariates. I've found that percent tree canopy cover (PCT_CAN) ...
-1
votes
1
answer
37
views
Pandas: Categorical sort not happening in defined order instead picks up alphabetical order [duplicate]
have got a dataframe df like below:
maingroup subgroup item itemrank
Citrus Mandarin aa 12
Citrus Lemon bb 22
Citrus Kiwi cc 32
Citrus ...
0
votes
1
answer
46
views
How can I conditionally fill color using two variables in ggplot2?
I am fairly new to R, and I am trying to create a scatterplot in which the fill of points (representing study sites) depends on the variable, acceleration. However, I also want to omit the fill in ...
0
votes
0
answers
19
views
What is the STD of the distribution of categorical data?
K-Means clustering allows one to look for centroids in a multivariate dataset. The outputs are those centroids as well as 'labels' which is essentially a list of integers between 1 and k representing ...
0
votes
1
answer
38
views
Add total count in the bargraph
I have a stacked bar graph with 3 variables. How do I add the total number of counts of each in the y-axis. For eg in the picture, I would like to add Rat/rodent (n= 37), Dog (n = 297) and Cat (n=23) ...
0
votes
0
answers
22
views
What could be causing my R dumbbell plot to only display a single point on the x-axis?
I am trying to create a dumbell plot of two categorical variables.
The data is participants in a study who have samples collected at certain timepoints in a study. Participants are labelled P-001, P-...
1
vote
2
answers
72
views
Sampling Data, Update number of factor levels [duplicate]
I have a given dataset with 1000 observations and 10 columns.
Data can be found here. Every column represents a categorical variable with differing numbers of factor levels and are defined as such.
...
-1
votes
1
answer
45
views
R - Converting multiple dataframes within a list to numeric
I´ve recreated the datastructure so it may help me to get my question better across. Lets generate some data.
a <- c(10,20,30,40)
b <- c('book', 'pen', 'textbook', 'pencil_case')
c <- c(TRUE,...