-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelement 3.Rmd
More file actions
110 lines (75 loc) · 2.5 KB
/
element 3.Rmd
File metadata and controls
110 lines (75 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
title: "Element 3"
output: html_notebook
---
```{r}
df <- read.csv("Attachment_1638128243.csv", header=TRUE)
df
#NAS
df[is.na(df)] = 0
#Percentile
quantile(df,.7,na.rm=TRUE)
#Mean
mean.result = mean(df$Claim.size)
#stadard deviation
sd.result = sqrt(var(df$Claim.size))
#simulation
set.seed(5)
# normal
x <- rnorm(1000, mean.result, sd.result)
#Skewness and Kurtosis
library(moments)
skewness(x)
kurtosis(x)
#Skewness
library(ggplot2)
datasim <- data.frame(x)
density_plot <-
datasim %>%
ggplot(aes(x = x)) +
stat_density(geom = "line", alpha = 1, colour = "cornflowerblue")
density_plot
shaded_area_data <-
ggplot_build(density_plot)$data[[1]] %>%
filter(x < mean(datasim$x))
density_plot_shaded <-
density_plot +
geom_area(data = shaded_area_data, aes(x = x, y = y), fill="pink", alpha = 0.5)
density_plot_shaded
median <- median(datasim$x)
mean <- mean(datasim$x)
median_line_data <-
ggplot_build(density_plot)$data[[1]] %>%
filter(x <= median)
density_plot_shaded +
geom_segment(data = shaded_area_data, aes(x = mean, y = 0, xend = mean, yend = density),
color = "red", linetype = "dotted") +
geom_segment(data = median_line_data, aes(x = median, y = 0, xend = median, yend = density),
color = "black", linetype = "dotted") +
ggtitle("Density Plot Illustrating Skewness")
#Kurtosis
library(tidyverse)
mean <- mean(datasim$x)
sd_pos <- mean + (2 * sd(datasim$x))
sd_neg <- mean - (2 * sd(datasim$x))
sd_pos_shaded_area <-
ggplot_build(density_plot)$data[[1]] %>%
filter(x > sd_pos )
sd_neg_shaded_area <-
ggplot_build(density_plot)$data[[1]] %>%
filter(x < sd_neg)
density_plot <-
density_plot +
geom_area(data = sd_pos_shaded_area, aes(x = x, y = y), fill="pink", alpha = 0.5) +
geom_area(data = sd_neg_shaded_area, aes(x = x, y = y), fill="pink", alpha = 0.5) +
scale_x_continuous(breaks = scales::pretty_breaks(n = 10))
density_plot
mean <- mean(datasim$x)
mean_line_data <-
ggplot_build(density_plot)$data[[1]] %>%
filter(x <= mean)
density_plot + geom_segment(data = median_line_data, aes(x = median, y = 0, xend = median, yend = density),
color = "black", linetype = "dotted")+
ggtitle("Density Plot Illustrating Kurtosis")
```
The critical value of Zg2 is approximately 2. (This is a two-tailed test of excess kurtosis ≠ 0 at approximately the 0.05 significance level.)