Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. library(tidyverse)
  2. library(latex2exp)
  3. library(patchwork)
  4. library(animation)
  5.  
  6. (
  7. ggplot(data.frame(x = 0:30), aes(x = x)) +
  8. stat_function(
  9. fun = dnorm,
  10. args = list(mean = 30, sd = 4),
  11. geom = "density",
  12. size = 1,
  13. fill = "gray20",
  14. alpha = 0.5,
  15. linetype = 0
  16. ) +
  17. stat_function(
  18. fun = dnorm,
  19. args = list(mean = 20, sd = 4),
  20. geom = "density",
  21. size = 1,
  22. xlim = c(0, 30 + 4 * qnorm(0.05 / 2)),
  23. fill = "darkred",
  24. linetype = 0
  25. ) +
  26. stat_function(
  27. fun = dnorm,
  28. args = list(mean = 30, sd = 4),
  29. geom = "density",
  30. size = 1,
  31. xlim = c(0, 30 + 4 * qnorm(0.05 / 2)),
  32. fill = "steelblue",
  33. linetype = 0
  34. ) +
  35. stat_function(
  36. fun = dnorm,
  37. args = list(mean = 30, sd = 4),
  38. geom = "density",
  39. size = 1,
  40. xlim = c(0, 30 + 4 * qnorm(0.0176 / 2)),
  41. fill = "deeppink",
  42. linetype = 0
  43. ) +
  44. # stat_function(fun = dnorm, args = list(mean = 30, sd = 4), geom = "col", width = 0.08, xlim = c(0, 30 + 4* qnorm(0.0176/2)), fill = "deeppink", linetype = 2) +
  45. stat_function(
  46. fun = dnorm,
  47. args = list(mean = 30, sd = 4),
  48. geom = "density",
  49. size = 1,
  50. xlim = c(30 - 4 * qnorm(0.05 / 2), 60),
  51. fill = "steelblue",
  52. linetype = 0
  53. ) +
  54. stat_function(
  55. fun = dnorm,
  56. args = list(mean = 30, sd = 4),
  57. geom = "density",
  58. size = 1,
  59. xlim = c(30 - 4 * qnorm(0.0176 / 2), 60),
  60. fill = "deeppink",
  61. linetype = 0
  62. ) +
  63. # stat_function(fun = dnorm, args = list(mean = 30, sd = 4), geom = "col",width = 0.08, xlim = c( 30 - 4* qnorm(0.0176/2),60), fill = "deeppink", linetype =\ 2) +
  64. stat_function(
  65. fun = dnorm,
  66. args = list(mean = 20, sd = 4),
  67. geom = "density",
  68. size = 1,
  69. linetype = 0
  70. ) +
  71. stat_function(
  72. fun = dnorm,
  73. args = list(mean = 20, sd = 4),
  74. geom = "density",
  75. size = 1,
  76. xlim = c(30 + 4 * qnorm(0.05 / 2), 60),
  77. fill = "orange",
  78. linetype = 0
  79. ) +
  80. annotate(
  81. "text",
  82. 25,
  83. 0.02,
  84. label = parse(text = TeX("$\\beta$")),
  85. size = 13,
  86. col = "white"
  87. ) +
  88. annotate(
  89. "text",
  90. 17,
  91. 0.02,
  92. label = parse(text = TeX("$1-\\beta$")),
  93. size = 13,
  94. col = "white"
  95. ) +
  96. annotate(
  97. "text",
  98. 21.5,
  99. 0.005,
  100. label = parse(text = TeX("$\\frac{\\alpha}{2}$")),
  101. size = 8,
  102. col = "white"
  103. ) +
  104. annotate(
  105. "text",
  106. 38.5,
  107. 0.005,
  108. label = parse(text = TeX("$\\frac{\\alpha}{2}$")),
  109. size = 8,
  110. col = "white"
  111. ) +
  112. geom_segment(
  113. aes(
  114. x = 21,
  115. y = 0.1,
  116. xend = 29,
  117. yend = 0.1
  118. ),
  119. arrow = arrow(length = unit(0.01, "npc")),
  120. size = 1
  121. ) +
  122. geom_segment(
  123. aes(
  124. xend = 21,
  125. yend = 0.1,
  126. x = 29,
  127. y = 0.1
  128. ),
  129. arrow = arrow(length = unit(0.01, "npc")),
  130. size = 1
  131. ) +
  132. theme_void()
  133. ) %>%
  134. ggsave("frequentialhypothesistesting.png",., width = 16, height = 9)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement