4

I'm trying to perform this function in R: fviz_famd_ind() and keep getting an error. It works on the wine dataset provided in the package, but not on my cleaned data set from Telco.Customer.Churn from IBM.

I've created the object of the FAMD function using the cleaned data set called dfcfamd1. I've verified there are no duplicate row or column names in the sets using any(duplicated(rownames())) for both Telco.Customer.Churn and dfcfamd1 which both return FALSE.

fviz_famd_ind(dfcfamd1)

> Error in `.rowNamesDF<-`(x, value = value) : 
>   duplicate 'row.names' are not allowed
> In addition: Warning message:
> non-unique values when setting 'row.names': ‘No’, ‘Yes’

Sample Data below

head(Telco.Customer.Churn)

    customerID  gender  SeniorCitizen  Partner  Dependents  tenure
1   7590-VHVEG  Female              0      Yes          No       1
2   5575-GNVDE    Male              0       No          No      34
3   3668-QPYBK    Male              0       No          No       2

 PhoneService    MultipleLines InternetService OnlineSecurity
1          No               No             DSL             No
2         Yes               No             DSL            Yes
3         Yes              Yes     Fiber optic             No


  OnlineBackup DeviceProtection  TechSupport  StreamingTV   
1          Yes               No            No          No
2           No               No            No          No
3           No              Yes            No         Yes

 StreamingMovies        Contract  PaperlessBilling       PaymentMethod
1             No   Month-to-month               Yes   Electronic check
2             No         One year                No       Mailed check
3             No   Month-to-month               Yes       Mailed check

  MonthlyCharges    TotalCharges    Churn
1          29.85           29.85       No
2          56.95         1889.50       No
3          53.85          108.15      Yes

The output should give me a graphical output which it does for the package data, but not for my data.

Attempting to set names to unique, I get a vector error:

rownames(dfcfamd1) = make.names(names, unique=TRUE)

> Error in as.character(names) : 
>   cannot coerce type 'builtin' to vector of type 'character'
starball
  • 20,030
  • 7
  • 43
  • 238
Bashta
  • 49
  • 2

3 Answers3

1

The issue is that names is a function

 rownames(dfcfamd1) = make.names(names, unique=TRUE)

instead it should be

 row.names(dfcfamd1) = make.names(row.names(dfcfamd1), unique=TRUE)
akrun
  • 874,273
  • 37
  • 540
  • 662
1

Try:

fviz_pca_ind(dfcfamd1)

PS: I met the same problem! It could be solved by simply using the function fviz_pca_ind rather than using the function fviz_famd_ind, as the two functions use data with similar structures.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
0

It seems that fviz_famd_ind cannot handle the same values across multiple categorical columns.

One way to solve this is to rename the values to be unique across columns:

# Define factors
cols <- c("Partner","Dependents ", "PhoneService", "MultipleLines", "InternetService","OnlineSecurity" "OnlineBackup", "DeviceProtection",
"TechSupport", "StreamingTV", "StreamingMovies","PaperlessBilling","Churn")

dfcfamd1[cols] <- lapply(dfcfamd1[cols], factor) 
rm(cols)

# Rename the factors
# Do this for every column until only unique values remain. 
dfcfamd1$Partner<- recode_factor(dfcfamd1$Partner,"Yes" = "yesParnter", "No" = "noPartner")
#[...] 
dfcfamd1$Churn<- recode_factor(dfcfamd1$Churn,"Yes" = "yesChurn", "No" = "noChurn")

# Run the function on dfcfamd1
fviz_famd_ind(dfcfamd1)
Picard
  • 11
  • 5