Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. message("\n")
  2. message("############################################")
  3. message("# Mediation analysis example #")
  4. message("############################################")
  5. message("\n")
  6.  
  7. message(" + Import packages\n")
  8. library('mediation')
  9. # For sobel filter:
  10. library('multilevel')
  11.  
  12. message("\n + Read the data")
  13. data = read.csv('ExamAnxiety.csv')
  14.  
  15. message("\n + Calculate the results")
  16. outcome = with(data, sobel(pred=Revise, med=Anxiety, out=Exam))
  17.  
  18. message("\n + Overview of the analysis")
  19. outcome[1:3]
  20.  
  21. message("\n + Get coefficients")
  22. a <- outcome$`Mod3: M~X`[2,1]; b <- outcome$`Mod2: Y~X+M`[3,1]
  23. sa <- outcome$`Mod3: M~X`[2,2]; sb <- outcome$`Mod2: Y~X+M`[3,2]
  24.  
  25. message("\n + Z Aroian")
  26. (z.aroian <- (a*b)/sqrt(b^2*sa^2 + a^2*sb^2 + sa^2 * sb^2))
  27.  
  28. message("\n + Aroian p-value")
  29. round(2*(1-pnorm(z.aroian)),5)
  30.  
  31. message("\n + Mediation percentage")
  32. (VAF <- outcome$Indirect.Effect/outcome$`Mod1: Y~X`[2,1])
  33.  
  34. message("\n + outcome$Indirect.Effect")
  35. outcome$Indirect.Effect
  36. message("\n + outcome$SE")
  37. outcome$SE
  38. message("\n + outcome$z.value")
  39. outcome$z.value
  40. message("\n + outcome$N")
  41. outcome$N
  42.  
  43. message("\n\np-value from the from CDF of the normal distribution")
  44. round(2*(1-pnorm(outcome$z.value)),5)
  45.  
  46. message("\n")
  47. message("############################################")
  48. message("# End of Mediation analysis example #")
  49. message("############################################")
  50. message("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement