Advertisement
Teunis

R-stuff

Dec 30th, 2021 (edited)
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 3.81 KB | None | 0 0
  1. # 1. OLP-Functions
  2. source(file.choose())
  3.  
  4. # 2. Packages
  5. library(car)
  6. library(moments)
  7. library(ggplot2)    
  8. library(GGally)    
  9. library(scatterplot3d)
  10. library(effects)    
  11. library(lavaan)    
  12. library(semPlot)    
  13. library(Rcpp)
  14. library(lme4)      
  15. library(lmerTest)  
  16. library(sjPlot)
  17. library(lattice)
  18.  
  19. options(scipen=999)
  20.  
  21. # 3. Dataset
  22. load(file.choose()) # Rdata
  23.  
  24. #renaming variables
  25. Montenegro$Thuisvoelen<-(Montenegro$ASBGSSB)
  26. mean(Montenegro$Thuisvoelen, na.rm=T)
  27. sd(Montenegro$Thuisvoelen, na.rm=T)
  28.  
  29. Montenegro$Geslacht<-(Montenegro$ASBG01)  
  30. Montenegro$Thuistaal<-(Montenegro$ASBG03)  
  31. Montenegro$Leermiddelen_thuis<-(Montenegro$ASBGHRL)  
  32. Montenegro$Gepest_voelen<-(Montenegro$ASBGSB)  
  33.  
  34. #recoding variables
  35. Montenegro$Gepest_voelenR <-(Montenegro$Gepest_voelen)*-1
  36. Montenegro$Gepest_voelen
  37. Montenegro$Gepest_voelenR
  38.  
  39. #z-score
  40. Montenegro$Leermiddelen_thuisZ <- zscore(Montenegro$Leermiddelen_thuis)  
  41. Montenegro$Gepest_voelenRZ <- zscore(Montenegro$Gepest_voelenR)  
  42. Montenegro$Gepest_voelenZ <- zscore(Montenegro$Gepest_voelen)  
  43. Montenegro$ThuisvoelenZ <- zscore(Montenegro$ASBGSSB)
  44.  
  45. #categorical variables > dummyvariables
  46. Montenegro$Meisje<-(Montenegro$Geslacht=="1")*1  
  47. Montenegro$Jongen<-(Montenegro$Geslacht=="2")*1  
  48. Montenegro$Instructietaal_Zelfde <- (Montenegro$Thuistaal=="1" | Montenegro$Thuistaal=="2" )*1  
  49. Montenegro$Instructietaal_Andere <- (Montenegro$Thuistaal=="3" | Montenegro$Thuistaal=="4")*1
  50.  
  51. ## So far so good
  52. Montenegro_Model2C0 <- lmer(ThuisvoelenZ ~ 1 + (1|IDSCHOOL) + (1|IDCLASS), data = Montenegro, REML = F)  
  53. summary(Montenegro_Model2C0)  
  54.  
  55. Montenegro_Model2C1 <- lmer(ThuisvoelenZ ~ 1 + Gepest_voelenRZ + (1 + Gepest_voelenRZ|IDSCHOOL) + (1|IDCLASS), data = Montenegro, REML = F)  
  56. summary(Montenegro_Model2C1)
  57.  
  58. ## Here, things start to go wrong...
  59. Montenegro_Model2C2 <- lmer(ThuisvoelenZ ~ 1 + Gepest_voelenRZ + Instructietaal_Andere + (1 + Gepest_voelenRZ|IDSCHOOL) + (1 + Instructietaal_Andere|IDSCHOOL) + (1|IDCLASS), data = Montenegro, REML = F)
  60. summary(Montenegro_Model2C2)
  61.  
  62. Montenegro_Model2C3 <- lmer(ThuisvoelenZ ~ 1 + Gepest_voelenRZ + Instructietaal_Andere + Leermiddelen_thuisZ + (1 + Gepest_voelenRZ|IDSCHOOL) + (1 + Instructietaal_Andere|IDSCHOOL) + (1 + Leermiddelen_thuisZ|IDSCHOOL) + (1|IDCLASS), data = Montenegro, REML = F)
  63. summary(Montenegro_Model2C3)  
  64.  
  65. Montenegro_Model2C4 <- lmer(ThuisvoelenZ ~ 1 + Gepest_voelenRZ + Instructietaal_Andere + Leermiddelen_thuisZ + Meisje + (1 + Gepest_voelenRZ|IDSCHOOL) + (1 + Instructietaal_Andere|IDSCHOOL) + (1 + Leermiddelen_thuisZ|IDSCHOOL) + (1|IDCLASS), data = Montenegro, REML = F)
  66. summary(Montenegro_Model2C4)  
  67.  
  68. Montenegro_NA<-na.omit(Montenegro[c("IDSCHOOL","IDCLASS","ThuisvoelenZ", "Meisje", "Instructietaal_Andere", "Instructietaal_Zelfde", "Gepest_voelenRZ" , "Leermiddelen_thuisZ")])  
  69. Montenegro_Model2C0NA <- lmer(ThuisvoelenZ ~ 1 + (1|IDSCHOOL) + (1|IDCLASS), data = Montenegro_NA, REML = F)  
  70. Montenegro_Model2c1NA <- lmer(ThuisvoelenZ ~ 1 + Gepest_voelenRZ + (1 + Gepest_voelenRZ|IDSCHOOL) + (1|IDCLASS), data = Montenegro_NA, REML = F)  
  71. Montenegro_Model2C2NA <- lmer(ThuisvoelenZ ~ 1 + Gepest_voelenRZ + Instructietaal_Andere + (1 + Instructietaal_Andere|IDSCHOOL) + (1 + Gepest_voelenRZ|IDSCHOOL) + (1|IDCLASS), data = Montenegro_NA, REML = F)  
  72. Montenegro_Model2C3NA <- lmer(ThuisvoelenZ ~ 1 + Gepest_voelenRZ + Instructietaal_Andere + Leermiddelen_thuisZ + (1 + Gepest_voelenRZ|IDSCHOOL) + (1 + Instructietaal_Andere|IDSCHOOL) + (1 + Leermiddelen_thuisZ|IDSCHOOL) + (1|IDCLASS), data = Montenegro_NA, REML = F)  
  73. Montenegro_Model2C4NA <- lmer(ThuisvoelenZ ~ 1 + Gepest_voelenRZ + Instructietaal_Andere + Leermiddelen_thuisZ + Meisje + (1 + Gepest_voelenRZ|IDSCHOOL) + (1 + Instructietaal_Andere|IDSCHOOL) + (1 + Leermiddelen_thuisZ|IDSCHOOL) + (1|IDCLASS), data = Montenegro_NA, REML = F)  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement