[R] Structuring data for Correspondence Analysis

Michael Friendly |r|end|y @end|ng |rom yorku@c@
Sat Mar 30 16:51:40 CET 2019


I think something like table(Preference, Sex, data=table) will get you 
started. With 3+ variables, you are probably looking for a MCA analysis
or simple CA using the stacked approach.

Your SAS table statement,

table Preference, Sex Age Time;

treats Preference vs. all combinations of Sex, Age & Time.  This 
corresponds to a loglinear model asserting Preference is jointly
independent of the other three.

See the vignette for the vcdExtra package for this kind of thing more 
generally.

install.packages("vcdExtra")
browseVignettes("vcdExtra")

See my book, Discrete Data Analysis with R, http://ddar.datavis.ca/

best,
-Michael

On 3/29/2019 9:35 AM, Alfredo wrote:
> Hi, I am very new to r and need help from you to do a correspondence
> analysis because I don't know how to structure the following data:
> 
> Thank you.
> 
> Alfredo
> 
>   
> 
> library(ca,lib.loc=folder)
> 
> table <- read.csv(file="C:\\Temp\\Survey_Data.csv", header=TRUE, sep=",")
> 
> head (table, n=20)
> 
>                  Preference   Sex        Age   Time
> 
> 1           News/Info/Talk     M      25-30  06-09
> 
> 2                Classical     F      >35    09-12
> 
> 3          Rock and Top 40     F      21-25  12-13
> 
> 4                     Jazz     M      >35    13-16
> 
> 5           News/Info/Talk     F      25-30  16-18
> 
> 6             Don't listen     F      30-35  18-20
> 
> ...
> 
> 19         Rock and Top 40     M      25-30  16-18
> 
> 20          Easy Listening     F      >35    18-20
> 
>   
> 
> In SAS I would simply do this:
> 
> proc corresp data=table dim=2 outc=_coord;
> 
>     table Preference, Sex Age Time;
> 
> run;
> 
>   
> 
> I don't know how convert in R a data frame to a frequency table to execute
> properly this function:
> 
> ca <- ca(<frequency table>, graph=FALSE)
> 
> 
> 	[[alternative HTML version deleted]]
> 


-- 
Michael Friendly     Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, ASA Statistical Graphics Section
York University      Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele Street    Web:   http://www.datavis.ca  |  @datavisFriendly
Toronto, ONT  M3J 1P3 CANADA



More information about the R-help mailing list