# install.packages("ResIN")
library(ggplot2)
library(ResIN)
Welcome to the ResIN R-Package vignette. Here we’ll showcase and comment on some of the features available in the ResIN package.
Let’s first simulate a slightly noisy dataset of 8 Likert-scale items for 1000 hypothetical respondents:
set.seed(42)
<- 1000
n <- 8
k
<- rnorm(1000, 0, 1)
latent_dgp
## Data for k manifest indicators measured with some error
<- matrix(rep(latent_dgp, k), n, k)
cont_data <- apply(cont_data, 2, function(x) {
cont_data + rnorm(1000, 0, 0.2)}) ## 20% error
x
## Ordinal, 5-point Likert-scale items
<- function(x) {
lik_maker sort(runif(x, min = -2, max = 2))}
<- matrix(NA, n, k)
lik_data
for(i in 1:ncol(lik_data)) {
<- findInterval(cont_data[, i], vec = c(-Inf, lik_maker(4), Inf))
lik_data[, i] }
The first argument supplied to the function is simply the data-frame containing all (survey) items we would like to include in the analysis. Here, we also chose the correlation method that calculates the item-pair associations and specified that we’d like to estimate network descriptive statistics. All this can be done in one line of code.
# Apply the ResIN function to toy Likert data:
<- ResIN(lik_data, cor_method = "spearman", network_stats = TRUE) output
We can now freely investigate the ResIN output. Let’s make use of the convenient, ggplot-ready edge-list stored in the output to visualize the result. Because we want to take advantage of our network statistics, we first re-order the ggplot dataframe
# Create a basic outcome plot with ggplot
$ggplot_frame <- output$ggplot_frame[order(output$ggplot_frame$Strength,
outputdecreasing = FALSE), ]
<- ggplot2::ggplot(output$ggplot_frame) +
ResIN_plot geom_curve(data = output$ggplot_frame, aes(x = from.x, xend = to.x, y = from.y,
yend = to.y, linewidth = weight,
color = Strength), curvature = 0.2) +
geom_point(aes(x = from.x, y = from.y, shape = as.factor(cluster)), size = 8)+
geom_point(aes(x = to.x, y = to.y), size = 8)+
geom_text(data = output$ggplot_frame, aes(x = from.x, y = from.y, label = from),
size = 3, color = "white") +
geom_text(data = output$ggplot_frame, aes(x = to.x, y = to.y, label = to),
size = 3, color = "white") +
ggtitle("ResIN example plot")+
theme_dark()+
theme(axis.text.x = element_blank(), axis.title.x = element_blank(),
axis.text.y = element_blank(), axis.title.y = element_blank(),
axis.ticks = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), legend.position = "none",
legend.text = element_blank(), plot.title = element_text(hjust = 0.5))
ResIN_plot