Abstract
You will get a list of servers. Select a server that is close to your country.
You have full access to this open access chapter, Download chapter PDF
Similar content being viewed by others
Download and install R on your computer.
FormalPara Task 2:Install the necessary packages.
-
a)
Install the vcd package
> install.packages()
You will get a list of servers. Select a server that is close to your country.
You will get a list of available packages. Select vcd.
The installation process starts.
Activate the vcd package from the console: > library(vcd)
-
b)
Install the FactoMineR package
> install.packages()
You will get a list of servers. Select a server that is close to your country.
You will get a list of available packages. Select FactoMineR.
The installation process starts.
Activate the FactoMineR package from the console: > library(FactoMineR)
Beware: R considers upper and lower case letters to be different symbols.
Get some data. We will create a table with some fictional data.
> a <- matrix(c(100,50,100,50,100,200,100,200,25,50,75,100), nrow=4,dimnames=list(c("A","B","C","D"),c("positive","negative","neutral")))
> a
Positive | Negative | Neutral | |
---|---|---|---|
A | 100 | 100 | 25 |
B | 50 | 200 | 50 |
C | 100 | 100 | 75 |
D | 50 | 200 | 100 |
The data is entered column by column, from first to last row. The variable a is assigned the result. If you need to switch the rows and columns you can do so with the transpose command (t).
> t(a)
A | B | C | D | |
---|---|---|---|---|
Positive | 100 | 50 | 100 | 50 |
Negative | 100 | 200 | 100 | 200 |
Neutral | 25 | 50 | 75 | 100 |
Now you have some data. The first we do is to create association tables with “assoc” from the vcd package.
> assoc(a, shade=T)
The parameter shade=T asks the function to color code how significant each cell is.
You may also transpose rows and columns, using the function t().
> assoc(t(a), shade=T)
The red bars mark cells that contain frequencies that are lower than expected. The blue bars mark cells that have higher frequencies than expected. The height of the bars is proportional to significance and the width of the bars is proportional to the support (how much data note that “negative” has a wider base where the frequencies are higher) (Fig. 1).
The graphs allow us to look for associations between rows and columns, and see if the association is higher or lower than expected if rows and columns were statistically independent.
The second function we will investigate is Correspondence Analysis. The input to this function is also a matrix, just like the association graphs. It is often good to use both association graphs and CA graphs. We simply call the CA function, after we have activated the package FactoMineR.
> CA(a)
> CA(t(a))
You will see part of the analysis is text, and a graph that can be saved is also presented.
The CA graph calculates a coordinate system with the dimensions that best explain the variance in the data set. It is a nice way to present very complicated datasets with many different variables. The way to read the graph is to look at the extreme points, most distant from the origin. These points span up the dimensions. We further need to look at the line from each point to the origin. For example, B and negative are highly associated, both because they are close in the space and they have a similar angle toward the origin. We can also see this directly from the data, the value on negative for B is 200, which is much higher than the values for positive or neutral. The real usefulness of CA comes when you have large tables or matrices, with many rows (items) and columns (typically descriptors). Such data is very difficult to grasp, but in the CA graph you can see the structure (Fig. 2).
Find your own data sets, and see if association and correspondence will help you understand and present the structure in your data.
Further Reading
Visualizing Categorical Data and Association Graphs
Cohen, A. (1980). On the graphical display of the significant components in a two-way contingency table. Communications in Statistics-Theory and Methods, A9, 1025–1041. https://doi.org/10.1080/03610928008827940
Friendly, M. (1992). Graphical methods for categorical data. In SAS User Group International Conference Proceedings, 17, 190–200. http://preview.tinyurl.com/h29ffha
Meyer, D., Zeileis, A., & Hornik, K. (2021). vcd: Visualizing Categorical Data. R package version 1.4-9.
Correspondence Analysis
Glynn, D. (2014). Correspondence analysis: Exploring data and identifying patterns. In D. Glynn & J. A. Robinson (Eds.), Corpus methods for semantics: Quantitative studies in polysemy and synonymy (pp. 443–485). John Benjamins Publishing Company. http://digital.casalini.it/9789027270337
Lê, S., Josse, J., & Husson, F. (2008). FactoMineR: An R package for multivariate analysis. Journal of Statistical Software, 25(1), 1–18. https://doi.org/10.18637/jss.v025.i01
R
R Core Team. (2015). R: A language and environment for statistical computing. In R Foundation for Statistical Computing (Vienna, Austria). https://www.R-project.org/
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.
The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.
Copyright information
© 2024 The Author(s)
About this chapter
Cite this chapter
Johansson, C., Folgerø, P.O. (2024). Unit 4 Lab: Create Your Own Association Graphs and Correspondence Analysis Using R. In: Balinisteanu, T., Priest, K. (eds) Neuroaesthetics. Palgrave Macmillan, Cham. https://doi.org/10.1007/978-3-031-42323-9_13
Download citation
DOI: https://doi.org/10.1007/978-3-031-42323-9_13
Published:
Publisher Name: Palgrave Macmillan, Cham
Print ISBN: 978-3-031-42325-3
Online ISBN: 978-3-031-42323-9
eBook Packages: Behavioral Science and PsychologyBehavioral Science and Psychology (R0)