rsquaredacademy / vistributions

@@ -48,15 +48,19 @@
Loading
48 48
49 49
  gplot <-
50 50
    ggplot(plot_data) +
51 -
    geom_line(aes(x = x, y = y), color = 'blue') +
52 -
    ggtitle(label = 't Distribution', subtitle = paste("df =", df)) +
53 -
    xlab('') + ylab('') +
54 -
    geom_polygon(data = poly_data, mapping = aes(x = y, y = z),
55 -
      fill = '#4682B4') +
51 +
    geom_line(aes(x = x, y = y),
52 +
              color = 'blue') +
53 +
    ggtitle(label    = 't Distribution',
54 +
            subtitle = paste("df =", df)) +
55 +
    xlab('') +
56 +
    ylab('') +
57 +
    geom_polygon(data    = poly_data,
58 +
                 mapping = aes(x = y, y = z),
59 +
                 fill    = '#4682B4') +
56 60
    scale_y_continuous(breaks = NULL) +
57 61
    scale_x_continuous(breaks = -4:4) +
58 -
    theme(plot.title = element_text(hjust = 0.5),
59 -
                   plot.subtitle = element_text(hjust = 0.5))
62 +
    theme(plot.title    = element_text(hjust = 0.5),
63 +
          plot.subtitle = element_text(hjust = 0.5))
60 64
61 65
  if (print_plot) {
62 66
    print(gplot)
@@ -69,9 +73,7 @@
Loading
69 73
#' @rdname vdist_t
70 74
#' @export
71 75
#'
72 -
vdist_t_perc <- function(probs = 0.95, df = 4,
73 -
                         type = c("lower", "upper", "both"),
74 -
                         print_plot = TRUE) {
76 +
vdist_t_perc <- function(probs = 0.95, df = 4, type = c("lower", "upper", "both"), print_plot = TRUE) {
75 77
76 78
  check_numeric(probs, "probs")
77 79
  check_numeric(df, "df")
@@ -109,55 +111,80 @@
Loading
109 111
110 112
  gplot <-
111 113
    ggplot(plot_data) +
112 -
    geom_line(aes(x = x, y = y), color = 'blue') +
113 -
    xlab(paste("df =", df)) + ylab('') +
114 -
    theme(plot.title = element_text(hjust = 0.5),
115 -
                   plot.subtitle = element_text(hjust = 0.5))
114 +
    geom_line(aes(x = x, y = y),
115 +
              color = 'blue') +
116 +
    xlab(paste("df =", df)) +
117 +
    ylab('') +
118 +
    theme(plot.title    = element_text(hjust = 0.5),
119 +
          plot.subtitle = element_text(hjust = 0.5))
116 120
117 121
  if (method == "lower") {
118 122
    gplot <-
119 123
      gplot +
120 -
      ggtitle(label = "t Distribution",
121 -
        subtitle = paste0("P(X < ", pp, ") = ", probs * 100, "%")) +
122 -
      annotate("text", label = paste0(probs * 100, "%"),
123 -
        x = pp - 0.3, y = max(dt(l, df)) + 0.025, color = "#0000CD",
124 -
        size = 3) +
125 -
      annotate("text", label = paste0((1 - probs) * 100, "%"),
126 -
        x = pp + 0.3, y = max(dt(l, df)) + 0.025, color = "#6495ED",
127 -
        size = 3)
124 +
      ggtitle(label    = "t Distribution",
125 +
              subtitle = paste0("P(X < ", pp, ") = ", probs * 100, "%")) +
126 +
      annotate("text",
127 +
               label = paste0(probs * 100, "%"),
128 +
               x     = pp - 0.3,
129 +
               y     = max(dt(l, df)) + 0.025,
130 +
               color = "#0000CD",
131 +
               size  = 3) +
132 +
      annotate("text",
133 +
               label = paste0((1 - probs) * 100, "%"),
134 +
               x     = pp + 0.3,
135 +
               y     = max(dt(l, df)) + 0.025,
136 +
               color = "#6495ED",
137 +
               size  = 3)
128 138
129 139
  } else if (method == "upper") {
130 140
    gplot <-
131 141
      gplot +
132 -
      ggtitle(label = "t Distribution",
133 -
        subtitle = paste0("P(X > ", pp, ") = ", probs * 100, "%")) +
134 -
      annotate("text", label = paste0((1 - probs) * 100, "%"),
135 -
        x = pp - 0.3, y = max(dt(l, df)) + 0.025, color = "#6495ED",
136 -
        size = 3) +
137 -
      annotate("text", label = paste0(probs * 100, "%"),
138 -
        x = pp + 0.3, y = max(dt(l, df)) + 0.025, color = "#0000CD",
139 -
        size = 3)
142 +
      ggtitle(label    = "t Distribution",
143 +
              subtitle = paste0("P(X > ", pp, ") = ", probs * 100, "%")) +
144 +
      annotate("text",
145 +
               label = paste0((1 - probs) * 100, "%"),
146 +
               x     = pp - 0.3,
147 +
               y     = max(dt(l, df)) + 0.025,
148 +
               color = "#6495ED",
149 +
               size  = 3) +
150 +
      annotate("text",
151 +
               label = paste0(probs * 100, "%"),
152 +
               x     = pp + 0.3,
153 +
               y     = max(dt(l, df)) + 0.025,
154 +
               color = "#0000CD",
155 +
               size  = 3)
140 156
  } else {
141 157
    gplot <-
142 158
      gplot +
143 -
      ggtitle(label = "t Distribution",
144 -
        subtitle = paste0("P(", pp[1], " < X < ", pp[2], ") = ", probs * 100, "%")) +
145 -
      annotate("text", label = paste0(probs * 100, "%"),
146 -
        x = mean(l), y = max(dt(l, df)) + 0.025, color = "#0000CD",
147 -
        size = 3) +
148 -
      annotate("text", label = paste0(alpha * 100, "%"),
149 -
        x = pp[1] - 0.3, y = max(dt(l, df)) + 0.025, color = "#6495ED",
150 -
        size = 3) +
151 -
      annotate("text", label = paste0(alpha * 100, "%"),
152 -
        x = pp[2] + 0.3, y = max(dt(l, df)) + 0.025, color = "#6495ED",
153 -
        size = 3)
159 +
      ggtitle(label    = "t Distribution",
160 +
              subtitle = paste0("P(", pp[1], " < X < ", pp[2], ") = ", probs * 100, "%")) +
161 +
      annotate("text",
162 +
               label = paste0(probs * 100, "%"),
163 +
               x     = mean(l),
164 +
               y     = max(dt(l, df)) + 0.025,
165 +
               color = "#0000CD",
166 +
               size  = 3) +
167 +
      annotate("text",
168 +
               label = paste0(alpha * 100, "%"),
169 +
               x     = pp[1] - 0.3,
170 +
               y     = max(dt(l, df)) + 0.025,
171 +
               color = "#6495ED",
172 +
               size  = 3) +
173 +
      annotate("text",
174 +
               label = paste0(alpha * 100, "%"),
175 +
               x     = pp[2] + 0.3,
176 +
               y     = max(dt(l, df)) + 0.025,
177 +
               color = "#6495ED",
178 +
               size  = 3)
154 179
  }
155 180
156 181
  for (i in seq_len(length(l1))) {
157 182
    poly_data <- vdist_pol_t(lc[l1[i]], lc[l2[i]], df)
158 183
    gplot <-
159 184
      gplot +
160 -
      geom_polygon(data = poly_data, mapping = aes(x = x, y = y), fill = col[i])
185 +
      geom_polygon(data    = poly_data,
186 +
                   mapping = aes(x = x, y = y),
187 +
                   fill    = col[i])
161 188
  }
162 189
163 190
  pln <- length(pp)
@@ -168,9 +195,14 @@
Loading
168 195
169 196
    gplot <-
170 197
      gplot +
171 -
      geom_vline(xintercept = pp[i], linetype = 2, size = 1) +
172 -
      geom_point(data = point_data, mapping = aes(x = x, y = y),
173 -
      shape = 4, color = 'red', size = 3)
198 +
      geom_vline(xintercept = pp[i],
199 +
                 linetype   = 2,
200 +
                 size       = 1) +
201 +
      geom_point(data    = point_data,
202 +
                 mapping = aes(x = x, y = y),
203 +
                 shape   = 4,
204 +
                 color   = 'red',
205 +
                 size    = 3)
174 206
  }
175 207
176 208
  gplot <-
@@ -189,9 +221,7 @@
Loading
189 221
#' @rdname vdist_t
190 222
#' @export
191 223
#'
192 -
vdist_t_prob <- function(perc = 1.6, df = 7,
193 -
                         type = c("lower", "upper", "interval", "both"),
194 -
                         print_plot = TRUE) {
224 +
vdist_t_prob <- function(perc = 1.6, df = 7, type = c("lower", "upper", "interval", "both"), print_plot = TRUE) {
195 225
196 226
  check_numeric(perc, "perc")
197 227
  check_numeric(df, "df")
@@ -249,10 +279,12 @@
Loading
249 279
250 280
  gplot <-
251 281
    ggplot(plot_data) +
252 -
    geom_line(aes(x = x, y = y), color = 'blue') +
253 -
    xlab(paste("df =", df)) + ylab('') +
254 -
    theme(plot.title = element_text(hjust = 0.5),
255 -
                   plot.subtitle = element_text(hjust = 0.5)) +
282 +
    geom_line(aes(x = x, y = y),
283 +
              color = 'blue') +
284 +
    xlab(paste("df =", df)) +
285 +
    ylab('') +
286 +
    theme(plot.title    = element_text(hjust = 0.5),
287 +
          plot.subtitle = element_text(hjust = 0.5)) +
256 288
    scale_x_continuous(breaks = min(l):max(l)) +
257 289
    scale_y_continuous(breaks = NULL)
258 290
@@ -260,7 +292,9 @@
Loading
260 292
    poly_data <- vdist_pol_t(lc[l1[i]], lc[l2[i]], df)
261 293
    gplot <-
262 294
      gplot +
263 -
      geom_polygon(data = poly_data, mapping = aes(x = x, y = y), fill = col[i])
295 +
      geom_polygon(data    = poly_data,
296 +
                   mapping = aes(x = x, y = y),
297 +
                   fill    = col[i])
264 298
  }
265 299
266 300
@@ -270,17 +304,28 @@
Loading
270 304
271 305
    gplot <-
272 306
      gplot +
273 -
      ggtitle(label = "t Distribution",
274 -
        subtitle = paste0("P(X < ", perc, ") = ", pp * 100, "%")) +
275 -
      annotate("text", label = paste0(pp * 100, "%"),
276 -
        x = perc - 1, y = max(dt(l, df)) + 0.07, color = "#0000CD",
277 -
        size = 3) +
278 -
      annotate("text", label = paste0((1 - pp) * 100, "%"),
279 -
        x = perc + 1, y = max(dt(l, df)) + 0.07, color = "#6495ED",
280 -
        size = 3) +
281 -
      geom_vline(xintercept = perc, linetype = 2, size = 1) +
282 -
      geom_point(data = point_data, mapping = aes(x = x, y = y),
283 -
      shape = 4, color = 'red', size = 3)
307 +
      ggtitle(label    = "t Distribution",
308 +
              subtitle = paste0("P(X < ", perc, ") = ", pp * 100, "%")) +
309 +
      annotate("text",
310 +
               label = paste0(pp * 100, "%"),
311 +
               x     = perc - 1,
312 +
               y     = max(dt(l, df)) + 0.07,
313 +
               color = "#0000CD",
314 +
               size  = 3) +
315 +
      annotate("text",
316 +
               label = paste0((1 - pp) * 100, "%"),
317 +
               x     = perc + 1,
318 +
               y     = max(dt(l, df)) + 0.07,
319 +
               color = "#6495ED",
320 +
               size  = 3) +
321 +
      geom_vline(xintercept = perc,
322 +
                 linetype   = 2,
323 +
                 size       = 1) +
324 +
      geom_point(data    = point_data,
325 +
                 mapping = aes(x = x, y = y),
326 +
                 shape   = 4,
327 +
                 color   = 'red',
328 +
                 size    = 3)
284 329
285 330
  } else if (method == "upper") {
286 331
@@ -288,17 +333,28 @@
Loading
288 333
289 334
    gplot <-
290 335
      gplot +
291 -
      ggtitle(label = "t Distribution",
292 -
        subtitle = paste0("P(X > ", perc, ") = ", pp * 100, "%")) +
293 -
      annotate("text", label = paste0((1 - pp) * 100, "%"),
294 -
        x = perc - 1, y = max(dt(l, df)) + 0.07, color = "#0000CD",
295 -
        size = 3) +
296 -
      annotate("text", label = paste0(pp * 100, "%"),
297 -
        x = perc + 1, y = max(dt(l, df)) + 0.07, color = "#6495ED",
298 -
        size = 3) +
299 -
      geom_vline(xintercept = perc, linetype = 2, size = 1) +
300 -
      geom_point(data = point_data, mapping = aes(x = x, y = y),
301 -
      shape = 4, color = 'red', size = 3)
336 +
      ggtitle(label    = "t Distribution",
337 +
              subtitle = paste0("P(X > ", perc, ") = ", pp * 100, "%")) +
338 +
      annotate("text",
339 +
               label = paste0((1 - pp) * 100, "%"),
340 +
               x     = perc - 1,
341 +
               y     = max(dt(l, df)) + 0.07,
342 +
               color = "#0000CD",
343 +
               size  = 3) +
344 +
      annotate("text",
345 +
               label = paste0(pp * 100, "%"),
346 +
               x     = perc + 1,
347 +
               y     = max(dt(l, df)) + 0.07,
348 +
               color = "#6495ED",
349 +
               size  = 3) +
350 +
      geom_vline(xintercept = perc,
351 +
                 linetype   = 2,
352 +
                 size       = 1) +
353 +
      geom_point(data    = point_data,
354 +
                 mapping = aes(x = x, y = y),
355 +
                 shape   = 4,
356 +
                 color   = 'red',
357 +
                 size    = 3)
302 358
303 359
  } else if (method == "interval") {
304 360
@@ -306,44 +362,84 @@
Loading
306 362
307 363
    gplot <-
308 364
      gplot +
309 -
      ggtitle(label = "t Distribution",
310 -
        subtitle = paste0("P(", -perc, " < X < ", perc, ") = ", (1 - (pp1 + pp2)) * 100, "%")) +
311 -
      annotate("text", label = paste0((1 - (pp1 + pp2)) * 100, "%"),
312 -
        x = 0, y = max(dt(l, df)) + 0.07, color = "#0000CD", size = 3) +
313 -
      annotate("text", label = paste0(pp[1] * 100, "%"),
314 -
        x = perc + 1, y = max(dt(l, df)) + 0.07, color = "#6495ED",
315 -
        size = 3) +
316 -
      annotate("text", label = paste0(pp[2] * 100, "%"),
317 -
        x = -perc - 1, y = max(dt(l, df)) + 0.07, color = "#6495ED",
318 -
        size = 3) +
319 -
      geom_vline(xintercept = perc, linetype = 2, size = 1) +
320 -
      geom_vline(xintercept = -perc, linetype = 2, size = 1) +
321 -
      geom_point(data = point_data, mapping = aes(x = x1, y = y),
322 -
      shape = 4, color = 'red', size = 3) +
323 -
      geom_point(data = point_data, mapping = aes(x = x2, y = y),
324 -
      shape = 4, color = 'red', size = 3)
365 +
      ggtitle(label    = "t Distribution",
366 +
              subtitle = paste0("P(", -perc, " < X < ", perc, ") = ", (1 - (pp1 + pp2)) * 100, "%")) +
367 +
      annotate("text",
368 +
               label = paste0((1 - (pp1 + pp2)) * 100, "%"),
369 +
               x     = 0,
370 +
               y     = max(dt(l, df)) + 0.07,
371 +
               color = "#0000CD",
372 +
               size  = 3) +
373 +
      annotate("text",
374 +
               label = paste0(pp[1] * 100, "%"),
375 +
               x     = perc + 1,
376 +
               y     = max(dt(l, df)) + 0.07,
377 +
               color = "#6495ED",
378 +
               size  = 3) +
379 +
      annotate("text",
380 +
               label = paste0(pp[2] * 100, "%"),
381 +
               x     = -perc - 1,
382 +
               y     = max(dt(l, df)) + 0.07,
383 +
               color = "#6495ED",
384 +
               size  = 3) +
385 +
      geom_vline(xintercept = perc,
386 +
                 linetype   = 2,
387 +
                 size       = 1) +
388 +
      geom_vline(xintercept = -perc,
389 +
                 linetype   = 2,
390 +
                 size       = 1) +
391 +
      geom_point(data    = point_data,
392 +
                 mapping = aes(x = x1, y = y),
393 +
                 shape   = 4,
394 +
                 color   = 'red',
395 +
                 size    = 3) +
396 +
      geom_point(data    = point_data,
397 +
                 mapping = aes(x = x2, y = y),
398 +
                 shape   = 4,
399 +
                 color   = 'red',
400 +
                 size    = 3)
325 401
  } else {
326 402
327 403
    point_data <- data.frame(x1 = perc, x2 = -perc, y = 0)
328 404
329 405
    gplot <-
330 406
      gplot +
331 -
      ggtitle(label = "t Distribution",
332 -
        subtitle = paste0("P(|X| > ", perc, ") = ", (pp1 + pp2) * 100, "%")) +
333 -
      annotate("text", label = paste0((1 - (pp1 + pp2)) * 100, "%"),
334 -
        x = 0, y = max(dt(l, df)) + 0.07, color = "#0000CD", size = 3) +
335 -
      annotate("text", label = paste0(pp[1] * 100, "%"),
336 -
        x = perc + 1, y = max(dt(l, df)) + 0.07, color = "#6495ED",
337 -
        size = 3) +
338 -
      annotate("text", label = paste0(pp[2] * 100, "%"),
339 -
        x = -perc - 1, y = max(dt(l, df)) + 0.07, color = "#6495ED",
340 -
        size = 3) +
341 -
      geom_vline(xintercept = perc, linetype = 2, size = 1) +
342 -
      geom_vline(xintercept = -perc, linetype = 2, size = 1) +
343 -
      geom_point(data = point_data, mapping = aes(x = x1, y = y),
344 -
      shape = 4, color = 'red', size = 3) +
345 -
      geom_point(data = point_data, mapping = aes(x = x2, y = y),
346 -
      shape = 4, color = 'red', size = 3)
407 +
      ggtitle(label    = "t Distribution",
408 +
              subtitle = paste0("P(|X| > ", perc, ") = ", (pp1 + pp2) * 100, "%")) +
409 +
      annotate("text",
410 +
               label = paste0((1 - (pp1 + pp2)) * 100, "%"),
411 +
               x     = 0,
412 +
               y     = max(dt(l, df)) + 0.07,
413 +
               color = "#0000CD",
414 +
               size  = 3) +
415 +
      annotate("text",
416 +
               label = paste0(pp[1] * 100, "%"),
417 +
               x     = perc + 1,
418 +
               y     = max(dt(l, df)) + 0.07,
419 +
               color = "#6495ED",
420 +
               size  = 3) +
421 +
      annotate("text",
422 +
               label = paste0(pp[2] * 100, "%"),
423 +
               x     = -perc - 1,
424 +
               y     = max(dt(l, df)) + 0.07,
425 +
               color = "#6495ED",
426 +
               size  = 3) +
427 +
      geom_vline(xintercept = perc,
428 +
                 linetype   = 2,
429 +
                 size       = 1) +
430 +
      geom_vline(xintercept = -perc,
431 +
                 linetype   = 2,
432 +
                 size       = 1) +
433 +
      geom_point(data    = point_data,
434 +
                 mapping = aes(x = x1, y = y),
435 +
                 shape   = 4,
436 +
                 color   = 'red',
437 +
                 size    = 3) +
438 +
      geom_point(data    = point_data,
439 +
                 mapping = aes(x = x2, y = y),
440 +
                 shape   = 4,
441 +
                 color   = 'red',
442 +
                 size    = 3)
347 443
  }
348 444
349 445
  if (print_plot) {

@@ -45,31 +45,44 @@
Loading
45 45
  nx     <- seq(-2, 4, 0.01)
46 46
47 47
  plot_data  <- data.frame(x = x, y = df(x, num_df, den_df))
48 -
  poly_data  <- data.frame(y = c(0, seq(0, 4, 0.01), 4),
49 -
    z = c(0, df(seq(0, 4, 0.01), num_df, den_df), 0))
50 48
  point_data <- data.frame(x = fm, y = 0)
51 49
  nline_data <- data.frame(x = nx, y = dnorm(nx, fm, fsd))
52 50
51 +
  poly_data  <- data.frame(y = c(0, seq(0, 4, 0.01), 4),
52 +
                           z = c(0,
53 +
                                 df(seq(0, 4, 0.01),
54 +
                                    num_df,
55 +
                                    den_df),
56 +
                                 0))
57 +
58 +
53 59
  gplot <-
54 60
    ggplot(plot_data) +
55 -
    geom_line(aes(x = x, y = y), color = "blue") +
56 -
    geom_polygon(data = poly_data, mapping = aes(x = y, y = z),
57 -
      fill = '#4682B4') +
58 -
    geom_point(data = point_data, mapping = aes(x = x, y = y),
59 -
      shape = 4, color = 'red', size = 3) +
60 -
    xlab(paste("Mean =", fm, " Std Dev. =", fsd)) + ylab('') +
61 -
    ggtitle(label = 'f Distribution',
62 -
      subtitle = paste("Num df =", num_df, "  Den df =", den_df)) +
63 -
    theme(plot.title = element_text(hjust = 0.5),
64 -
                   plot.subtitle = element_text(hjust = 0.5)) +
61 +
    geom_line(aes(x = x, y = y),
62 +
              color = "blue") +
63 +
    geom_polygon(data    = poly_data,
64 +
                 mapping = aes(x = y, y = z),
65 +
                 fill    = '#4682B4') +
66 +
    geom_point(data    = point_data,
67 +
               mapping = aes(x = x, y = y),
68 +
               shape   = 4,
69 +
               color   = 'red',
70 +
               size    = 3) +
71 +
    xlab(paste("Mean =", fm, " Std Dev. =", fsd)) +
72 +
    ylab('') +
73 +
    ggtitle(label    = 'f Distribution',
74 +
            subtitle = paste("Num df =", num_df, "  Den df =", den_df)) +
75 +
    theme(plot.title    = element_text(hjust = 0.5),
76 +
          plot.subtitle = element_text(hjust = 0.5)) +
65 77
    scale_x_continuous(breaks = c(-2:4)) +
66 78
    scale_y_continuous(breaks = NULL)
67 79
68 80
  if (normal) {
69 81
    gplot <-
70 82
      gplot +
71 -
      geom_line(data = nline_data, mapping = aes(x = x, y = y),
72 -
        color = '#FF4500')
83 +
      geom_line(data    = nline_data,
84 +
                mapping = aes(x = x, y = y),
85 +
                color   = '#FF4500')
73 86
  }
74 87
75 88
  if (print_plot) {
@@ -117,44 +130,59 @@
Loading
117 130
118 131
  gplot <-
119 132
    ggplot(plot_data) +
120 -
    geom_line(data = plot_data, mapping = aes(x = x, y = y),
121 -
      color = 'blue') + xlab(paste("Mean =", fm, " Std Dev. =", fsd)) +
133 +
    geom_line(data    = plot_data,
134 +
              mapping = aes(x = x, y = y),
135 +
              color   = 'blue') +
136 +
    xlab(paste("Mean =", fm, " Std Dev. =", fsd)) +
122 137
    ylab('') +
123 -
    theme(plot.title = element_text(hjust = 0.5),
124 -
                   plot.subtitle = element_text(hjust = 0.5))
138 +
    theme(plot.title    = element_text(hjust = 0.5),
139 +
          plot.subtitle = element_text(hjust = 0.5))
125 140
126 141
127 142
  if (method == "lower") {
128 143
    gplot <-
129 144
      gplot +
130 -
      ggtitle(label = 'f Distribution',
131 -
        subtitle = paste0("P(X < ", pp, ") = ", probs * 100, "%")) +
132 -
      annotate("text", label = paste0(probs * 100, "%"),
133 -
        x = pp - 0.2, y = max(df(l, num_df, den_df)) + 0.02, color = "#0000CD",
134 -
        size = 3) +
135 -
      annotate("text", label = paste0((1 - probs) * 100, "%"),
136 -
        x = pp + 0.2, y = max(df(l, num_df, den_df)) + 0.02, color = "#6495ED",
137 -
        size = 3)
145 +
      ggtitle(label    = 'f Distribution',
146 +
              subtitle = paste0("P(X < ", pp, ") = ", probs * 100, "%")) +
147 +
      annotate("text",
148 +
               label = paste0(probs * 100, "%"),
149 +
               x     = pp - 0.2,
150 +
               y     = max(df(l, num_df, den_df)) + 0.02,
151 +
               color = "#0000CD",
152 +
               size  = 3) +
153 +
      annotate("text",
154 +
               label = paste0((1 - probs) * 100, "%"),
155 +
               x     = pp + 0.2,
156 +
               y     = max(df(l, num_df, den_df)) + 0.02,
157 +
               color = "#6495ED",
158 +
               size  = 3)
138 159
139 160
  } else {
140 161
    gplot <-
141 162
      gplot +
142 -
      ggtitle(label = 'f Distribution',
143 -
        subtitle = paste0("P(X > ", pp, ") = ", probs * 100, "%")) +
144 -
      annotate("text", label = paste0((1 - probs) * 100, "%"),
145 -
        x = pp - 0.2, y = max(df(l, num_df, den_df)) + 0.02, color = "#6495ED",
146 -
        size = 3) +
147 -
      annotate("text", label = paste0(probs * 100, "%"),
148 -
        x = pp + 0.2, y = max(df(l, num_df, den_df)) + 0.02, color = "#0000CD",
149 -
        size = 3)
163 +
      ggtitle(label    = 'f Distribution',
164 +
              subtitle = paste0("P(X > ", pp, ") = ", probs * 100, "%")) +
165 +
      annotate("text",
166 +
               label = paste0((1 - probs) * 100, "%"),
167 +
               x     = pp - 0.2,
168 +
               y     = max(df(l, num_df, den_df)) + 0.02,
169 +
               color = "#6495ED",
170 +
               size  = 3) +
171 +
      annotate("text",
172 +
               label = paste0(probs * 100, "%"),
173 +
               x     = pp + 0.2,
174 +
               y     = max(df(l, num_df, den_df)) + 0.02,
175 +
               color = "#0000CD",
176 +
               size  = 3)
150 177
  }
151 178
152 179
  for (i in seq_len(length(l1))) {
153 180
    poly_data <- vdist_pol_f(lc[l1[i]], lc[l2[i]], num_df, den_df)
154 181
    gplot <-
155 182
      gplot +
156 -
      geom_polygon(data = poly_data, mapping = aes(x = x, y = y),
157 -
        fill = col[i])
183 +
      geom_polygon(data    = poly_data,
184 +
                   mapping = aes(x = x, y = y),
185 +
                   fill    = col[i])
158 186
  }
159 187
160 188
  pln <- length(pp)
@@ -165,9 +193,14 @@
Loading
165 193
166 194
    gplot <-
167 195
      gplot +
168 -
      geom_vline(xintercept = pp[i], linetype = 2, size = 1) +
169 -
      geom_point(data = point_data, mapping = aes(x = x, y = y),
170 -
      shape = 4, color = 'red', size = 3)
196 +
      geom_vline(xintercept = pp[i],
197 +
                 linetype   = 2,
198 +
                 size       = 1) +
199 +
      geom_point(data    = point_data,
200 +
                 mapping = aes(x = x, y = y),
201 +
                 shape   = 4,
202 +
                 color   = 'red',
203 +
                 size    = 3)
171 204
  }
172 205
173 206
  gplot <-
@@ -224,43 +257,58 @@
Loading
224 257
225 258
  gplot <-
226 259
    ggplot(plot_data) +
227 -
    geom_line(data = plot_data, mapping = aes(x = x, y = y),
228 -
      color = 'blue') + xlab(paste("Mean =", fm, " Std Dev. =", fsd)) +
260 +
    geom_line(data    = plot_data,
261 +
              mapping = aes(x = x, y = y),
262 +
              color   = 'blue') +
263 +
    xlab(paste("Mean =", fm, " Std Dev. =", fsd)) +
229 264
    ylab('') +
230 -
    theme(plot.title = element_text(hjust = 0.5),
231 -
                   plot.subtitle = element_text(hjust = 0.5))
265 +
    theme(plot.title    = element_text(hjust = 0.5),
266 +
          plot.subtitle = element_text(hjust = 0.5))
232 267
233 268
  if (method == "lower") {
234 269
    gplot <-
235 270
      gplot +
236 -
      ggtitle(label = 'f Distribution',
237 -
        subtitle = paste0("P(X < ", perc, ") = ", pp * 100, "%")) +
238 -
      annotate("text", label = paste0(pp * 100, "%"),
239 -
        x = perc - fsd, y = max(df(l, num_df, den_df)) + 0.04, color = "#0000CD",
240 -
        size = 3) +
241 -
      annotate("text", label = paste0(round((1 - pp) * 100, 2), "%"),
242 -
        x = perc + fsd, y = max(df(l, num_df, den_df)) + 0.02, color = "#6495ED",
243 -
        size = 3)
271 +
      ggtitle(label    = 'f Distribution',
272 +
              subtitle = paste0("P(X < ", perc, ") = ", pp * 100, "%")) +
273 +
      annotate("text",
274 +
               label = paste0(pp * 100, "%"),
275 +
               x     = perc - fsd,
276 +
               y     = max(df(l, num_df, den_df)) + 0.04,
277 +
               color = "#0000CD",
278 +
               size  = 3) +
279 +
      annotate("text",
280 +
               label = paste0(round((1 - pp) * 100, 2), "%"),
281 +
               x     = perc + fsd,
282 +
               y     = max(df(l, num_df, den_df)) + 0.02,
283 +
               color = "#6495ED",
284 +
               size  = 3)
244 285
245 286
  } else {
246 287
    gplot <-
247 288
      gplot +
248 -
      ggtitle(label = 'f Distribution',
249 -
        subtitle = paste0("P(X > ", perc, ") = ", pp * 100, "%")) +
250 -
      annotate("text", label = paste0(round((1 - pp) * 100, 2), "%"),
251 -
        x = perc - fsd, y = max(df(l, num_df, den_df)) + 0.04, color = "#6495ED",
252 -
        size = 3) +
253 -
      annotate("text", label = paste0(pp * 100, "%"),
254 -
        x = perc + fsd, y = max(df(l, num_df, den_df)) + 0.04, color = "#0000CD",
255 -
        size = 3)
289 +
      ggtitle(label    = 'f Distribution',
290 +
              subtitle = paste0("P(X > ", perc, ") = ", pp * 100, "%")) +
291 +
      annotate("text",
292 +
               label = paste0(round((1 - pp) * 100, 2), "%"),
293 +
               x     = perc - fsd,
294 +
               y     = max(df(l, num_df, den_df)) + 0.04,
295 +
               color = "#6495ED",
296 +
               size  = 3) +
297 +
      annotate("text",
298 +
               label = paste0(pp * 100, "%"),
299 +
               x     = perc + fsd,
300 +
               y     = max(df(l, num_df, den_df)) + 0.04,
301 +
               color = "#0000CD",
302 +
               size  = 3)
256 303
  }
257 304
258 305
  for (i in seq_len(length(l1))) {
259 306
    poly_data <- vdist_pol_f(lc[l1[i]], lc[l2[i]], num_df, den_df)
260 307
    gplot <-
261 308
      gplot +
262 -
      geom_polygon(data = poly_data, mapping = aes(x = x, y = y),
263 -
        fill = col[i])
309 +
      geom_polygon(data    = poly_data,
310 +
                   mapping = aes(x = x, y = y),
311 +
                   fill    = col[i])
264 312
  }
265 313
266 314
  pln <- length(pp)
@@ -271,9 +319,14 @@
Loading
271 319
272 320
    gplot <-
273 321
      gplot +
274 -
      geom_vline(xintercept = perc[i], linetype = 2, size = 1) +
275 -
      geom_point(data = point_data, mapping = aes(x = x, y = y),
276 -
      shape = 4, color = 'red', size = 3)
322 +
      geom_vline(xintercept = perc[i],
323 +
                 linetype   = 2,
324 +
                 size       = 1) +
325 +
      geom_point(data    = point_data,
326 +
                 mapping = aes(x = x, y = y),
327 +
                 shape   = 4,
328 +
                 color   = 'red',
329 +
                 size    = 3)
277 330
  }
278 331
279 332
  gplot <-

@@ -42,17 +42,18 @@
Loading
42 42
  l1  <- c(3, 2, 1, 5, 6)
43 43
  l2  <- c(5, 3, 2, 6, 7)
44 44
  xm  <- vdist_xmm(mean, sd)
45 -
  
45 +
46 46
  plot_data <- data.frame(x = x, y = dnorm(x, mean, sd))
47 47
48 48
  gplot <-
49 49
    ggplot(plot_data) +
50 50
    geom_line(aes(x = x, y = y)) +
51 -
    xlab('') + ylab('') +
52 -
    ggtitle(label = "Normal Distribution",
53 -
      subtitle = paste("Mean:", mean, "     Standard Deviation:", sd)) +
54 -
    theme(plot.title = element_text(hjust = 0.5),
55 -
                   plot.subtitle = element_text(hjust = 0.5))
51 +
    xlab('') +
52 +
    ylab('') +
53 +
    ggtitle(label    = "Normal Distribution",
54 +
            subtitle = paste("Mean:", mean, "     Standard Deviation:", sd)) +
55 +
    theme(plot.title    = element_text(hjust = 0.5),
56 +
          plot.subtitle = element_text(hjust = 0.5))
56 57
57 58
  ll <- l[3:9]
58 59
@@ -60,7 +61,9 @@
Loading
60 61
    poly_data <- vdist_pol_cord(ll[l1[i]], ll[l2[i]], mean, sd)
61 62
    gplot <-
62 63
      gplot +
63 -
      geom_polygon(data = poly_data, mapping = aes(x = x, y = y), fill = col[i])
64 +
      geom_polygon(data    = poly_data,
65 +
                   mapping = aes(x = x, y = y),
66 +
                   fill    = col[i])
64 67
  }
65 68
66 69
  if (print_plot) {
@@ -74,9 +77,7 @@
Loading
74 77
#' @rdname vdist_normal_plot
75 78
#' @export
76 79
#'
77 -
vdist_normal_perc <- function(probs = 0.95, mean = 0, sd = 1,
78 -
                              type = c("lower", "upper", "both"),
79 -
                              print_plot = TRUE) {
80 +
vdist_normal_perc <- function(probs = 0.95, mean = 0, sd = 1, type = c("lower", "upper", "both"), print_plot = TRUE) {
80 81
81 82
  check_numeric(mean, "mean")
82 83
  check_numeric(sd, "sd")
@@ -118,54 +119,78 @@
Loading
118 119
  gplot <-
119 120
    ggplot(plot_data) +
120 121
    geom_line(aes(x = x, y = y)) +
121 -
    xlab(paste("Mean:", mean, " Standard Deviation:", sd)) + ylab('') +
122 -
    theme(plot.title = element_text(hjust = 0.5),
123 -
                   plot.subtitle = element_text(hjust = 0.5))
122 +
    xlab(paste("Mean:", mean, " Standard Deviation:", sd)) +
123 +
    ylab('') +
124 +
    theme(plot.title    = element_text(hjust = 0.5),
125 +
          plot.subtitle = element_text(hjust = 0.5))
124 126
125 127
  if (method == "lower") {
126 128
	  gplot <-
127 129
	    gplot +
128 -
	    ggtitle(label = "Normal Distribution",
129 -
	      subtitle = paste0("P(X < ", pp, ") = ", probs * 100, "%")) +
130 -
	    annotate("text", label = paste0(probs * 100, "%"),
131 -
	      x = pp - sd, y = max(dnorm(x, mean, sd)) + 0.025, color = "#0000CD",
132 -
	      size = 3) +
133 -
	    annotate("text", label = paste0((1 - probs) * 100, "%"),
134 -
	      x = pp + sd, y = max(dnorm(x, mean, sd)) + 0.025, color = "#6495ED",
135 -
	      size = 3)
130 +
	    ggtitle(label    = "Normal Distribution",
131 +
	            subtitle = paste0("P(X < ", pp, ") = ", probs * 100, "%")) +
132 +
	    annotate("text",
133 +
	             label = paste0(probs * 100, "%"),
134 +
	             x     = pp - sd,
135 +
	             y     = max(dnorm(x, mean, sd)) + 0.025,
136 +
	             color = "#0000CD",
137 +
	             size  = 3) +
138 +
	    annotate("text",
139 +
	             label = paste0((1 - probs) * 100, "%"),
140 +
	             x     = pp + sd,
141 +
	             y     = max(dnorm(x, mean, sd)) + 0.025,
142 +
	             color = "#6495ED",
143 +
	             size  = 3)
136 144
137 145
	} else if (method == "upper") {
138 146
	  gplot <-
139 147
	  	gplot +
140 -
	    ggtitle(label = "Normal Distribution",
141 -
	      subtitle = paste0("P(X > ", pp, ") = ", probs * 100, "%")) +
142 -
	    annotate("text", label = paste0((1 - probs) * 100, "%"),
143 -
	      x = pp - sd, y = max(dnorm(x, mean, sd)) + 0.025, color = "#6495ED",
144 -
	      size = 3) +
145 -
	    annotate("text", label = paste0(probs * 100, "%"),
146 -
	      x = pp + sd, y = max(dnorm(x, mean, sd)) + 0.025, color = "#0000CD",
147 -
	      size = 3)
148 +
	    ggtitle(label    = "Normal Distribution",
149 +
	            subtitle = paste0("P(X > ", pp, ") = ", probs * 100, "%")) +
150 +
	    annotate("text",
151 +
	             label = paste0((1 - probs) * 100, "%"),
152 +
	             x     = pp - sd,
153 +
	             y     = max(dnorm(x, mean, sd)) + 0.025,
154 +
	             color = "#6495ED",
155 +
	             size  = 3) +
156 +
	    annotate("text",
157 +
	             label = paste0(probs * 100, "%"),
158 +
	             x     = pp + sd,
159 +
	             y     = max(dnorm(x, mean, sd)) + 0.025,
160 +
	             color = "#0000CD",
161 +
	             size  = 3)
148 162
	} else {
149 163
		gplot <-
150 164
	  	gplot +
151 -
	    ggtitle(label = "Normal Distribution",
152 -
	      subtitle = paste0("P(", pp[1], " < X < ", pp[2], ") = ", probs * 100, "%")) +
153 -
	    annotate("text", label = paste0(probs * 100, "%"),
154 -
	      x = mean, y = max(dnorm(x, mean, sd)) + 0.025, color = "#0000CD",
155 -
	      size = 3) +
156 -
	    annotate("text", label = paste0(alpha * 100, "%"),
157 -
	      x = pp[1] - sd, y = max(dnorm(x, mean, sd)) + 0.025, color = "#6495ED",
158 -
	      size = 3) +
159 -
	    annotate("text", label = paste0(alpha * 100, "%"),
160 -
	      x = pp[2] + sd, y = max(dnorm(x, mean, sd)) + 0.025, color = "#6495ED",
161 -
	      size = 3)
165 +
	    ggtitle(label    = "Normal Distribution",
166 +
	            subtitle = paste0("P(", pp[1], " < X < ", pp[2], ") = ", probs * 100, "%")) +
167 +
	    annotate("text",
168 +
	             label = paste0(probs * 100, "%"),
169 +
	             x     = mean,
170 +
	             y     = max(dnorm(x, mean, sd)) + 0.025,
171 +
	             color = "#0000CD",
172 +
	             size  = 3) +
173 +
	    annotate("text",
174 +
	             label = paste0(alpha * 100, "%"),
175 +
	             x     = pp[1] - sd,
176 +
	             y     = max(dnorm(x, mean, sd)) + 0.025,
177 +
	             color = "#6495ED",
178 +
	             size  = 3) +
179 +
	    annotate("text",
180 +
	             label = paste0(alpha * 100, "%"),
181 +
	             x     = pp[2] + sd,
182 +
	             y     = max(dnorm(x, mean, sd)) + 0.025,
183 +
	             color = "#6495ED",
184 +
	             size  = 3)
162 185
	}
163 186
164 187
	for (i in seq_len(length(l1))) {
165 188
		poly_data <- vdist_pol_cord(lc[l1[i]], lc[l2[i]], mean, sd)
166 189
		gplot <-
167 190
		  gplot +
168 -
		  geom_polygon(data = poly_data, mapping = aes(x = x, y = y), fill = col[i])
191 +
		  geom_polygon(data    = poly_data,
192 +
		               mapping = aes(x = x, y = y),
193 +
		               fill    = col[i])
169 194
  }
170 195
171 196
  pln <- length(pp)
@@ -176,9 +201,14 @@
Loading
176 201
177 202
  	gplot <-
178 203
  	  gplot +
179 -
  	  geom_vline(xintercept = pp[i], linetype = 2, size = 1) +
180 -
  	  geom_point(data = point_data, mapping = aes(x = x, y = y),
181 -
	    shape = 4, color = 'red', size = 3)
204 +
  	  geom_vline(xintercept = pp[i],
205 +
  	             linetype   = 2,
206 +
  	             size       = 1) +
207 +
  	  geom_point(data    = point_data,
208 +
  	             mapping = aes(x = x, y = y),
209 +
  	             shape   = 4,
210 +
  	             color   = 'red',
211 +
  	             size    = 3)
182 212
  }
183 213
184 214
  gplot <-
@@ -197,9 +227,7 @@
Loading
197 227
#' @rdname vdist_normal_plot
198 228
#' @export
199 229
#'
200 -
vdist_normal_prob <- function(perc = 3, mean = 0, sd = 1,
201 -
                              type = c("lower", "upper", "both"),
202 -
                              print_plot = TRUE) {
230 +
vdist_normal_prob <- function(perc = 3, mean = 0, sd = 1, type = c("lower", "upper", "both"), print_plot = TRUE) {
203 231
204 232
  method <- match.arg(type)
205 233
@@ -253,54 +281,78 @@
Loading
253 281
  gplot <-
254 282
    ggplot(plot_data) +
255 283
    geom_line(aes(x = x, y = y)) +
256 -
    xlab(paste("Mean:", mean, " Standard Deviation:", sd)) + ylab('') +
257 -
    theme(plot.title = element_text(hjust = 0.5),
258 -
                   plot.subtitle = element_text(hjust = 0.5))
284 +
    xlab(paste("Mean:", mean, " Standard Deviation:", sd)) +
285 +
    ylab('') +
286 +
    theme(plot.title    = element_text(hjust = 0.5),
287 +
          plot.subtitle = element_text(hjust = 0.5))
259 288
260 289
  if (method == "lower") {
261 290
	  gplot <-
262 291
	    gplot +
263 -
	    ggtitle(label = "Normal Distribution",
264 -
	      subtitle = paste0("P(X < ", perc, ") = ", pp * 100, "%")) +
265 -
	    annotate("text", label = paste0(pp * 100, "%"),
266 -
	      x = perc - sd, y = max(dnorm(x, mean, sd)) + 0.07, color = "#0000CD",
267 -
	      size = 3) +
268 -
	    annotate("text", label = paste0((1 - pp) * 100, "%"),
269 -
	      x = perc + sd, y = max(dnorm(x, mean, sd)) + 0.07, color = "#6495ED",
270 -
	      size = 3)
292 +
	    ggtitle(label    = "Normal Distribution",
293 +
	            subtitle = paste0("P(X < ", perc, ") = ", pp * 100, "%")) +
294 +
	    annotate("text",
295 +
	             label = paste0(pp * 100, "%"),
296 +
	             x     = perc - sd,
297 +
	             y     = max(dnorm(x, mean, sd)) + 0.07,
298 +
	             color = "#0000CD",
299 +
	             size  = 3) +
300 +
	    annotate("text",
301 +
	             label = paste0((1 - pp) * 100, "%"),
302 +
	             x     = perc + sd,
303 +
	             y     = max(dnorm(x, mean, sd)) + 0.07,
304 +
	             color = "#6495ED",
305 +
	             size  = 3)
271 306
272 307
	} else if (method == "upper") {
273 308
	  gplot <-
274 309
	  	gplot +
275 -
	    ggtitle(label = "Normal Distribution",
276 -
	      subtitle = paste0("P(X > ", perc, ") = ", pp * 100, "%")) +
277 -
	    annotate("text", label = paste0((1 - pp) * 100, "%"),
278 -
	      x = perc - sd, y = max(dnorm(x, mean, sd)) + 0.07, color = "#6495ED",
279 -
	      size = 3) +
280 -
	    annotate("text", label = paste0(pp * 100, "%"),
281 -
	      x = perc + sd, y = max(dnorm(x, mean, sd)) + 0.07, color = "#0000CD",
282 -
	      size = 3)
310 +
	    ggtitle(label    = "Normal Distribution",
311 +
	            subtitle = paste0("P(X > ", perc, ") = ", pp * 100, "%")) +
312 +
	    annotate("text",
313 +
	             label = paste0((1 - pp) * 100, "%"),
314 +
	             x     = perc - sd,
315 +
	             y     = max(dnorm(x, mean, sd)) + 0.07,
316 +
	             color = "#6495ED",
317 +
	             size  = 3) +
318 +
	    annotate("text",
319 +
	             label = paste0(pp * 100, "%"),
320 +
	             x     = perc + sd,
321 +
	             y     = max(dnorm(x, mean, sd)) + 0.07,
322 +
	             color = "#0000CD",
323 +
	             size  = 3)
283 324
	} else {
284 325
		gplot <-
285 326
	  	gplot +
286 -
	    ggtitle(label = "Normal Distribution",
287 -
	      subtitle = paste0("P(", perc[1], " < X < ", perc[2], ") = ", (1 - (pp1 + pp2)) * 100, "%")) +
288 -
	    annotate("text", label = paste0((1 - (pp1 + pp2)) * 100, "%"),
289 -
	      x = mean(perc), y = max(dnorm(x, mean, sd)) + 0.07, color = "#0000CD",
290 -
	      size = 3) +
291 -
	    annotate("text", label = paste0(pp[1] * 100, "%"),
292 -
	      x = perc[1] - sd, y = max(dnorm(x, mean, sd)) + 0.07, color = "#6495ED",
293 -
	      size = 3) +
294 -
	    annotate("text", label = paste0(pp[2] * 100, "%"),
295 -
	      x = perc[2] + sd, y = max(dnorm(x, mean, sd)) + 0.07, color = "#6495ED",
296 -
	      size = 3)
327 +
	    ggtitle(label    = "Normal Distribution",
328 +
	            subtitle = paste0("P(", perc[1], " < X < ", perc[2], ") = ", (1 - (pp1 + pp2)) * 100, "%")) +
329 +
	    annotate("text",
330 +
	             label = paste0((1 - (pp1 + pp2)) * 100, "%"),
331 +
	             x     = mean(perc),
332 +
	             y     = max(dnorm(x, mean, sd)) + 0.07,
333 +
	             color = "#0000CD",
334 +
	             size  = 3) +
335 +
	    annotate("text",
336 +
	             label = paste0(pp[1] * 100, "%"),
337 +
	             x     = perc[1] - sd,
338 +
	             y     = max(dnorm(x, mean, sd)) + 0.07,
339 +
	             color = "#6495ED",
340 +
	             size  = 3) +
341 +
	    annotate("text",
342 +
	             label = paste0(pp[2] * 100, "%"),
343 +
	             x     = perc[2] + sd,
344 +
	             y     = max(dnorm(x, mean, sd)) + 0.07,
345 +
	             color = "#6495ED",
346 +
	             size  = 3)
297 347
	}
298 348
299 349
  for (i in seq_len(length(l1))) {
300 350
		poly_data <- vdist_pol_cord(lc[l1[i]], lc[l2[i]], mean, sd)
301 351
		gplot <-
302 352
		  gplot +
303 -
		  geom_polygon(data = poly_data, mapping = aes(x = x, y = y), fill = col[i])
353 +
		  geom_polygon(data    = poly_data,
354 +
		               mapping = aes(x = x, y = y),
355 +
		               fill    = col[i])
304 356
  }
305 357
306 358
  pln <- length(pp)
@@ -311,9 +363,14 @@
Loading
311 363
312 364
  	gplot <-
313 365
  	  gplot +
314 -
  	  geom_vline(xintercept = perc[i], linetype = 2, size = 1) +
315 -
  	  geom_point(data = point_data, mapping = aes(x = x, y = y),
316 -
	    shape = 4, color = 'red', size = 3)
366 +
  	  geom_vline(xintercept = perc[i],
367 +
  	             linetype   = 2,
368 +
  	             size       = 1) +
369 +
  	  geom_point(data    = point_data,
370 +
  	             mapping = aes(x = x, y = y),
371 +
	               shape   = 4,
372 +
  	             color   = 'red',
373 +
  	             size    = 3)
317 374
  }
318 375
319 376
  gplot <-

@@ -31,8 +31,7 @@
Loading
31 31
#'
32 32
#' @export
33 33
#'
34 -
vdist_chisquare_plot <- function(df = 3, normal = FALSE,
35 -
                                 xaxis_range = 25, print_plot = TRUE) {
34 +
vdist_chisquare_plot <- function(df = 3, normal = FALSE, xaxis_range = 25, print_plot = TRUE) {
36 35
37 36
  check_numeric(df, "df")
38 37
  check_logical(normal)
@@ -52,29 +51,32 @@
Loading
52 51
53 52
	pp <-
54 53
	  ggplot(plot_data) +
55 -
	  geom_line(aes(x, chi), color = '#4682B4', size = 2) +
54 +
	  geom_line(aes(x, chi),
55 +
	            color = '#4682B4',
56 +
	            size  = 2) +
56 57
	  ggtitle(label    = "Chi Square Distribution",
57 -
	                   subtitle = paste("df =", df)) +
58 +
	          subtitle = paste("df =", df)) +
58 59
	  ylab('') +
59 60
	  xlab(paste("Mean =", chim, " Std Dev. =", chisd)) +
60 -
	  theme(plot.title = element_text(hjust = 0.5),
61 -
	                 plot.subtitle = element_text(hjust = 0.5)) +
61 +
	  theme(plot.title    = element_text(hjust = 0.5),
62 +
	        plot.subtitle = element_text(hjust = 0.5)) +
62 63
	  scale_x_continuous(breaks = seq(0, xaxis_range, 2)) +
63 64
	  geom_polygon(data    = poly_data,
64 -
	                        mapping = aes(x = y, y = z),
65 -
	                        fill    = '#4682B4') +
65 +
	               mapping = aes(x = y, y = z),
66 +
	               fill    = '#4682B4') +
66 67
	  geom_point(data    = point_data,
67 -
	                      mapping = aes(x = x, y = y),
68 -
	                      shape   = 4,
69 -
	                      color   = 'red',
70 -
	                      size    = 3)
68 +
	             mapping = aes(x = x, y = y),
69 +
	             shape   = 4,
70 +
	             color   = 'red',
71 +
	             size    = 3)
71 72
72 73
73 74
	if (normal) {
74 75
	  pp <-
75 76
	  	pp +
76 -
	    geom_line(data = nline_data, mapping = aes(x = x, y = y),
77 -
	      color = '#FF4500')
77 +
	    geom_line(data    = nline_data,
78 +
	              mapping = aes(x = x, y = y),
79 +
	              color   = '#FF4500')
78 80
	}
79 81
80 82
	if (print_plot) {
@@ -88,9 +90,7 @@
Loading
88 90
#' @rdname vdist_chisquare_plot
89 91
#' @export
90 92
#'
91 -
vdist_chisquare_perc <- function(probs = 0.95, df = 3,
92 -
                                 type = c("lower", "upper"),
93 -
                                 print_plot = TRUE) {
93 +
vdist_chisquare_perc <- function(probs = 0.95, df = 3, type = c("lower", "upper"), print_plot = TRUE) {
94 94
95 95
  check_numeric(probs, "probs")
96 96
  check_numeric(df, "df")
@@ -121,48 +121,49 @@
Loading
121 121
	plot_data <- data.frame(x = l, y = dchisq(l, df))
122 122
	gplot <-
123 123
	  ggplot(plot_data) +
124 -
	  geom_line(aes(x = x, y = y), color = "blue") +
124 +
	  geom_line(aes(x = x, y = y),
125 +
	            color = "blue") +
125 126
	  xlab(paste("Mean =", chim, " Std Dev. =", chisd)) +
126 127
	  ylab('') +
127 128
	  theme(plot.title    = element_text(hjust = 0.5),
128 -
	                 plot.subtitle = element_text(hjust = 0.5))
129 +
	        plot.subtitle = element_text(hjust = 0.5))
129 130
130 131
131 132
	if (method == "lower") {
132 133
	  gplot <-
133 134
	    gplot +
134 135
	    ggtitle(label    = paste("Chi Square Distribution: df =", df),
135 -
	                     subtitle = paste0("P(X < ", pp, ") = ", probs * 100, "%")) +
136 +
	            subtitle = paste0("P(X < ", pp, ") = ", probs * 100, "%")) +
136 137
	    annotate("text",
137 -
	                      label   = paste0(probs * 100, "%"),
138 -
	                      x       = pp - chisd,
139 -
	                      y       = max(dchisq(l, df)) + 0.02,
140 -
	                      color   = "#0000CD",
141 -
	                      size    = 3) +
138 +
	             label   = paste0(probs * 100, "%"),
139 +
	             x       = pp - chisd,
140 +
	             y       = max(dchisq(l, df)) + 0.02,
141 +
	             color   = "#0000CD",
142 +
	             size    = 3) +
142 143
	    annotate("text",
143 -
	                      label   = paste0((1 - probs) * 100, "%"),
144 -
	                      x       = pp + chisd,
145 -
	                      y       = max(dchisq(l, df)) + 0.02,
146 -
	                      color   = "#6495ED",
147 -
	                      size    = 3)
144 +
	             label   = paste0((1 - probs) * 100, "%"),
145 +
	             x       = pp + chisd,
146 +
	             y       = max(dchisq(l, df)) + 0.02,
147 +
	             color   = "#6495ED",
148 +
	             size    = 3)
148 149
149 150
	} else {
150 151
	  gplot <-
151 152
	  	gplot +
152 153
	    ggtitle(label    = paste("Chi Square Distribution: df =", df),
153 -
	                     subtitle = paste0("P(X > ", pp, ") = ", probs * 100, "%")) +
154 +
	            subtitle = paste0("P(X > ", pp, ") = ", probs * 100, "%")) +
154 155
	    annotate("text",
155 -
	                      label   = paste0((1 - probs) * 100, "%"),
156 -
	                      x       = pp - chisd,
157 -
	                      y       = max(dchisq(l, df)) + 0.02,
158 -
	                      color   = "#6495ED",
159 -
	                      size    = 3) +
156 +
	             label   = paste0((1 - probs) * 100, "%"),
157 +
	             x       = pp - chisd,
158 +
	             y       = max(dchisq(l, df)) + 0.02,
159 +
	             color   = "#6495ED",
160 +
	             size    = 3) +
160 161
	    annotate("text",
161 -
	                      label   = paste0(probs * 100, "%"),
162 -
	                      x       = pp + chisd,
163 -
	                      y       = max(dchisq(l, df)) + 0.02,
164 -
	                      color   = "#0000CD",
165 -
	                      size    = 3)
162 +
	             label   = paste0(probs * 100, "%"),
163 +
	             x       = pp + chisd,
164 +
	             y       = max(dchisq(l, df)) + 0.02,
165 +
	             color   = "#0000CD",
166 +
	             size    = 3)
166 167
	}
167 168
168 169
	for (i in seq_len(length(l1))) {
@@ -170,8 +171,8 @@
Loading
170 171
	  gplot <-
171 172
	    gplot +
172 173
	    geom_polygon(data    = pol_data,
173 -
	                          mapping = aes(x = x, y = y),
174 -
	                          fill    = col[i])
174 +
	                 mapping = aes(x = x, y = y),
175 +
	                 fill    = col[i])
175 176
	}
176 177
177 178
	point_data <- data.frame(x = pp, y = min(dchisq(l, df)))
@@ -179,13 +180,13 @@
Loading
179 180
	gplot <-
180 181
	  gplot +
181 182
	  geom_vline(xintercept = pp,
182 -
	                      linetype   = 2,
183 -
	                      size       = 1) +
183 +
	             linetype   = 2,
184 +
	             size       = 1) +
184 185
	  geom_point(data       = point_data,
185 -
	                      mapping    = aes(x = x, y = y),
186 -
	                      shape      = 4,
187 -
	                      color      = 'red',
188 -
	                      size       = 3) +
186 +
	             mapping    = aes(x = x, y = y),
187 +
	             shape      = 4,
188 +
	             color      = 'red',
189 +
	             size       = 3) +
189 190
	  scale_y_continuous(breaks = NULL) +
190 191
	  scale_x_continuous(breaks = seq(0, xm[2], by = 5))
191 192
@@ -200,8 +201,7 @@
Loading
200 201
#' @rdname vdist_chisquare_plot
201 202
#' @export
202 203
#'
203 -
vdist_chisquare_prob <- function(perc = 13, df = 11, type = c("lower", "upper"),
204 -
                                 print_plot = TRUE) {
204 +
vdist_chisquare_prob <- function(perc = 13, df = 11, type = c("lower", "upper"), print_plot = TRUE) {
205 205
206 206
207 207
  check_numeric(df, "df")
@@ -235,36 +235,49 @@
Loading
235 235
  plot_data <- data.frame(x = l, y = dchisq(l, df))
236 236
	gplot <-
237 237
	  ggplot(plot_data) +
238 -
	  geom_line(aes(x = x, y = y), color = "blue") +
238 +
	  geom_line(aes(x = x, y = y),
239 +
	            color = "blue") +
239 240
	  xlab(paste("Mean =", chim, " Std Dev. =", chisd)) +
240 241
	  ylab('') +
241 -
	  theme(plot.title = element_text(hjust = 0.5),
242 -
	                 plot.subtitle = element_text(hjust = 0.5))
242 +
	  theme(plot.title    = element_text(hjust = 0.5),
243 +
	        plot.subtitle = element_text(hjust = 0.5))
243 244
244 245
245 246
  if (method == "lower") {
246 247
	  gplot <-
247 248
	    gplot +
248 -
	    ggtitle(label = paste("Chi Square Distribution: df =", df),
249 -
	      subtitle = paste0("P(X < ", perc, ") = ", pp * 100, "%")) +
250 -
	    annotate("text", label = paste0(pp * 100, "%"),
251 -
	      x = perc - chisd, y = max(dchisq(l, df)) + 0.02, color = "#0000CD",
252 -
	      size = 3) +
253 -
	    annotate("text", label = paste0((1 - pp) * 100, "%"),
254 -
	      x = perc + chisd, y = max(dchisq(l, df)) + 0.02, color = "#6495ED",
255 -
	      size = 3)
249 +
	    ggtitle(label    = paste("Chi Square Distribution: df =", df),
250 +
	            subtitle = paste0("P(X < ", perc, ") = ", pp * 100, "%")) +
251 +
	    annotate("text",
252 +
	             label = paste0(pp * 100, "%"),
253 +
	             x     = perc - chisd,
254 +
	             y     = max(dchisq(l, df)) + 0.02,
255 +
	             color = "#0000CD",
256 +
	             size  = 3) +
257 +
	    annotate("text",
258 +
	             label = paste0((1 - pp) * 100, "%"),
259 +
	             x     = perc + chisd,
260 +
	             y     = max(dchisq(l, df)) + 0.02,
261 +
	             color = "#6495ED",
262 +
	             size  = 3)
256 263
257 264
	} else {
258 265
	  gplot <-
259 266
	  	gplot +
260 -
	    ggtitle(label = paste("Chi Square Distribution: df =", df),
261 -
	      subtitle = paste0("P(X > ", perc, ") = ", pp * 100, "%")) +
262 -
	    annotate("text", label = paste0((1 - pp) * 100, "%"),
263 -
	      x = perc - chisd, y = max(dchisq(l, df)) + 0.02, color = "#6495ED",
264 -
	      size = 3) +
265 -
	    annotate("text", label = paste0(pp * 100, "%"),
266 -
	      x = perc + chisd, y = max(dchisq(l, df)) + 0.02, color = "#0000CD",
267 -
	      size = 3)
267 +
	    ggtitle(label    = paste("Chi Square Distribution: df =", df),
268 +
	            subtitle = paste0("P(X > ", perc, ") = ", pp * 100, "%")) +
269 +
	    annotate("text",
270 +
	             label = paste0((1 - pp) * 100, "%"),
271 +
	             x     = perc - chisd,
272 +
	             y     = max(dchisq(l, df)) + 0.02,
273 +
	             color = "#6495ED",
274 +
	             size  = 3) +
275 +
	    annotate("text",
276 +
	             label = paste0(pp * 100, "%"),
277 +
	             x     = perc + chisd,
278 +
	             y     = max(dchisq(l, df)) + 0.02,
279 +
	             color = "#0000CD",
280 +
	             size  = 3)
268 281
	}
269 282
270 283
@@ -273,8 +286,8 @@
Loading
273 286
	  gplot <-
274 287
	    gplot +
275 288
	    geom_polygon(data    = pol_data,
276 -
	                          mapping = aes(x = x, y = y),
277 -
	                          fill    = col[i])
289 +
	                 mapping = aes(x = x, y = y),
290 +
	                 fill    = col[i])
278 291
	}
