Loading required package: multcomp
Loading required package: mvtnorm
Loading required package: survival
Loading required package: TH.data
Loading required package: MASS
Attaching package: 'MASS'
The following object is masked from 'package:dplyr':
select
Attaching package: 'TH.data'
The following object is masked from 'package:MASS':
geyser
Rows: 369 Columns: 3
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): Gender
dbl (2): ID, TnI Conc
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
ggplot(dataset, aes(x = tni_conc, y =stat(density))) +geom_histogram() +labs(x ="Troponin I", y ="Density")
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
dt <- dataset %>%filter(tni_conc <900)
One sample histogram
ggplot(dt, aes(x = tni_conc, y =after_stat(density))) +geom_histogram() +labs(x ="Troponin I", y ="Density")
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
One Sample z-test
# Testing using the R-package BSDAz.test(x = dt$tni_conc, alternative ="two.sided", mu =2, sigma.x =1)
One-sample z-Test
data: dt$tni_conc
z = -11.265, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 2
95 percent confidence interval:
1.310603 1.514943
sample estimates:
mean of x
1.412773
z.test(x = dt$tni_conc, alternative ="greater", mu =2, sigma.x =1)
One-sample z-Test
data: dt$tni_conc
z = -11.265, p-value = 1
alternative hypothesis: true mean is greater than 2
95 percent confidence interval:
1.327029 NA
sample estimates:
mean of x
1.412773
z.test(x = dt$tni_conc, alternative ="less", mu =2, sigma.x =1)
One-sample z-Test
data: dt$tni_conc
z = -11.265, p-value < 2.2e-16
alternative hypothesis: true mean is less than 2
95 percent confidence interval:
NA 1.498517
sample estimates:
mean of x
1.412773
# Calculating the Z-scorez_score <- (mean(dt$tni_conc) -2)/sqrt(1/nrow(dt))# Calculating p valuepnorm(z_score, mean =0, sd =1)
[1] 9.771756e-30
p_value <-2*(1-pnorm(z_score, mean =0, sd =1))# Variance of our datasd(dt$tni_conc)
[1] 3.571236
sd(dt$tni_conc)^2
[1] 12.75372
var(dt$tni_conc)
[1] 12.75372
One Sample t-test
### t test# Testingt.test(x = dt$tni_conc, alternative ="two.sided", mu =2)
One Sample t-test
data: dt$tni_conc
t = -3.1544, df = 367, p-value = 0.001741
alternative hypothesis: true mean is not equal to 2
95 percent confidence interval:
1.046692 1.778854
sample estimates:
mean of x
1.412773
t.test(x = dt$tni_conc, alternative ="greater", mu =2)
One Sample t-test
data: dt$tni_conc
t = -3.1544, df = 367, p-value = 0.9991
alternative hypothesis: true mean is greater than 2
95 percent confidence interval:
1.105787 Inf
sample estimates:
mean of x
1.412773
t.test(x = dt$tni_conc, alternative ="less", mu =2)
One Sample t-test
data: dt$tni_conc
t = -3.1544, df = 367, p-value = 0.0008706
alternative hypothesis: true mean is less than 2
95 percent confidence interval:
-Inf 1.71976
sample estimates:
mean of x
1.412773
# Calculating the T-scoret_score <- (mean(dt$tni_conc) -2)/sqrt(var(dt$tni_conc)/nrow(dt))# p-value for the two-sided testpt(t_score, df = (nrow(dt) -1))
[1] 0.0008705882
p_value <-2*pt(t_score, df = (nrow(dt) -1))
Two sample histogram
ggplot(dt, aes(x = tni_conc, y =stat(density), fill = gender)) +geom_histogram() +facet_grid(. ~ gender, labeller =labeller(gender = label_both)) +theme(legend.position ="none") +labs(x ="Troponin I", y ="Density")
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Student t-test for two samples with equal variance
# t test with var.equal = TRUEt.test(tni_conc ~ gender, alternative ="two.sided", var.equal =TRUE,paired =FALSE, data = dt)
Two Sample t-test
data: tni_conc by gender
t = -2.5462, df = 366, p-value = 0.0113
alternative hypothesis: true difference in means between group F and group M is not equal to 0
95 percent confidence interval:
-1.6678834 -0.2142782
sample estimates:
mean in group F mean in group M
0.9371183 1.8781991
t.test(tni_conc ~ gender, alternative ="greater", var.equal =TRUE,paired =FALSE, data = dt)
Two Sample t-test
data: tni_conc by gender
t = -2.5462, df = 366, p-value = 0.9944
alternative hypothesis: true difference in means between group F and group M is greater than 0
95 percent confidence interval:
-1.550558 Inf
sample estimates:
mean in group F mean in group M
0.9371183 1.8781991
t.test(tni_conc ~ gender, alternative ="less", var.equal =TRUE,paired =FALSE, data = dt)
Two Sample t-test
data: tni_conc by gender
t = -2.5462, df = 366, p-value = 0.005649
alternative hypothesis: true difference in means between group F and group M is less than 0
95 percent confidence interval:
-Inf -0.3316031
sample estimates:
mean in group F mean in group M
0.9371183 1.8781991
# A tibble: 2 × 2
gender var
<chr> <dbl>
1 F 2.38
2 M 22.5
Welch t-test for two samples with unequal variance
t.test(tni_conc ~ gender, alternative ="two.sided", var.equal =FALSE,paired =FALSE, data = dt)
Welch Two Sample t-test
data: tni_conc by gender
t = -2.5688, df = 224.42, p-value = 0.01085
alternative hypothesis: true difference in means between group F and group M is not equal to 0
95 percent confidence interval:
-1.6630143 -0.2191473
sample estimates:
mean in group F mean in group M
0.9371183 1.8781991
t.test(tni_conc ~ gender, alternative ="greater", var.equal =FALSE,paired =FALSE, data = dt)
Welch Two Sample t-test
data: tni_conc by gender
t = -2.5688, df = 224.42, p-value = 0.9946
alternative hypothesis: true difference in means between group F and group M is greater than 0
95 percent confidence interval:
-1.546177 Inf
sample estimates:
mean in group F mean in group M
0.9371183 1.8781991
t.test(tni_conc ~ gender, alternative ="less", var.equal =FALSE,paired =FALSE, data = dt)
Welch Two Sample t-test
data: tni_conc by gender
t = -2.5688, df = 224.42, p-value = 0.005427
alternative hypothesis: true difference in means between group F and group M is less than 0
95 percent confidence interval:
-Inf -0.3359845
sample estimates:
mean in group F mean in group M
0.9371183 1.8781991
Warning in cvm.test(dt$tni_conc[dt$gender == "F"]): p-value is smaller than
7.37e-10, cannot be computed more accurately
Cramer-von Mises normality test
data: dt$tni_conc[dt$gender == "F"]
W = 6.0311, p-value = 7.37e-10
cvm.test(dt$tni_conc[dt$gender =="M"])
Warning in cvm.test(dt$tni_conc[dt$gender == "M"]): p-value is smaller than
7.37e-10, cannot be computed more accurately
Cramer-von Mises normality test
data: dt$tni_conc[dt$gender == "M"]
W = 8.2575, p-value = 7.37e-10
Variance test
levene.test(dt$tni_conc, group = dt$gender)
Modified robust Brown-Forsythe Levene-type test based on the absolute
deviations from the median
data: dt$tni_conc
Test Statistic = 3.5679, p-value = 0.0597
Wilcoxon rank sum test with continuity correction
data: dt$tni_conc by dt$gender
W = 9690, p-value = 1.324e-12
alternative hypothesis: true location shift is not equal to 0
95 percent confidence interval:
-0.4386174 -0.2453333
sample estimates:
difference in location
-0.336053
# Storing the results from a Wilcox testtest <-wilcox.test(dt$tni_conc ~ dt$gender,alternative ="two.sided",paired =FALSE, conf.int =TRUE,conf.level =0.95)test
Wilcoxon rank sum test with continuity correction
data: dt$tni_conc by dt$gender
W = 9690, p-value = 1.324e-12
alternative hypothesis: true location shift is not equal to 0
95 percent confidence interval:
-0.4386174 -0.2453333
sample estimates:
difference in location
-0.336053
#-----Nonparametric Test Procedures and Confidence Intervals for relative effects-----#
- Alternative Hypothesis: True relative effect p is less or equal than 1/2
- Confidence level: 95 %
- Method = Brunner - Munzel - T - Approx with 318.265 DF
#---------------------------Interpretation---------------------------------------------#
p(a,b) > 1/2 : b tends to be larger than a
#--------------------------------------------------------------------------------------#
#----Data Info-------------------------------------------------------------------------#
Sample Size
F F 182
M M 186
#----Analysis--------------------------------------------------------------------------#
Effect Estimator Lower Upper T p.Value
1 p(F,M) 0.714 0.66 0.767 7.835 0
Adding p-values to a box-plot
#install.packages("ggsignif")library(ggsignif)
test <-t.test(tni_conc ~ gender, alternative ="two.sided", var.equal =FALSE,paired =FALSE, data = dt)# Adding p-values to plotsls(test)