How do I flip categories before making a PCA

If I want to make a PCA with 4 variables.
And one of the variables goes from "disagree strongly, disagree, neutral, agree, agree strongly"
and another factor goes from "agree strongly, agree, neutral, disagree, disagree strongly"
How can I 'reverse' so I can create the PCA?

Kind regards

One of the may way is to recode the variable this way,
Assuming your variable are stored as numeric,

S<- data.frame(a=c(1, 2, 2, 2, 3, 3, 4, 5, 1, 1), b=c(2, 3, 4, 5,2, 2, 4, 1, 1, 2))

#you want to reverse code both and b variable
S[,c(1,2)] <- ifelse(S[,c(1,2)] == 1, 5,
ifelse(S[,c(1,2)] == 2, 4,
ifelse(S[,c(1,2)] == 3, 3,
ifelse(S[,c(1,2)] == 4, 2,
ifelse(S[,c(1,2)] == 5, 1,NA))))

If your data are stored as numeric, you can effectively flip/reverse them by subtracting the value from the maximum value of the scale, plus one.

library(dplyr)

pca_df <- tibble(
    a = 1:5,
    b = 5:1
)

pca_df
#> # A tibble: 5 x 2
#>       a     b
#>   <int> <int>
#> 1     1     5
#> 2     2     4
#> 3     3     3
#> 4     4     2
#> 5     5     1

num_levels <- 5

pca_df %>%
    mutate(
        rev_a = num_levels + 1 - a,
        rev_b = num_levels + 1 - b
    )
#> # A tibble: 5 x 4
#>       a     b rev_a rev_b
#>   <int> <int> <dbl> <dbl>
#> 1     1     5     5     1
#> 2     2     4     4     2
#> 3     3     3     3     3
#> 4     4     2     2     4
#> 5     5     1     1     5

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.