279 292
280 293
	point_data <- data.frame(x = perc,
@@ -283,13 +296,13 @@
Loading
283 296
	gplot <-
284 297
	  gplot +
285 298
	  geom_vline(xintercept = perc,
286 -
	                      linetype   = 2,
287 -
	                      size       = 1) +
299 +
	             linetype   = 2,
300 +
	             size       = 1) +
288 301
	  geom_point(data       = point_data,
289 -
	                      mapping    = aes(x = x, y = y),
290 -
	                      shape      = 4,
291 -
	                      color      = 'red',
292 -
	                      size       = 3) +
302 +
	             mapping    = aes(x = x, y = y),
303 +
	             shape      = 4,
304 +
	             color      = 'red',
305 +
	             size       = 3) +
293 306
	  scale_y_continuous(breaks = NULL) +
294 307
	  scale_x_continuous(breaks = seq(0, l[ln], by = 5))
295 308

@@ -48,12 +48,14 @@
Loading
48 48
49 49
	pp <-
50 50
		ggplot(plot_data) +
51 -
		geom_col(aes(x = n, y = df), fill = "blue") +
52 -
		ylab("Probability") + xlab("No. of success") +
53 -
		ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
54 -
										 subtitle = paste("Mean =", bm, ", Std. Dev. =", bsd)) +
