Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. set.seed(12326)
  2.  
  3. ### number of studies
  4. n <- 40
  5.  
  6. ### simulate explanatory variable
  7. xi <- round(runif(n, 1, 10), 1)
  8.  
  9. ### simulate sampling variances
  10. vi <- rgamma(n, 2, 2)/20
  11.  
  12. ### simulate estimates (quadratic relationship + residual heterogeneity + sampling error)
  13. yi <- 0.5 + 0.3 * xi - 0.03 * xi^2 + rnorm(n, 0, 0.1) + rnorm(n, 0, sqrt(vi))
  14.  
  15. library(metafor)
  16.  
  17. res <- rma(yi, vi, mods = ~ xi + I(xi^2))
  18. res
  19.  
  20. Mixed-Effects Model (k = 40; tau^2 estimator: REML)
  21.  
  22. tau^2 (estimated amount of residual heterogeneity): 0.0234 (SE = 0.0135)
  23. tau (square root of estimated tau^2 value): 0.1530
  24. I^2 (residual heterogeneity / unaccounted variability): 43.17%
  25. H^2 (unaccounted variability / sampling variability): 1.76
  26. R^2 (amount of heterogeneity accounted for): 69.27%
  27.  
  28. Test for Residual Heterogeneity:
  29. QE(df = 37) = 61.0438, p-val = 0.0077
  30.  
  31. Test of Moderators (coefficient(s) 2,3):
  32. QM(df = 2) = 37.5033, p-val < .0001
  33.  
  34. Model Results:
  35.  
  36. estimate se zval pval ci.lb ci.ub
  37. intrcpt 0.2655 0.2024 1.3119 0.1896 -0.1311 0.6621
  38. xi 0.4073 0.0834 4.8824 <.0001 0.2438 0.5708 ***
  39. I(xi^2) -0.0402 0.0073 -5.4753 <.0001 -0.0546 -0.0258 ***
  40.  
  41. ---
  42. Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  43.  
  44. plot(xi, yi, pch=19, cex=.2/sqrt(vi), xlim=c(1,10), ylim=c(0,2))
  45. xi.new <- seq(1,10,length=100)
  46. pred <- predict(res, newmods = cbind(xi.new, xi.new^2))
  47. lines(xi.new, pred$pred)
  48. lines(xi.new, pred$ci.lb, lty="dashed", col="gray")
  49. lines(xi.new, pred$ci.ub, lty="dashed", col="gray")
  50. points(xi, yi, pch=19, cex=.2/sqrt(vi))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement