Multiple-mediation example with lavaan

This post extends this previous one on multiple-mediation with lavaan. Here I modeled a ‘real’ dataset instead of a randomly generated one. This dataset we used previously for a paper published some time ago. There we investigated whether fear of an imperfect fat self was a stronger mediator than hope of a perfect thin self on dietary restraint in college women. At the time of the paper’s publication we performed the analysis using the SPSS macro INDIRECT . However,
Continue reading “Multiple-mediation example with lavaan”

Advertisements
Multiple-mediation example with lavaan

Multiple-mediator analysis with lavaan

I wrote this brief introductory post for my friend Simon. I want to show how easy the transition from SPSS to R can be. In the specific case of mediation analysis the transition to R can be very smooth because, thanks to lavaan, the R knowledge required to use the package is minimal. Analysis of mediator effects in lavaan requires only the specification of the model, all the other processes are automated by the package. So, after reading in the data, running the test is trivial.
Continue reading “Multiple-mediator analysis with lavaan”

Multiple-mediator analysis with lavaan

Streamgraphs in base::R [e.II]

Until recently I did not have a practical application in which to use streamgraphs. In fact, I still find the visualisation complex to understand, abstract and a bit too artistic. While I recognise that the strength of streamgraphs is the display of all the time series’ values into one (possibly interactive) plot, the amount of data displayed is massive, with many streams and even more data points. Because of the amount of data displayed Continue reading “Streamgraphs in base::R [e.II]”

Streamgraphs in base::R [e.II]

Streamgraphs in base::R [e.I]

This is the first of a series of four post on producing a streamgraph in plain R code. Here I present a very simple R script plotting a streamgraph. In this post I made streamgraph in d3.js, but I wanted to be able to do the same in R, to not depend on a webpage, or without requiring additional libraries (e.g. the streamgraph htmlwidgtet is only a wrapper around d3, and does not work always smoothly).
Continue reading “Streamgraphs in base::R [e.I]”

Streamgraphs in base::R [e.I]

Citations Network

This post describes the visualisation of a social network I made for a Coursera course on Data Visualisation. For this specific assignment I opted for gathering data on my own rather than using the datasets provided by the course instructor. I wanted to gather the data myself to try to visualise ‘real’ data. With real data I mean data that I try to scrape from the web and visualise. Basically with ‘real’ data I mean what other people call dirty data (i.e. data that is not been processed or polished before use). The question was also whether I could Continue reading “Citations Network”

Citations Network

Color-coded parallel coordinates in R

Parallel coordinates can be very helpful in understanding relationships among more than two variables. The first time I encountered parallel coordinates I did not understand their potential, until I saw Alberto Cairo’s slopegraph. In that slopegraph Cairo color-coded the Continue reading “Color-coded parallel coordinates in R”

Color-coded parallel coordinates in R

Custom colormap for image() in R

Creating a custom colormap in R to plot a matrix is simple:

nsamples <- 20
matrix2plot <- 1:nsamples
dim(matrix2plot) <- c(4, 5)
colors2spaceThrough <- c('red', 'white', 'blue')
customColorMap <- colorRampPalette(colors2spaceThrough)(nsamples)
image(1:4, 1:5, matrix2plot, col = customColorMap)

Continue reading “Custom colormap for image() in R”

Custom colormap for image() in R