Bisola
Bisola

Reputation: 31

Does re-labelling categorical variables change conditional inference tree result in partykit?

I'm using the function from from my analysis. My ctree contain all binary/categorical variables. When I change the value labels of the binary categorical variables, I end up getting a different ctree diagram.

Initial Labels

Racialized: 0 = "non-rac" ; 1 = "rac"

Immigrant: 0 = "non-imm"; 1 = "imm"

New Labels

Racialized: 0 = "no" ; 1 = "yes"

Immigrant: 0 = "no"; 1 = "yes"

I'm finding that this is only an issue when I change the labels to "yes/no". I've looked through my code and nothing else has changed. I don't understand why this is happening.

I'll appreciate any help/ideas.

Update Here's a glimpse of the code I initially used for "labelling" my variables, which pretty much changed by numeric variables to character:

data$racialized[data$PP_racialized==0]<- "non-rac"
data$racialized[data$PP_racialized==1]<- "rac" 

data$racialized[data$PP_racialized==0]<- "no"
data$racialized[data$PP_racialized==1]<- "yes" 
#before Ctree analysis 
data <- data %>% dplyr::mutate_if(is.character, factor)

I find that when I use the apply_labels function instead my results stay consistent and I no longer get a discrepancy when I rename my variables

data=apply_labels(racialized=c("rac"=1, "non-rac"= 0))

data=apply_labels(racialized=c("yes"=1, "no"= 0))
#before ctree analysis
data <- data %>% dplyr::mutate_if(is.numeric, factor)

Upvotes: 1

Views: 108

Answers (0)

Related Questions