library(readxl)
CHEM_RESULTS <- read_excel("CHEM RESULTS.xlsx",
sheet = "Variance tests ")
View(CHEM_RESULTS)
it is important to do both visual checks & normality tests in small samples (n<30).
set.seed(0)
library(ggpubr)
## Loading required package: ggplot2
ggqqplot(CHEM_RESULTS$`Enterococci (CFU/100 mL)`)+
ggtitle("QQ Plot Enterococci (CFU/100 mL)")
not normally distributed.
shapiro.test(CHEM_RESULTS$`Enterococci (CFU/100 mL)`)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$`Enterococci (CFU/100 mL)`
## W = 0.65488, p-value = 5.601e-05
not normallydistributed p value <0.05
set.seed(0)
ggqqplot(CHEM_RESULTS$`N as NOx (ug/L)`)+
ggtitle("QQ Plot NOx (ug/L)")
not normally distributed.
shapiro.test(CHEM_RESULTS$`N as NOx (ug/L)`)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$`N as NOx (ug/L)`
## W = 0.85527, p-value = 0.0163
not normally distributed p value <0.05.
set.seed(0)
ggqqplot(CHEM_RESULTS$`Total Dissolved N (ug/L)`)+
ggtitle("QQ Plot Total Dissolved N (ug/L)")+
theme(text = element_text(family = "Times New Roman", size= 14))
not normally distributed.
shapiro.test(CHEM_RESULTS$`Total Dissolved N (ug/L)`)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$`Total Dissolved N (ug/L)`
## W = 0.92373, p-value = 0.1936
Shapiro Wilk test p value >0.05 normally distributed.
ggdensity(CHEM_RESULTS$`Total Dissolved N (ug/L)`, fill = "seagreen4")+
ggtitle("Density Plot for Total Dissolved N (ug/L)")+
theme(text = element_text(family = "Times New Roman", size= 14))
can see the bell curve but a bit skewed in lower/ upper values. Therefore I think safe to treat as if not normally distributed.
set.seed(0)
ggqqplot(CHEM_RESULTS$`Total Dissolved P (ug/L)`)+
ggtitle("QQ Plot Total Dissolved P (ug/L)")
-pretty close !
have a look at density plot to have more clarity:
ggdensity(CHEM_RESULTS$`Total Dissolved P (ug/L)`, fill = "seagreen4")+
ggtitle("Density Plot for Total Dissolved P (ug/L)")
not quite lol.
shapiro.test(CHEM_RESULTS$`Total Dissolved P (ug/L)`)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$`Total Dissolved P (ug/L)`
## W = 0.54364, p-value = 4.984e-06
P value <0.05 therefore not normally distributed.
set.seed(0)
ggqqplot(CHEM_RESULTS$`P as P04 (ug/L)`)+
ggtitle("QQ Plot P as PO4 (ug/L)")+
theme(text = element_text(family = "Times New Roman", size= 14))
not normally distributed.
shapiro.test(CHEM_RESULTS$`P as P04 (ug/L)`)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$`P as P04 (ug/L)`
## W = 0.8493, p-value = 0.0133
p value <0.05 based on Shapiro Wilk - not normally distributed.
check density:
ggdensity(CHEM_RESULTS$`P as P04 (ug/L)`, fill = "seagreen4")+
ggtitle("Density Plot for P as P04 (ug/L)")+
theme(text = element_text(family = "Times New Roman", size= 14))
+ve skewed.
set.seed(0)
ggqqplot(CHEM_RESULTS$`N as NH4 (ug/L)`)+
ggtitle("QQ Plot N as NH4 (ug/L)")
not normally distributed.
shapiro.test(CHEM_RESULTS$`N as NH4 (ug/L)`)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$`N as NH4 (ug/L)`
## W = 0.89504, p-value = 0.06697
p value just greater than 0.05 therefore normally distributed based on Shapiro.
ggdensity(CHEM_RESULTS$`N as NH4 (ug/L)`, fill = "seagreen4")+
ggtitle("Density Plot for N as NH4 (ug/L)")
however density/ QQ plot indicate being able to treat it as not normal for convenience/ consistency.
set.seed(0)
ggqqplot(CHEM_RESULTS$pH)+
ggtitle("QQ Plot for pH")
close-ish
out of curosity:
ggdensity(CHEM_RESULTS$pH, fill = "seagreen4")+
ggtitle("Density Plot for pH")
shapiro.test(CHEM_RESULTS$pH)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$pH
## W = 0.94547, p-value = 0.4215
pH is normally distributed based on Shapiro Wilk p-value>0.05.
set.seed(0)
ggqqplot(CHEM_RESULTS$`Dissolved oxygen (% saturation)`)+
ggtitle("QQ Plot for Dissolved oxygen (% saturation)")
ohhh could be normally distributed.
ggdensity(CHEM_RESULTS$`Dissolved oxygen (% saturation)`, fill = "seagreen4")+
ggtitle("Density Plot for DO (% saturation)")
yay !
shapiro.test(CHEM_RESULTS$`Dissolved oxygen (% saturation)`)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$`Dissolved oxygen (% saturation)`
## W = 0.94985, p-value = 0.4874
voila - above p critical 0.05 assume normaly distributed.
set.seed(0)
ggqqplot(CHEM_RESULTS$`Turbidity (NTU)`)+
ggtitle("QQ Plot for Turbidity (NTU)")
shapiro.test(CHEM_RESULTS$`Turbidity (NTU)`)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$`Turbidity (NTU)`
## W = 0.94431, p-value = 0.4051
p value >0.05 therefore assume normally distributed.
ggdensity(CHEM_RESULTS$`Turbidity (NTU)`, fill = "seagreen4")+
ggtitle("Density Plot for Turbidity (NTU)")
would probably be appropriate to treat as either given small sample size / graphs on the “borderline”.
set.seed(0)
ggqqplot(CHEM_RESULTS$Salinity)+
ggtitle("QQ Plot for Salinity")
shapiro.test(CHEM_RESULTS$Salinity)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$Salinity
## W = 0.95086, p-value = 0.5035
normally distributed p value >0.05.
set.seed(0)
ggqqplot(CHEM_RESULTS$`Total Suspended Solids (mg/L)`)+
ggtitle("QQ Plot for TSS (mg/L")
shapiro.test(CHEM_RESULTS$`Total Suspended Solids (mg/L)`)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$`Total Suspended Solids (mg/L)`
## W = 0.40526, p-value = 3.828e-07
not normally distributed p value 0.05.
set.seed(0)
ggdensity(CHEM_RESULTS$`Total Suspended Solids (mg/L)`, fill = "seagreen4")+
ggtitle("Density Plot for TSS")
outlier.
set.seed(0)
ggqqplot(CHEM_RESULTS$`Temperature (°C)`)+
ggtitle("QQ Plot for Temperature")
shapiro.test(CHEM_RESULTS$`Temperature (°C)`)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$`Temperature (°C)`
## W = 0.83757, p-value = 0.00899
not normally distributed p value <0.05.
set.seed(0)
ggqqplot(CHEM_RESULTS$`Electrical conductivity`)+
ggtitle("QQ Plot for Conductivity")
not normally distributed due 2 outliers.
shapiro.test(CHEM_RESULTS$`Electrical conductivity`)
##
## Shapiro-Wilk normality test
##
## data: CHEM_RESULTS$`Electrical conductivity`
## W = 0.53408, p-value = 4.116e-06
not normally distributed. Therefore all variables EXCEPT pH and DO will be treated as not normally distributed.
library(corrplot)
## corrplot 0.92 loaded
cor_chem<- CHEM_RESULTS[ -c(1:2) ]
head(cor_chem)
## # A tibble: 6 × 13
## `Enterococci (CFU/100 mL)` `N as NOx (ug/L)` `Total Dissolved N (ug/L)`
## <dbl> <dbl> <dbl>
## 1 67 30.1 134.
## 2 60 9.36 50.3
## 3 15 4.21 44.4
## 4 25 6.86 39.9
## 5 47 85.9 153.
## 6 110 72.4 134.
## # ℹ 10 more variables: `Total Dissolved P (ug/L)` <dbl>,
## # `P as P04 (ug/L)` <dbl>, `N as NH4 (ug/L)` <dbl>, `Turbidity (NTU)` <dbl>,
## # `Dissolved oxygen (% saturation)` <dbl>, pH <dbl>, Salinity <dbl>,
## # `Total Suspended Solids (mg/L)` <dbl>, `Temperature (°C)` <dbl>,
## # `Electrical conductivity` <dbl>
corrplot(cor(cor_chem), main="Correlation Plot of Water quality Measurements",
mar=c(0,0,2,0))
spearman.cor = cor(cor_chem, method = c("spearman"))
print(spearman.cor)
## Enterococci (CFU/100 mL) N as NOx (ug/L)
## Enterococci (CFU/100 mL) 1.0000000 0.66764706
## N as NOx (ug/L) 0.6676471 1.00000000
## Total Dissolved N (ug/L) 0.4676471 0.64117647
## Total Dissolved P (ug/L) 0.6764706 0.55588235
## P as P04 (ug/L) 0.7235294 0.89117647
## N as NH4 (ug/L) 0.2176471 0.16764706
## Turbidity (NTU) 0.5200143 0.09037285
## Dissolved oxygen (% saturation) -0.6004417 -0.59749832
## pH -0.6671583 -0.76877845
## Salinity -0.7181753 -0.70345862
## Total Suspended Solids (mg/L) 0.2500000 -0.22352941
## Temperature (°C) 0.1799418 0.18879138
## Electrical conductivity -0.5445182 -0.40912447
## Total Dissolved N (ug/L)
## Enterococci (CFU/100 mL) 0.46764706
## N as NOx (ug/L) 0.64117647
## Total Dissolved N (ug/L) 1.00000000
## Total Dissolved P (ug/L) 0.06176471
## P as P04 (ug/L) 0.56176471
## N as NH4 (ug/L) 0.64117647
## Turbidity (NTU) 0.05185327
## Dissolved oxygen (% saturation) -0.27814577
## pH -0.80412458
## Salinity -0.51066975
## Total Suspended Solids (mg/L) -0.15294118
## Temperature (°C) -0.28613694
## Electrical conductivity -0.58425329
## Total Dissolved P (ug/L) P as P04 (ug/L)
## Enterococci (CFU/100 mL) 0.67647059 0.72352941
## N as NOx (ug/L) 0.55588235 0.89117647
## Total Dissolved N (ug/L) 0.06176471 0.56176471
## Total Dissolved P (ug/L) 1.00000000 0.66764706
## P as P04 (ug/L) 0.66764706 1.00000000
## N as NH4 (ug/L) -0.30882353 0.15000000
## Turbidity (NTU) 0.22815441 0.24296963
## Dissolved oxygen (% saturation) -0.62987508 -0.59308331
## pH -0.39469851 -0.68483138
## Salinity -0.76821213 -0.71670365
## Total Suspended Solids (mg/L) 0.22352941 -0.02941176
## Temperature (°C) 0.64897038 0.24483882
## Electrical conductivity -0.20014722 -0.41059614
## N as NH4 (ug/L) Turbidity (NTU)
## Enterococci (CFU/100 mL) 0.21764706 0.52001427
## N as NOx (ug/L) 0.16764706 0.09037285
## Total Dissolved N (ug/L) 0.64117647 0.05185327
## Total Dissolved P (ug/L) -0.30882353 0.22815441
## P as P04 (ug/L) 0.15000000 0.24296963
## N as NH4 (ug/L) 1.00000000 0.26222942
## Turbidity (NTU) 0.26222942 1.00000000
## Dissolved oxygen (% saturation) -0.19720388 -0.16012217
## pH -0.52282825 -0.19881656
## Salinity -0.05298015 -0.14233082
## Total Suspended Solids (mg/L) -0.24705882 0.38371423
## Temperature (°C) -0.64012078 0.02971798
## Electrical conductivity -0.25312737 -0.49964047
## Dissolved oxygen (% saturation) pH
## Enterococci (CFU/100 mL) -0.60044166 -0.66715831
## N as NOx (ug/L) -0.59749832 -0.76877845
## Total Dissolved N (ug/L) -0.27814577 -0.80412458
## Total Dissolved P (ug/L) -0.62987508 -0.39469851
## P as P04 (ug/L) -0.59308331 -0.68483138
## N as NH4 (ug/L) -0.19720388 -0.52282825
## Turbidity (NTU) -0.16012217 -0.19881656
## Dissolved oxygen (% saturation) 1.00000000 0.70302156
## pH 0.70302156 1.00000000
## Salinity 0.79381443 0.78113507
## Total Suspended Solids (mg/L) 0.23546732 0.15022108
## Temperature (°C) -0.43394940 -0.02067949
## Electrical conductivity 0.06038292 0.47162872
## Salinity Total Suspended Solids (mg/L)
## Enterococci (CFU/100 mL) -0.71817532 0.25000000
## N as NOx (ug/L) -0.70345862 -0.22352941
## Total Dissolved N (ug/L) -0.51066975 -0.15294118
## Total Dissolved P (ug/L) -0.76821213 0.22352941
## P as P04 (ug/L) -0.71670365 -0.02941176
## N as NH4 (ug/L) -0.05298015 -0.24705882
## Turbidity (NTU) -0.14233082 0.38371423
## Dissolved oxygen (% saturation) 0.79381443 0.23546732
## pH 0.78113507 0.15022108
## Salinity 1.00000000 -0.03826344
## Total Suspended Solids (mg/L) -0.03826344 1.00000000
## Temperature (°C) -0.51660643 0.04719785
## Electrical conductivity 0.39911635 -0.36497434
## Temperature (°C) Electrical conductivity
## Enterococci (CFU/100 mL) 0.17994179 -0.54451818
## N as NOx (ug/L) 0.18879138 -0.40912447
## Total Dissolved N (ug/L) -0.28613694 -0.58425329
## Total Dissolved P (ug/L) 0.64897038 -0.20014722
## P as P04 (ug/L) 0.24483882 -0.41059614
## N as NH4 (ug/L) -0.64012078 -0.25312737
## Turbidity (NTU) 0.02971798 -0.49964047
## Dissolved oxygen (% saturation) -0.43394940 0.06038292
## pH -0.02067949 0.47162872
## Salinity -0.51660643 0.39911635
## Total Suspended Solids (mg/L) 0.04719785 -0.36497434
## Temperature (°C) 1.00000000 0.09446518
## Electrical conductivity 0.09446518 1.00000000
relationships of interest, from management perspective I want to look at nutrients & Enterococci being introduced into aquatic environment and affect on Water Quality Parameter. Or if similar sources (high correlation) potentially finding how can mitigate: -Enterococci and P as P04 (ug/L) 0.72352941 -P as P04 (ug/L) and NOx 0.89117647 -Enterococci and TDP 0.67647059 - NH4 & Temp -0.64012078
cor1 <- cor.test(x=cor_chem$`Enterococci (CFU/100 mL)`,
y=cor_chem$`P as P04 (ug/L)`, method = 'spearman')
cor1
##
## Spearman's rank correlation rho
##
## data: cor_chem$`Enterococci (CFU/100 mL)` and cor_chem$`P as P04 (ug/L)`
## S = 188, p-value = 0.002174
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.7235294
rho
0.7235294 p value = 0.00217
cor2 <- cor.test(x=cor_chem$`N as NOx (ug/L)`,
y=cor_chem$`P as P04 (ug/L)`, method = 'spearman')
cor2
##
## Spearman's rank correlation rho
##
## data: cor_chem$`N as NOx (ug/L)` and cor_chem$`P as P04 (ug/L)`
## S = 74, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.8911765
rho
0.8911765 p-value < 2.2e-16
cor3 <- cor.test(x=cor_chem$`Enterococci (CFU/100 mL)`,
y=cor_chem$`Total Dissolved P (ug/L)`, method = 'spearman')
cor3
##
## Spearman's rank correlation rho
##
## data: cor_chem$`Enterococci (CFU/100 mL)` and cor_chem$`Total Dissolved P (ug/L)`
## S = 220, p-value = 0.005147
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.6764706
rho
0.6764706 p-value = 0.005147
cor4 <- cor.test(x=cor_chem$`N as NH4 (ug/L)`,
y=cor_chem$`Temperature (°C)`, method = 'spearman')
## Warning in cor.test.default(x = cor_chem$`N as NH4 (ug/L)`, y =
## cor_chem$`Temperature (°C)`, : Cannot compute exact p-value with ties
cor4
##
## Spearman's rank correlation rho
##
## data: cor_chem$`N as NH4 (ug/L)` and cor_chem$`Temperature (°C)`
## S = 1115.3, p-value = 0.007564
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.6401208
p-value = 0.007564 rho -0.6401208