55 -
		theme(plot.title = element_text(hjust = 0.5),
56 -
									 plot.subtitle = element_text(hjust = 0.5)) +
51 +
		geom_col(aes(x = n, y = df),
52 +
		         fill = "blue") +
53 +
		ylab("Probability") +
54 +
	  xlab("No. of success") +
55 +
		ggtitle(label    = paste("Binomial Distribution: n =", n, ", p =", p),
56 +
		        subtitle = paste("Mean =", bm, ", Std. Dev. =", bsd)) +
57 +
		theme(plot.title    = element_text(hjust = 0.5),
58 +
		      plot.subtitle = element_text(hjust = 0.5)) +
57 59
		scale_x_continuous(breaks = seq(0, n))
58 60
59 61
	if (print_plot) {
@@ -116,29 +118,30 @@
Loading
116 118
117 119
	pp <-
118 120
		ggplot(plot_data) +
119 -
		geom_col(aes(x = n, y = df), fill = cols) +
121 +
		geom_col(aes(x = n, y = df),
122 +
		         fill = cols) +
120 123
		ylab("Probability") +
121 124
		xlab(paste("No. of success\n", "Mean =", bm, ", Std. Dev. =", bsd)) +
122 125
		scale_x_continuous(breaks = seq(0, n)) +
123 -
		theme(plot.title = element_text(hjust = 0.5),
124 -
									 plot.subtitle = element_text(hjust = 0.5))
126 +
		theme(plot.title    = element_text(hjust = 0.5),
127 +
		      plot.subtitle = element_text(hjust = 0.5))
125 128
126 129
	if (method == "lower") {
127 130
		pp +
128 -
			ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
129 -
											 subtitle = paste("P(X) <=", s, "=", round(k, 3)))
131 +
			ggtitle(label    = paste("Binomial Distribution: n =", n, ", p =", p),
132 +
			        subtitle = paste("P(X) <=", s, "=", round(k, 3)))
130 133
	} else if (method == "upper") {
131 134
		pp +
132 -
			ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
133 -
											 subtitle = paste("P(X) >=", s, "=", round(k, 3)))
