### Load PCAmixdata library Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/supplementary.html Initial setup to load the package. ```R library(PCAmixdata) ``` -------------------------------- ### Perform PCAmix, PCA, and MCA analyses Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Examples demonstrating how to use PCAmix for mixed data, standard PCA, and MCA, including handling missing values. ```R #PCAMIX: data(wine) str(wine) X.quanti <- splitmix(wine)$X.quanti X.quali <- splitmix(wine)$X.quali pca<-PCAmix(X.quanti[,1:27],X.quali,ndim=4) pca<-PCAmix(X.quanti[,1:27],X.quali,ndim=4,graph=FALSE) pca$eig pca$ind$coord #PCA: data(decathlon) quali<-decathlon[,13] pca<-PCAmix(decathlon[,1:10]) pca<-PCAmix(decathlon[,1:10], graph=FALSE) plot(pca,choice="ind",coloring.ind=quali,cex=0.8, posleg="topright",main="Scores") plot(pca, choice="sqload",main="Squared correlations") plot(pca, choice="cor",main="Correlation circle") pca$quanti$coord #MCA data(flower) mca <- PCAmix(X.quali=flower[,1:4],rename.level=TRUE) mca <- PCAmix(X.quali=flower[,1:4],rename.level=TRUE,graph=FALSE) plot(mca,choice="ind",main="Scores") plot(mca,choice="sqload",main="Correlation ratios") plot(mca,choice="levels",main="Levels") mca$levels$coord #Missing values data(vnf) PCAmix(X.quali=vnf,rename.level=TRUE) vnf2<-na.omit(vnf) PCAmix(X.quali=vnf2,rename.level=TRUE) ``` -------------------------------- ### Visualize PCAmix results Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Examples of plotting correlation circles, individual maps, and squared loadings using the plot method for PCAmix objects. ```R data(gironde) base <- gironde$housing[1:20,] X.quanti <-splitmix(base)$X.quanti X.quali <- splitmix(base)$X.quali res<-PCAmix(X.quanti, X.quali, rename.level=TRUE, ndim=3,graph=FALSE) #----quantitative variables on the correlation circle plot(res,choice="cor",cex=0.8) #----individuals component map plot(res,choice="ind",cex=0.8) #----individuals colored with the qualitative variable "houses" houses <- X.quali$houses plot(res,choice="ind",cex=0.6,coloring.ind=houses) #----individuals selected according to their cos2 plot(res,choice="ind",cex=0.6,lim.cos2.plot=0.8) #----all the variables plotted with the squared loadings plot(res,choice="sqload",cex=0.8) #----variables colored according to their type (quanti or quali) plot(res,choice="sqload",cex=0.8,coloring.var=TRUE) #----levels component map plot(res,choice="levels",cex=0.8) #----example with supplementary variables data(wine) X.quanti <- splitmix(wine)$X.quanti[,1:5] X.quali <- splitmix(wine)$X.quali[,1,drop=FALSE] X.quanti.sup <-splitmix(wine)$X.quanti[,28:29] X.quali.sup <-splitmix(wine)$X.quali[,2,drop=FALSE] pca<-PCAmix(X.quanti,X.quali,ndim=4,graph=FALSE) pca2 <- supvar(pca,X.quanti.sup,X.quali.sup) plot(pca2,choice="levels") plot(pca2,choice="cor") plot(pca2,choice="sqload") ``` -------------------------------- ### MFAmix Function Example Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Demonstrates how to use the MFAmix function with sample data. It includes data preparation, model fitting, and prediction of scores for new data, followed by plotting. ```R data(gironde) class.var<-c(rep(1,9),rep(2,5),rep(3,9),rep(4,4)) names<-c("employment","housing","services","environment") dat<-cbind(gironde$employment,gironde$housing, gironde$services,gironde$environment) n <- nrow(dat) set.seed(10) sub <- sample(1:n,520) res<-MFAmix(data=dat[sub,],groups=class.var, name.groups=names, rename.level=TRUE, ndim=3,graph=FALSE) #Predict scores of new data pred<-predict(res,data=dat[-sub,]) plot(res,choice="ind",cex=0.6,lim.cos2.plot=0.7) points(pred[1:5,c(1,2)],col=2,pch=16,cex=0.6) text(pred[1:5,c(1,2)], labels = rownames(dat[-sub,])[1:5], col=2,pos=3,cex=0.6) ``` -------------------------------- ### Predict Function for PCAmix/PCArot (Quantitative Data) Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Example of using the predict function with quantitative data. It shows fitting PCAmix and PCArot models and then predicting scores for new observations. ```R # quantitative data data(decathlon) n <- nrow(decathlon) sub <- sample(1:n,20) pca<-PCAmix(decathlon[sub,1:10], graph=FALSE) predict(pca,decathlon[-sub,1:10]) rot <- PCArot(pca,dim=4) predict(rot,decathlon[-sub,1:10]) ``` -------------------------------- ### Initialize MFAmix analysis Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Loads the gironde dataset and prepares the data for MFAmix by concatenating tables and defining groups. ```R library(PCAmixdata) data(gironde) names(gironde) ``` ```R #Concatenation of the 4 datatables dat <- cbind(gironde$employment,gironde$housing,gironde$services,gironde$environment) index <- c(rep(1,9),rep(2,5),rep(3,9),rep(4,4)) names <- c("employment","housing","services","environment") res.mfamix<-MFAmix(data=dat,groups=index, name.groups=names,ndim=3,rename.level=TRUE,graph=FALSE) ``` -------------------------------- ### PCAmix and PCArot with Wine Data Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Demonstrates PCAmix for mixed data (quantitative and qualitative) and PCArot for rotation. Includes various plots for visualizing results. ```R #PCAMIX: data(wine) pca<-PCAmix(X.quanti=wine[,c(3:29)],X.quali=wine[,1:2],ndim=4,graph=FALSE) pca rot<-PCArot(pca,3) rot rot$eig #percentages of variances after rotation plot(rot,choice="ind",coloring.ind=wine[,1], posleg="bottomleft", main="Rotated scores") plot(rot,choice="sqload",main="Squared loadings after rotation") plot(rot,choice="levels",main="Levels after rotation") plot(rot,choice="cor",main="Correlation circle after rotation") ``` -------------------------------- ### Build indicator matrix Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Creates an indicator matrix from a qualitative data matrix, handling NAs. ```R tab.disjonctif.NA(tab, rename.level = FALSE) ``` -------------------------------- ### Load and inspect housing data Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Loads the 'gironde' dataset and displays the first few rows of the 'housing' component. This is a prerequisite for applying PCAmix. ```r library(PCAmixdata) data(gironde) head(gironde$housing) ``` -------------------------------- ### MFAmix Data Preparation and Initial Plotting Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Prepares data for MFAmix by combining variables from different groups and then generates initial plots for correlation, partial axes, groups, squared loadings, and individuals. ```R data(gironde) class.var<-c(rep(1,9),rep(2,5),rep(3,9),rep(4,4)) names <- c("employment","housing","services","environment") dat <- cbind(gironde$employment[1:20,],gironde$housing[1:20,], gironde$services[1:20,],gironde$environment[1:20,]) res <- MFAmix(data=dat,groups=class.var, name.groups=names, rename.level=TRUE, ndim=3,graph=FALSE) #---- quantitative variables plot(res,choice="cor",cex=0.6) plot(res,choice="cor",cex=0.6,coloring.var="groups") plot(res,choice="cor",cex=0.6,coloring.var="groups", col.groups=c("red","yellow","pink","brown"),leg=TRUE) #----partial axes plot(res,choice="axes",cex=0.6) plot(res,choice="axes",cex=0.6,coloring.var="groups") plot(res,choice="axes",cex=0.6,coloring.var="groups", col.groups=c("red","yellow","pink","brown"),leg=TRUE) #----groups plot(res,choice="groups",cex=0.6) #no colors for groups plot(res,choice="groups",cex=0.6,coloring.var="groups") plot(res,choice="groups",cex=0.6,coloring.var="groups", col.groups=c("red","yellow","pink","blue")) #----squared loadings plot(res,choice="sqload",cex=0.8) #no colors for groups plot(res,choice="sqload",cex=0.8,coloring.var="groups", posleg="topright") plot(res,choice="sqload",cex=0.6,coloring.var="groups", col.groups=c("red","yellow","pink","blue"),ylim=c(0,1)) plot(res,choice="sqload",cex=0.8,coloring.var="type", cex.leg=0.9,posleg="topright") #----individuals plot(res,choice="ind",cex=0.6) #----individuals with squared cosine greater than 0.5 plot(res,choice="ind",cex=0.6,lim.cos2.plot=0.5) #----individuals colored with a qualitative variable nbchem <- gironde$services$chemist[1:20] plot(res,choice="ind",cex=0.6,coloring.ind=nbchem, posleg="topright") plot(res,choice="ind",coloring.ind=nbchem, col.ind=c("pink","brown","darkblue"),label=FALSE,posleg="topright") #----partial individuals colored by groups plot(res,choice="ind",partial=c("AUBIAC","ARCACHON"), cex=0.6,posleg="bottomright") #----levels of qualitative variables plot(res,choice="levels",cex=0.8) plot(res,choice="levels",cex=0.8,coloring.var="groups") #levels with squared cosine greater than 0.6 plot(res,choice="levels",cex=0.8, lim.cos2.plot=0.6) ``` -------------------------------- ### Summary for PCAmix Objects Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Provides a summary of a PCAmix object, returning the matrix of squared loadings. ```APIDOC ## S3 method for class 'PCAmix' summary(object, ...) ### Arguments `object` | an object of class PCAmix obtained with the function `PCAmix` or `PCArot`. `...` | further arguments passed to or from other methods. ### Value Returns the matrix of squared loadings. For quantitative variables (resp. qualitative), squared loadings are the squared correlations (resp. the correlation ratios) with the scores or with the rotated (standardized) scores. ### Examples ```R data(wine) X.quanti <- wine[,c(3:29)] X.quali <- wine[,c(1,2)] pca<-PCAmix(X.quanti,X.quali,ndim=4, graph=FALSE) summary(pca) rot<-PCArot(pca,3,graph=FALSE) summary(rot) ``` ``` -------------------------------- ### Load wine Dataset Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Loads the wine dataset containing 21 rows and 31 columns of sensory descriptors. ```R data(wine) ``` -------------------------------- ### Load vnf Dataset Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Loads the user satisfaction survey dataset containing 1232 observations and 14 qualitative variables. ```R data(vnf) ``` -------------------------------- ### Summarize PCAmix objects Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Provides a summary for objects of class PCAmix or PCArot, returning squared loadings. ```R ## S3 method for class 'PCAmix' summary(object, ...) ``` ```R data(wine) X.quanti <- wine[,c(3:29)] X.quali <- wine[,c(1,2)] pca<-PCAmix(X.quanti,X.quali,ndim=4, graph=FALSE) summary(pca) rot<-PCArot(pca,3,graph=FALSE) summary(rot) ``` -------------------------------- ### Load Flower Data Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Loads the flower dataset, which contains characteristics for 18 popular flowers. ```R data(flower) ``` -------------------------------- ### Inspect MFAmix results Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Checks the class and prints the summary of the MFAmix object. ```R class(res.mfamix) ``` ```R res.mfamix ``` -------------------------------- ### Summarize MFAmix objects Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Provides a summary for objects of class MFAmix. ```R ## S3 method for class 'MFAmix' summary(object, ...) ``` -------------------------------- ### MFAmix with Supplementary Variables and Plotting Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Demonstrates how to add supplementary variables to an MFAmix object and then plot various aspects of the supplemented analysis, including squared loadings, axes, groups, levels, and correlations. ```R #----supplementary groups data(wine) X.quanti <- splitmix(wine)$X.quanti[,1:5] X.quali <- splitmix(wine)$X.quali[,1,drop=FALSE] X.quanti.sup <- splitmix(wine)$X.quanti[,28:29] X.quali.sup <- splitmix(wine)$X.quali[,2,drop=FALSE] data <- cbind(X.quanti,X.quali) data.sup <- cbind(X.quanti.sup,X.quali.sup) groups <-c(1,2,2,3,3,1) name.groups <- c("G1","G2","G3") groups.sup <- c(1,1,2) name.groups.sup <- c("Gsup1","Gsup2") mfa <- MFAmix(data,groups,name.groups,ndim=4,rename.level=TRUE,graph=FALSE) mfa.sup <- supvar(mfa,data.sup,groups.sup,name.groups.sup,rename.level=TRUE) plot(mfa.sup,choice="sqload",coloring.var="groups") plot(mfa.sup,choice="axes",coloring.var="groups") plot(mfa.sup,choice="groups",coloring.var="groups") plot(mfa.sup,choice="levels",coloring.var="groups") plot(mfa.sup,choice="levels") plot(mfa.sup,choice="cor",coloring.var = "groups") ``` -------------------------------- ### Build Indicator Matrix Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Builds the indicator matrix for a qualitative data matrix, handling missing observations. ```APIDOC tab.disjonctif.NA(tab, rename.level = FALSE) ### Arguments `tab` | a categorical data matrix.. `rename.level` | boolean, if TRUE all the levels of the qualitative variables are renamed as follows: variable_name=level_name. ``` -------------------------------- ### wine Dataset Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Sensory descriptor data for 21 wines from the Val de Loire region. ```APIDOC ## wine ### Description Data referring to 21 wines of Val de Loire, including label of origin, soil type, and sensory descriptors. ### Format A data frame with 21 rows and 31 columns. ### Usage ``` data(wine) ``` ``` -------------------------------- ### Apply PCAmix to housing data Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Applies the PCAmix function to the housing data, splitting it into quantitative and qualitative variables. The results are stored in 'res.pcamix'. Set graph=FALSE to suppress graphical outputs during computation. ```r split <- splitmix(gironde$housing) X1 <- split$X.quanti X2 <- split$X.quali res.pcamix <- PCAmix(X.quanti=X1, X.quali=X2,rename.level=TRUE, graph=FALSE) ``` -------------------------------- ### Perform Multiple Factor Analysis with MFAmix Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Executes MFAmix on a combined dataset with specified group assignments and dimensions. Requires the gironde dataset to be loaded. ```R data(gironde) class.var<-c(rep(1,9),rep(2,5),rep(3,9),rep(4,4)) names <- c("employment","housing","services","environment") dat<-cbind(gironde$employment[1:20,],gironde$housing[1:20,], gironde$services[1:20,],gironde$environment[1:20,]) res<-MFAmix(data=dat,groups=class.var, name.groups=names, rename.level=TRUE, ndim=3,graph=FALSE) summary(res) ``` -------------------------------- ### Generate graphical outputs for PCAmix Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Generates various graphical outputs for the PCAmix analysis, including plots for individuals, levels of qualitative variables, correlations of quantitative variables, and squared loadings. Requires setting up the plotting area with par(mfrow=c(2,2)). ```r par(mfrow=c(2,2)) plot(res.pcamix,choice="ind",coloring.ind=X2$houses,label=FALSE, posleg="bottomright", main="Observations") plot(res.pcamix,choice="levels",xlim=c(-1.5,2.5), main="Levels") plot(res.pcamix,choice="cor",main="Numerical variables") plot(res.pcamix,choice="sqload",coloring.var=T, leg=TRUE, posleg="topright", main="All variables") ``` -------------------------------- ### Summary for MFAmix Objects Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Provides a summary of an MFAmix object, including counts of observations, variable types, and group-wise statistics. ```APIDOC ## S3 method for class 'MFAmix' summary(object, ...) ### Arguments `object` | an object of class MFAmix obtained with the function `MFAmix`. `...` | further arguments passed to or from other methods. ### Value Returns the total number of observations, the number of quantitative variables, the number of qualitative variables with the total number of levels. And all those values are also given by groups. ``` -------------------------------- ### Print PCAmix results Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Prints a summary of the PCAmix object 'res.pcamix', providing an overview of the analysis results including eigenvalues, and results for individuals, quantitative variables, qualitative variables, and loadings. ```r res.pcamix ``` -------------------------------- ### Prepare training data for PCAmix prediction Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Randomly selects 100 observations for a test sample and uses the remaining observations to train a PCAmix model. The model is built with ndim=2, meaning it will retain the first two principal components, and graph=FALSE suppresses graphical output. ```r set.seed(10) test <- sample(1:nrow(gironde$housing),100) train.pcamix <- PCAmix(X1[-test,],X2[-test,],ndim=2,graph=FALSE) ``` -------------------------------- ### Print Method for PCAmix Object Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html This is a print method for objects of the class PCAmix, generated by the PCAmix and PCArot functions. ```R ## S3 method for class 'PCAmix' print(x, ...) ``` -------------------------------- ### Perform Principal Component Analysis with PCAmix Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Analyzes a mixture of qualitative and quantitative variables using PCAmix. Parameters allow for weighting columns and renaming levels. ```R PCAmix(X.quanti = NULL, X.quali = NULL, ndim = 5, rename.level = FALSE, weight.col.quanti = NULL, weight.col.quali = NULL, graph = TRUE) ``` -------------------------------- ### PCAmix and PCArot with Decathlon Data Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Applies PCAmix and PCArot to decathlon performance data. Visualizes results using plots for individuals, squared loadings, and correlation circles. ```R #PCA: data(decathlon) quali<-decathlon[,13] pca<-PCAmix(decathlon[,1:10], graph=FALSE) rot<-PCArot(pca,3) plot(rot,choice="ind",coloring.ind=quali,cex=0.8, posleg="topright",main="Scores after rotation") plot(rot, choice="sqload", main="Squared correlations after rotation") plot(rot, choice="cor", main="Correlation circle after rotation") ``` -------------------------------- ### Plot PCAmix and PCArrot graphical outputs Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Visualizes observations and variables before and after rotation using standard maps. ```R par(mfrow=c(2,2)) plot(res.pcamix,choice="ind",label=FALSE,axes=c(1,3), main="Observations before rotation") plot(res.pcarot,choice="ind",label=FALSE,axes=c(1,3), main="Observations after rotation") plot(res.pcamix,choice="sqload", coloring.var=TRUE, leg=TRUE,axes=c(1,3), posleg="topleft", main="Variables before rotation", xlim=c(0,1), ylim=c(0,1)) plot(res.pcarot,choice="sqload", coloring.var=TRUE, leg=TRUE,axes=c(1,3), posleg="topright", main="Variables after rotation", xlim=c(0,1), ylim=c(0,1)) ``` ```R par(mfrow=c(2,2)) plot(res.pcamix,choice="cor", coloring.var=TRUE, leg=TRUE,axes=c(1,3), posleg="topright", main="Before rotation") plot(res.pcarot,choice="cor", coloring.var=TRUE, leg=TRUE,axes=c(1,3), posleg="topright", main="After rotation") plot(res.pcamix,choice="levels", leg=TRUE,axes=c(1,3), posleg="topright", main="Before rotation",xlim=c(-1.5,2.5)) plot(res.pcarot,choice="levels", leg=TRUE,axes=c(1,3), posleg="topright", main="After rotation",xlim=c(-1.5,2.5)) ``` -------------------------------- ### Print Method for MFAmix Object Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html This is a print method for objects of the class MFAmix, generated by the MFAmix function. ```R ## S3 method for class 'MFAmix' print(x, ...) ``` -------------------------------- ### PCAmix Output Structure Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Details the structure and content of the output generated by the PCAmix function. ```APIDOC ## PCAmix Output Structure ### Description This section describes the components of the object returned by the `MFAmix` function (which is of class `PCAmix`). ### Value - `eig`: A matrix containing eigenvalues, percentages of variance, and cumulative percentages of variance. - `ind`: A list containing results for individuals: - `$coord`: Factor coordinates (scores) of the individuals. - `$contrib`: Absolute contributions of the individuals. - `$contrib.pct`: Relative contributions of the individuals. - `$cos2`: Squared cosinus of the individuals. - `quanti`: A list containing results for quantitative variables: - `$coord`: Factor coordinates (scores) of the quantitative variables. - `$contrib`: Absolute contributions of the quantitative variables. - `$contrib.pct`: Relative contributions of the quantitative variables (in percentage). - `$cos2`: Squared cosinus of the quantitative variables. - `levels`: A list containing results for the levels of qualitative variables: - `$coord`: Factor coordinates (scores) of the levels. - `$contrib`: Absolute contributions of the levels. - `$contrib.pct`: Relative contributions of the levels (in percentage). - `$cos2`: Squared cosinus of the levels. - `quali`: A list containing results for qualitative variables: - `$contrib`: Absolute contributions of the qualitative variables (sum of absolute contributions of the levels). - `$contrib.pct`: Relative contributions (in percentage) of the qualitative variables (sum of relative contributions of the levels). - `sqload`: A matrix of dimension (`p`, `ndim`) containing the squared loadings of the quantitative and qualitative variables. - `coef`: The coefficients of the linear combinations used to construct the principal components and predict scores for new observations. - `eig.separate`: A matrix containing the `ndim` first eigenvalues of the separated analyses of each group. - `separate.analyses`: The results for the separated analyses of each group. - `groups`: A list containing results for the groups: - `$Lg`: Lg coefficients between groups. - `$RV`: RV coefficients between groups. - `$contrib`: Contributions of the groups (sum of variable contributions belonging to the group). - `$contrib.pct`: Relative contributions of the groups (times 100). - `partial.axes`: A matrix containing the coordinates of the partial axes. - `ind.partial`: A list of `G` matrices containing the coordinates of the partial individuals. - `listvar.group`: Lists the variables in each group. - `global.pca`: An object of class `PCAmix` containing the results of `MFAmix` considered as a unique `PCAmix`. ### Method None ### Endpoint None ### Parameters None ### Request Example None ### Response None ``` -------------------------------- ### splitmix Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Splits a mixed data matrix into two datasets: one for quantitative variables and one for qualitative variables. ```APIDOC ## splitmix ### Description Splits a mixed data matrix in two data sets: one with the quantitative variables and one with the qualitative variables. Columns of class "integer" are considered quantitative. If you want an integer column to be considered qualitative, it must be of class character or factor. ### Usage ``` splitmix(data) ``` ### Arguments - `data` (data matrix or data.frame) - A data matrix or data.frame with a mixture of quantitative and qualitative variables. ### Value - `X.quanti` (data matrix) - A data matrix containing only the quantitative variables. - `X.quali` (data.frame) - A data.frame containing only the qualitative variables. ### Examples ```R data(decathlon) data.split <- splitmix(decathlon) data.split$X.quanti data.split$X.quali ``` ``` -------------------------------- ### Print PCAmix Object Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Prints an object of the class PCAmix, which is generated by the PCAmix and PCArot functions. ```APIDOC ## print(x, ...) ### Description This is a method for the function print for objects of the class `PCAmix`. ### Arguments - **x** (object of class PCAmix) - an object of class `PCAmix` generated by the functions `PCAmix` and `PCArot`. - **...** (further arguments) - further arguments to be passed to or from other methods. They are ignored in this function. ``` -------------------------------- ### Print MFAmix Object Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Prints an object of the class MFAmix, which is generated by the MFAmix function. ```APIDOC ## print(x, ...) ### Description This is a method for the function print for objects of the class `MFAmix`. ### Arguments - **x** (object of class MFAmix) - an object of class `MFAmix` generated by the function `PCAmix`. - **...** (further arguments) - further arguments to be passed to or from other methods. They are ignored in this function. ### See Also `MFAmix` ``` -------------------------------- ### splitgroups Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Splits a data matrix into multiple datasets based on group membership of variables. ```APIDOC ## splitgroups ### Description If the p variables of a data matrix of dimension (n,p) are separated into G groups, this function splits this data matrix into `G` datasets according the groups membership. ### Usage ``` splitgroups(data, groups, name.groups) ``` ### Arguments - `data` (data matrix) - The data matrix with `n` rows and `p` columns. - `groups` (vector) - A vector of size `p` indicating the group membership for each variable. - `name.groups` (vector) - A vector of size `G` containing names for each group, in increasing order of group numbers. ### Value - `data.groups` (list) - A list of G data matrices, one for each group. - `listvar.groups` (list) - The list of variables in each group. ### Examples ```R data(decathlon) split <- splitgroups(decathlon, groups = c(rep(1, 10), 2, 2, 3), name.groups = c("Epreuve", "Classement", "Competition")) split$data.groups$Epreuve ``` ``` -------------------------------- ### Handle supplementary groups in MFAmix with a single group Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/supplementary.html Demonstrates adding supplementary information when the model contains a single group structure. ```R #devtools::install_github("chavent/PCAmixdata") library(PCAmixdata) data(wine) X.quanti <- splitmix(wine)$X.quanti[,1:5] X.quali <- splitmix(wine)$X.quali[,1,drop=FALSE] X.quali.sup <- splitmix(wine)$X.quali[,2,drop=FALSE] data <- cbind(X.quanti,X.quali) groups <-c(1,1,1,2,2,2) name.groups <- c("G1","G2") mfa <- MFAmix(data,groups,name.groups,ndim=4,rename.level=TRUE,graph=FALSE) groups.sup <- c(1) name.groups.sup <- "Gsup1" mfa.sup <- supvar(mfa,X.quali.sup,groups.sup,name.groups.sup,rename.level=TRUE) plot(mfa.sup,choice="levels",coloring.var = "groups") ``` ```R groups.sup <- c(1,1,2) name.groups.sup <- c("Gsup1","Gsup2") mfa.sup <- supvar(mfa,data.sup,groups.sup,name.groups.sup,rename.level=TRUE) plot(mfa.sup,choice="sqload",coloring.var="groups") ``` ```R plot(mfa.sup,choice="axes",coloring.var="groups") ``` ```R plot(mfa.sup,choice="groups",coloring.var="groups") ``` ```R plot(mfa.sup,choice="levels",coloring.var="groups") ``` ```R plot(mfa.sup,choice="levels") ``` ```R plot(mfa.sup,choice="cor",coloring.var = "groups") ``` -------------------------------- ### Load Decathlon Data Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Loads the decathlon dataset, which contains performance data for athletes in two sporting events. ```R data(decathlon) ``` -------------------------------- ### Predict Function for PCAmix (Mixed Data) Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Demonstrates using the predict function with mixed (quantitative and qualitative) data. It involves splitting data, fitting PCAmix, predicting scores, and plotting results. ```R # quantitative and qualitative data data(wine) str(wine) X.quanti <- splitmix(wine)$X.quanti X.quali <- splitmix(wine)$X.quali pca<-PCAmix(X.quanti[,1:27],X.quali,ndim=4,graph=FALSE) n <- nrow(wine) sub <- sample(1:n,10) pca<-PCAmix(X.quanti[sub,1:27],X.quali[sub,],ndim=4) pred <- predict(pca,X.quanti[-sub,1:27],X.quali[-sub,]) plot(pca,axes=c(1,2)) points(pred[,c(1,2)],col=2,pch=16) text(pred[,c(1,2)], labels = rownames(X.quanti[-sub,1:27]), col=2,pos=3) ``` -------------------------------- ### vnf Dataset Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html User satisfaction survey data of pleasure craft operators on the Canal des Deux Mers. ```APIDOC ## vnf ### Description A user satisfaction survey of 1232 individuals regarding pleasure craft operators on the Canal des Deux Mers, managed by Voies Navigables de France. ### Format A data frame with 1232 observations and 14 qualitative variables. ### Usage ``` data(vnf) ``` ``` -------------------------------- ### recodquant Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Recodes a quantitative data matrix by standardizing it and calculating column means and standard deviations. ```APIDOC ## recodquant ### Description Recoding of the quantitative data matrix. ### Usage ``` recodquant(X) ``` ### Arguments - `X` (data matrix) - The quantitative data matrix. ### Value - `Z` (matrix) - The standardized quantitative data matrix (centered and reduced by standard deviations). - `g` (numeric vector) - The means of the columns of X. - `s` (numeric vector) - The standard deviations of the columns of X (population version with 1/n). - `Xcod` (matrix) - The quantitative matrix X with missing values replaced with the column mean values. ### Examples ```R data(decathlon) X <- decathlon[1:5, 1:5] X[1, 2] <- NA X[2, 3] <- NA rec <- recodquant(X) ``` ``` -------------------------------- ### Plot Supplementary Variables with PCAmix Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Use the `supvar` method to calculate and plot coordinates for supplementary numerical and categorical variables on a PCAmix correlation circle. Ensure the PCAmix object and supplementary data are correctly prepared. ```R ?supvar.PCAmix ``` ```R X1sup <- gironde$environment[,1,drop=FALSE] X2sup <- gironde$services[,7,drop=FALSE] res.sup <- supvar(res.pcamix,X1sup,X2sup,rename.level=TRUE) res.sup$quanti.sup$coord[,1:2,drop=FALSE] ``` ```R res.sup$levels.sup$coord[,1:2] ``` ```R ?plot.PCAmix ``` ```R #par(mfrow=c(2,1)) plot(res.sup,choice="cor",main="Numerical variables") ``` ```R plot(res.sup,choice="levels",main="Levels",xlim=c(-2,2.5)) ``` -------------------------------- ### Perform Multiple Factor Analysis with MFAmix Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Use this function to analyze datasets where observations are described by multiple groups of mixed quantitative and qualitative variables. ```R MFAmix(data, groups, name.groups, ndim=5, rename.level=FALSE, graph = TRUE, axes = c(1, 2)) ``` -------------------------------- ### Predicting and Plotting New Observations Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Predicts the coordinates of a new observation (municipality) in the MFAmix analysis and plots it as an illustrative point on the existing map. Requires the original data and the MFAmix result object. ```R sel <- which(rownames(dat)=="SAINTE-FOY-LA-GRANDE") res.mfamix<- MFAmix(data=dat[-sel,],groups=index, name.groups=names,rename.level=TRUE,graph=FALSE) pred <- predict(res.mfamix,dat[sel,,drop=FALSE]) pred[,1:2,drop=FALSE] ``` ```R plot(res.mfamix,axes=c(1,2),label=FALSE,main="Observations map", ylim=c(-5,1.5),cex=0.8) points(pred[,1:2,drop=FALSE],col=2,pch=16) text(pred,"SAINTE-FOY-LA-GRANDE",col=2,cex=0.7,pos=2) selplot <- which(res.mfamix$ind$coord[,1]>4.2) text(res.mfamix$ind$coord[selplot,1:2],rownames(dat[-sel,])[selplot],col=1,cex=0.7,pos=2) legend("topright",legend = c("active","illustrative"),fill=1:2,col=1:2) ``` -------------------------------- ### S3 method for class 'PCAmix' plot Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Displays the graphical outputs of PCAmix and PCArot, plotting individuals, quantitative variables, and levels of qualitative variables. ```APIDOC ## S3 method for class 'PCAmix' plot ### Description Displays the graphical outputs of PCAmix and PCArot. The individuals (observations), the quantitative variables and the levels of the qualitative variables are plotted as points using their factor coordinates (scores). All the variables (quantitative and qualitative) are plotted as points on the same graph using their squared loadings. ### Parameters #### Arguments - **x** (PCAmix) - Required - An object of class PCAmix. - **axes** (vector) - Optional - A length 2 vector specifying the components to plot. - **choice** (string) - Optional - The type of graph to plot: 'ind', 'cor', 'sqload', 'axes', 'groups', or 'levels'. - **label** (boolean) - Optional - Whether to label the points. - **coloring.ind** (vector) - Optional - A vector for coloring individuals. - **col.ind** (vector) - Optional - Colors for individuals. - **coloring.var** (boolean/string) - Optional - Whether to color variables by groups or type. - **lim.cos2.plot** (numeric) - Optional - Threshold for squared cosine to filter points. - **lim.contrib.plot** (numeric) - Optional - Threshold for contribution to filter points. - **posleg** (string) - Optional - Position of the legend. - **xlim** (vector) - Optional - Limits for the x-axis. - **ylim** (vector) - Optional - Limits for the y-axis. - **cex** (numeric) - Optional - Character expansion factor. - **leg** (boolean) - Optional - Whether to display the legend. - **main** (string) - Optional - Main title of the plot. - **cex.leg** (numeric) - Optional - Character expansion for the legend. ``` -------------------------------- ### Project supplementary variables in PCAmix Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Calculates coordinates of supplementary variables for PCAmix objects. ```R ## S3 method for class 'PCAmix' supvar(obj, X.quanti.sup = NULL, X.quali.sup = NULL, rename.level = FALSE, ...) ``` ```R data(wine) X.quanti <- splitmix(wine)$X.quanti[,1:5] X.quali <- splitmix(wine)$X.quali[,1,drop=FALSE] X.quanti.sup <-splitmix(wine)$X.quanti[,28:29] X.quali.sup <-splitmix(wine)$X.quali[,2,drop=FALSE] pca<-PCAmix(X.quanti,X.quali,ndim=4,graph=FALSE) pcasup <- supvar(pca,X.quanti.sup,X.quali.sup) ``` -------------------------------- ### recodqual Source: https://cran.r-project.org/web/packages/PCAmixdata/refman/PCAmixdata.html Recodes a qualitative data matrix into an indicator matrix. ```APIDOC ## recodqual ### Description Recoding of the qualitative data matrix. ### Usage ``` recodqual(X, rename.level = FALSE) ``` ### Arguments - `X` (data matrix) - The qualitative data matrix. - `rename.level` (boolean) - If TRUE, all levels of qualitative variables are renamed as follows: "variable_name=level_name". ### Value - `G` (matrix) - The indicator matrix of X with missing values replaced by 0. ### Examples ```R data(vnf) X <- vnf[1:10, 9:12] tab.disjonctif.NA(X) recodqual(X) ``` ``` -------------------------------- ### Extract eigenvalues from PCAmix results Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Retrieves and displays the eigenvalues of the principal components from the 'res.pcamix' object. This includes the eigenvalue, proportion of variance explained, and cumulative proportion for each dimension. ```r res.pcamix$eig ``` -------------------------------- ### Add supplementary variables and groups in MFAmix Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/supplementary.html Incorporate supplementary data into an MFAmix model using supvar. ```R data(wine) X.quanti <- splitmix(wine)$X.quanti[,1:5] X.quali <- splitmix(wine)$X.quali[,1,drop=FALSE] X.quanti.sup <- splitmix(wine)$X.quanti[,28:29] X.quali.sup <- splitmix(wine)$X.quali[,2,drop=FALSE] data <- cbind(X.quanti,X.quali) data.sup <- cbind(X.quanti.sup,X.quali.sup) groups <-c(1,2,2,3,3,1) name.groups <- c("G1","G2","G3") mfa <- MFAmix(data,groups,name.groups,ndim=4,rename.level=TRUE,graph=FALSE) groups.sup <- c(1,1,2) name.groups.sup <- c("Gsup1","Gsup2") mfa.sup <- supvar(mfa,data.sup,groups.sup,name.groups.sup,rename.level=TRUE) plot(mfa.sup,choice="sqload",coloring.var="groups") ``` ```R plot(mfa.sup,choice="axes",coloring.var="groups") ``` ```R plot(mfa.sup,choice="groups",coloring.var="groups") ``` ```R plot(mfa.sup,choice="levels",coloring.var="groups") ``` ```R plot(mfa.sup,choice="levels") ``` ```R plot(mfa.sup,choice="cor",coloring.var = "groups") ``` -------------------------------- ### Plotting Supplementary Groups Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Applies MFAmix with active groups and adds a supplementary group ('housing'). The supplementary group can then be plotted on the maps generated by MFAmix, allowing for comparison with the active groups. ```R dat <- cbind(gironde$employment,gironde$services,gironde$environment) names <- c("employment","services","environment") mfa <-MFAmix(data=dat,groups=c(rep(1,9),rep(2,9),rep(3,4)), name.groups=names, rename.level=TRUE,graph=FALSE) mfa.sup <- supvar(mfa,data.sup=gironde$housing, groups.sup=rep(1,5), name.groups.sup="housing.sup",rename.level=TRUE) ``` ```R #par(mfrow=c(1,2)) plot(mfa.sup,choice="groups",coloring.var="groups") ``` ```R plot(mfa.sup,choice="cor",coloring.var = "groups") ``` -------------------------------- ### Plotting MFAmix Graphical Outputs Source: https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html Generates various graphical outputs for MFAmix objects, including correlation circles, individual factor maps, and variable factor maps. Use the 'choice' argument to select the desired plot type. ```R ?plot.MFAmix par(mfrow=c(2,2)) plot(res.mfamix, choice="cor",coloring.var="groups",leg=TRUE, main="(a) Numerical variables") plot(res.mfamix,choice="ind", partial=c("SAINTE-FOY-LA-GRANDE"), label=TRUE, posleg="topright", main="(b) Observations") plot(res.mfamix,choice="sqload",coloring.var="groups", posleg="topright",main="(c) All variables") plot(res.mfamix, choice="groups", coloring.var="groups", main="(c) Groups") ``` ```R plot(res.mfamix, choice="levels", coloring.var="groups", posleg="bottomleft", main="(c) Levels",xlim=c(-2,4)) ```