-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontinuous.Rmd
94 lines (67 loc) · 2.34 KB
/
continuous.Rmd
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
---
title: "PhyloWizard Continuous"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(knitr)
```
```{r, echo = FALSE}
# hidden from user, these are the functions to provide the summaries
summary_stats <- function(data) {
ave <- mean(data)
medi <- median(data)
stand_dv <- sd(data)
range_upper <- max(data)
range_lower <- min(data)
return(list(ave = ave,
medi = medi,
stand_dv = stand_dv,
range_upper = range_upper,
range_lower = range_lower))
}
num_obs <- function(data) {
length(data)
}
data_normal <- function(data) {
shap_test <- shapiro.test(data)
return(shap_test$p.value)
}
density_plot <- function(data) {
d <- density(data) # returns the density data
plot(d, main = "Density Plot of Data")
polygon(d, col="darkolivegreen3")
}
hist_w_normal <- function(data, char_name = NA) {
#histogram
h <- hist(data, col="grey", xlab = char_name,
main = paste("Shapiro-Wilk test of normality P-Value:", round(data_normal(data), digits = 3), sep = " "))
#normal distribution based on mean and sd of data
xfit <- seq(min(data),max(data),length=40)
yfit <- dnorm(xfit,mean=mean(data),sd=sd(data))
yfit <- yfit*diff(h$mids[1:2])*length(data)
lines(xfit, yfit, col="black", lwd=2, lty = 2)
legend("topright",
legend = c("Data", "Normal"),
col = c("grey", "black"),
pch = c(19, 19),
bty = "n",
pt.cex = 1,
cex = 1,
text.col = c("black", "black"),
horiz = F)
}
```
## Let's make up test data
Here we go!!
```{r}
test_data <- rnorm(n = 100, mean = 65, sd = 10)
```
```{r, include = FALSE}
summary <- summary_stats(test_data)
```
Your data has a mean of `r round(summary$ave, digits = 2)`, median of `r round(summary$medi, digits = 2)`, and standard deviation of `r round(summary$stand_dv, digits = 2)`. The data range from `r round(summary$range_lower, digits = 2)` to `r round(summary$range_upper, digits = 2)`.
The plot below shows the distribution of your data compared to a normal distribution with the same mean and standard deviation. The Shapiro-Wilk test of normality compares your data to a normal distribution. A significant p-value indicates that your data are significantly different from a normal distribution.
```{r, echo = FALSE}
hist_w_normal(test_data)
```