Skip to content
analyse_data.R 1.43 KiB
Newer Older
Maike Kleemeyer's avatar
Maike Kleemeyer committed
# COMPUTE sum scores and means for A2, A3, B1, B2, C1, D1, D2, E1, E2, G1, G5, G7
# Run Factor analysis on all likert scale items 



## OLD R CODE
setwd("~/Seafile/FragebogenMpg")
file1 = read.csv("20200106_MPG Work Culture_Basic Data_likert.csv",header=TRUE,sep=";")

library(psych)
library(umx)
library(ggplot2)
library(Hmisc)

file1$H1_gender <- as.factor(file1$H1_gender)

scale_a <- subset(file1, select = A2_groupatmo1_1:A3_groupatmo4_3)

umxEFA(file1, factors = 19, scores= "ML")

print(class(file1[[i]]))

for (i in colnames(file1)){
  p <- ggplot(file1, aes(x=c("all"), 
                         y=file1[[i]])) 
  + geom_violin(trim=FALSE)
  
  data_summary <- function(x) {
    m <- mean(x)
    ymin <- m-sd(x)
    ymax <- max(x)
    return(c(y=m,ymin=ymin,ymax=ymax))
  }
  p + stat_summary(fun.data=data_summary)
  
  p <- ggplot(file1, aes(x=file1$H1_gender, 
                         y=file1[[i]], fill=file1$H1_gender)) 
  + geom_violin(trim=FALSE)
  
  data_summary <- function(x) {
    m <- mean(x)
    ymin <- m-sd(x)
    ymax <- max(x)
    return(c(y=m,ymin=ymin,ymax=ymax))
  }
  p + stat_summary(fun.data=data_summary)
  
  p <- ggplot(file1, aes(x=file1$H1_gender, 
                         y=file1[[i]], fill=file1$startlanguage)) 
  + geom_violin(trim=FALSE)
  data_summary <- function(x) {
    m <- mean(x)
    ymin <- m-sd(x)
    ymax <- max(x)
    return(c(y=m,ymin=ymin,ymax=ymax))
  }
  p + stat_summary(fun.data=data_summary)
  
}