135 +
			ggtitle(label    = paste("Binomial Distribution: n =", n, ", p =", p),
136 +
			        subtitle = paste("P(X) >=", s, "=", round(k, 3)))
134 137
	} else if (method == "exact") {
135 138
		pp +
136 -
			ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
137 -
											 subtitle = paste("P(X) =", s, "=", round(k, 3)))
139 +
			ggtitle(label    = paste("Binomial Distribution: n =", n, ", p =", p),
140 +
			        subtitle = paste("P(X) =", s, "=", round(k, 3)))
138 141
	} else {
139 142
		pp +
140 -
			ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
141 -
											 subtitle = paste0("P(", s[1], " <= X <= ", s[2], ")", " = ", round(k, 3)))
143 +
			ggtitle(label    = paste("Binomial Distribution: n =", n, ", p =", p),
144 +
			        subtitle = paste0("P(", s[1], " <= X <= ", s[2], ")", " = ", round(k, 3)))
142 145
	}
143 146
144 147
	if (print_plot) {
@@ -160,7 +163,7 @@
Loading
160 163
	check_numeric(tp, "tp")
161 164
	check_range(p)
162 165
	check_range(tp, 0, 0.5, "tp")
163 -
	
166 +
164 167
	n      <- as.integer(n)
165 168
	method <- match.arg(type)
166 169
	x      <- seq(0, n, 1)
@@ -178,23 +181,25 @@
Loading
178 181
179 182
	pp <-
180 183
		ggplot(plot_data) +
181 -
		geom_col(aes(x = n, y = df), fill = cols) +
182 -
		ylab("Probability") + xlab("No. of success") +
184 +
		geom_col(aes(x = n, y = df),
185 +
		         fill = cols) +
186 +
		ylab("Probability") +
187 +
	  xlab("No. of success") +
183 188
		scale_x_continuous(breaks = seq(0, n)) +
184 -
		theme(plot.title = element_text(hjust = 0.5),
185 -
									 plot.subtitle = element_text(hjust = 0.5))
189 +
		theme(plot.title    = element_text(hjust = 0.5),
190 +
		      plot.subtitle = element_text(hjust = 0.5))
186 191
187 192
188 193
	if (method == "lower") {
189 194
		pp +
190 -
			ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
191 -
				subtitle = paste0("P(X <= ", k, ") <= ", tp, ", but P(X <= ", (k + 1),
192 -
				") > ", tp))
195 +
			ggtitle(label    = paste("Binomial Distribution: n =", n, ", p =", p),
196 +
			        subtitle = paste0("P(X <= ", k, ") <= ", tp, ", but P(X <= ", (k + 1), ") > ", tp)
197 +
			        )
193 198
	} else {
194 199
		pp +
195 -
			ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
196 -
				subtitle = paste0("P(X >= ", (k + 1), ") <= ", tp, ", but P(X >= ", k,
197 -
				") > ", tp))
200 +
			ggtitle(label    = paste("Binomial Distribution: n =", n, ", p =", p),
201 +
			        subtitle = paste0("P(X >= ", (k + 1), ") <= ", tp, ", but P(X >= ", k, ") > ", tp)
202 +
			        )
198 203
	}
199 204
200 205
	if (print_plot) {
Files Coverage
R 95.68%
Project Totals (8 files) 95.68%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
        informational: true
10
    patch:
11
      default:
12
        target: auto
13
        threshold: 1%
14
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading