Question 1

A COVID frontliner wants to estimate the average amount that a resident in Maramag would donate to COVID affected families in Maramag. Twenty residents were randomly selected from the Municipality of Maramag. The 20 randomly residents were contacted by telephone and asked how much they would be willing to donate. Their responses are given below.

30 20 15 8 10 40 20 25 20 28 20 25 50 40 20 10 25 25 20 15

1.1 Test at 0.05 level of significance using R for a two-tailed test.

z <- c(30, 20, 15, 8, 10, 40, 20, 25, 20, 28, 20, 25, 50, 40, 20, 10, 25, 25, 20, 15)

Null Hypothesis: The average amount that a resident in Maramag would donate to COVID affected families in Maramag is mean mu = 23.3.

Alternative Hypothesis: The average amount that a resident in Maramag would donate to COVID affected families in Maramag is mean mu > 23.3.

z
 [1] 30 20 15  8 10 40 20 25 20 28 20 25 50 40 20 10 25 25 20 15
t.test(x = z, alternative = "two.sided", mu = 20)

    One Sample t-test

data:  z
t = 1.3905, df = 19, p-value = 0.1804
alternative hypothesis: true mean is not equal to 20
95 percent confidence interval:
 18.33282 28.26718
sample estimates:
mean of x 
     23.3 

Given the high p-value, we fail to reject the null hypothesis that the mean is equal to 20. That is, there is no enough evidence to prove that Maramag residents would donate more than 20.

1.2 Test at 0.05 level of significance using R for a an appropriate one-tailed test.

Case 1:

Null Hypothesis: The average amount that a resident in Maramag would donate to COVID affected families in Maramag is mean mu = 23.3.

Alternative Hypothesis: The average amount that a resident in Maramag would donate to COVID affected families in Maramag is mean mu < 23.3.

#Less than
t.test(x = z,
       alternative = "less",
       mu = 20)

    One Sample t-test

data:  z
t = 1.3905, df = 19, p-value = 0.9098
alternative hypothesis: true mean is less than 20
95 percent confidence interval:
     -Inf 27.40359
sample estimates:
mean of x 
     23.3 

Since the p value is less than the significance level 0.05, we fail to reject the null hypothesis. That is, there is no enough evidence to prove that Maramag residents would donate more than 20.

Case 2:

Null Hypothesis: The average amount that a resident in Maramag would donate to COVID affected families in Maramag is mean mu = 23.3.

Alternative Hypothesis: The average amount that a resident in Maramag would donate to COVID affected families in Maramag is mean mu > 23.3.

#Greater than
t.test(x = z,
       alternative = "greater",
       mu = 20)

    One Sample t-test

data:  z
t = 1.3905, df = 19, p-value = 0.09022
alternative hypothesis: true mean is greater than 20
95 percent confidence interval:
 19.19641      Inf
sample estimates:
mean of x 
     23.3 

Since the p value is greater than the significance level 0.05, we fail to reject the null hypothesis. That is, there is no enough evidence to prove that Maramag residents would donate more than 20

Question 2

library(readxl)
pgviews <- read_excel("D:/MARV BS MATH/Marv 4th year, 1st sem/Regression Analysis/pgviews.xlsx")
View(pgviews)

Refer to the pgviews data, answer the following:

2.1 Is the distribution of the data normally distributed?

Null Hypothesis: The data is normally distributed.

Alternative Hypothesis: The data is not normally distributed.

Marv <- head(pgviews , 20)
Marv
# A tibble: 20 × 3
   Subject Site  Pages
     <dbl> <chr> <dbl>
 1       1 B         2
 2       2 B         6
 3       3 A         5
 4       4 B         7
 5       5 A         3
 6       6 B         2
 7       7 B         6
 8       8 A         1
 9       9 A         3
10      10 A         4
11      11 B         6
12      12 B         6
13      13 B         4
14      14 A         5
15      15 A         3
16      16 A         6
17      17 B         6
18      18 B         3
19      19 A         4
20      20 B         7
shapiro.test(Marv$Pages)

    Shapiro-Wilk normality test

data:  Marv$Pages
W = 0.92449, p-value = 0.1209

From the output, the p-value > 0.05 implying that the distribution of the data are not significantly different from normal distribution. In other words, we can assume normality.

2.2 Are the variances equal?

str(Marv)
tibble [20 × 3] (S3: tbl_df/tbl/data.frame)
 $ Subject: num [1:20] 1 2 3 4 5 6 7 8 9 10 ...
 $ Site   : chr [1:20] "B" "B" "A" "B" ...
 $ Pages  : num [1:20] 2 6 5 7 3 2 6 1 3 4 ...
var.test(Pages ~ Site, Marv, alternative = "two.sided")

    F test to compare two variances

data:  Pages by Site
F = 0.60957, num df = 8, denom df = 10, p-value = 0.4948
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.1581284 2.6181715
sample estimates:
ratio of variances 
         0.6095679 

The p-value is greater than the significance level of 0.05. We can conclude that there is no significant difference between the variances.

2.3 At 0.05 level of significance, does Site A and Site B differ statistically?

t.test(Pages ~ Site, Marv, var.equal = TRUE)

    Two Sample t-test

data:  Pages by Site
t = -1.5765, df = 18, p-value = 0.1323
alternative hypothesis: true difference in means between group A and group B is not equal to 0
95 percent confidence interval:
 -2.8510432  0.4065987
sample estimates:
mean in group A mean in group B 
       3.777778        5.000000 

The p-value of the test is 0.1323, which is greater than the significance level alpha = 0.05. Hence, we do not have enough evidences to prove that A’s average Pages is significantly different from B’s average Pages with a p-value = 0.1323.

Question 3

Two medications for the treatment of panic disorder, Medication1 and Medication 2, were compared with a placebo. A random sample of 36 patients was obtained from a listing of about 4,000 panic disorder patients who volunteered to participate in clinical trials. The 36 patients were randomly divided into three groups of equal size. The first group received Medication 1 for 10 weeks, the second group received Medication 2 for 10 weeks, and the third group received a placebo pill for 10 weeks. On week 11, all 36 patients were given the 7-item Panic Disorder Severity Scale (PDSC) which is scored on a 0 to 28 scale (lower scores are better). The PDSC scores are given below.

Group 1: 12 10 11 14 15 9 11 12 13 10 15 10

Group 2: 12 13 17 11 16 13 12 14 17 12 16 18

Group 3: 14 21 17 16 17 22 16 22 19 20 18 16

3.1 Is the distribution of the data normally distributed?

library(readxl)
Marv2 <- read_excel("D:/MARV BS MATH/Marv 4th year, 1st sem/Regression Analysis/Marv2.xlsx")
View(Marv2)
str(Marv2)
tibble [36 × 2] (S3: tbl_df/tbl/data.frame)
 $ Treatment  : chr [1:36] "Group 1" "Group 1" "Group 1" "Group 1" ...
 $ Observation: num [1:36] 12 10 11 14 15 9 11 12 13 10 ...
shapiro.test(Marv2$Observation)
## 
##  Shapiro-Wilk normality test
## 
## data:  Marv2$Observation
## W = 0.95851, p-value = 0.1933

From the output, the p-value > 0.05 implying that the distribution of the data are not significantly different from normal distribution. In other words, we can assume normality.

3.2 Are the variances equal?

res <- bartlett.test(Observation ~ Treatment, data = Marv2)
res

    Bartlett test of homogeneity of variances

data:  Observation by Treatment
Bartlett's K-squared = 0.67864, df = 2, p-value = 0.7123

The p-value is 0.7123 is greater than the significance level of 0.05. We can conclude that there is no significant difference between the variances.

3.3 At 0.05 level of significance, does the PDSC scores differ significantly among the different treatments?

Marv3 <- head(Marv2, 36)
Marv3
## # A tibble: 36 × 2
##    Treatment Observation
##    <chr>           <dbl>
##  1 Group 1            12
##  2 Group 1            10
##  3 Group 1            11
##  4 Group 1            14
##  5 Group 1            15
##  6 Group 1             9
##  7 Group 1            11
##  8 Group 1            12
##  9 Group 1            13
## 10 Group 1            10
## # … with 26 more rows
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library("ggpubr")
## Loading required package: ggplot2
library("gplots")
## 
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
## 
##     lowess
set.seed(123)
dplyr::sample_n(Marv2, 10)
## # A tibble: 10 × 2
##    Treatment Observation
##    <chr>           <dbl>
##  1 Group 3            16
##  2 Group 2            17
##  3 Group 2            13
##  4 Group 1            11
##  5 Group 1            10
##  6 Group 2            13
##  7 Group 2            12
##  8 Group 1            15
##  9 Group 1            15
## 10 Group 2            14
group_by(Marv3, Treatment) %>%
  summarise(
    count = n(),
    mean = mean(Observation, na.rm = TRUE),
    sd = sd(Observation, na.rm = TRUE)
  )
## # A tibble: 3 × 4
##   Treatment count  mean    sd
##   <chr>     <int> <dbl> <dbl>
## 1 Group 1      12  11.8  2.04
## 2 Group 2      12  14.2  2.42
## 3 Group 3      12  18.2  2.62
Marv3$Treatment <- ordered(Marv3$Treatment,
                         levels = c("Group 1", "Group 2", "Group 3"))
levels(Marv3$Treatment)
## [1] "Group 1" "Group 2" "Group 3"
library("ggpubr")
ggboxplot(Marv3, x = "Treatment", y = "Observation",
          color = "Treatment", palette = c("#00AFBB", "#E7B800", "#FC4E07"),
          order = c("Group 1", "Group 2", "Group 3"),
          ylab = "Observation", xlab = "Treatment")

ggline(Marv3, x = "Treatment", y = "Observation",
       add = c("mean_se", "jitter"),
       order = c("Group 1", "Group 2", "Group 3"),
       ylab = "Observation", xlab = "Treatment")

plotmeans(Observation ~ Treatment, data = Marv3, frame = FALSE,
          xlab = "Treatment", ylab = "Observation",
          main="Mean Plot with 95% CI")
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "frame" is not a
## graphical parameter
## Warning in axis(1, at = 1:length(means), labels = legends, ...): "frame" is not
## a graphical parameter
## Warning in plot.xy(xy.coords(x, y), type = type, ...): "frame" is not a
## graphical parameter

res.aov <- aov(Observation ~ Treatment, data = Marv2)
summary(res.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## Treatment    2  245.2  122.58    21.8 9.25e-07 ***
## Residuals   33  185.6    5.62                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

We can conclude that there are significant differences between the treatments highlighted with “***” in the model summary because the p-value is less than the significance level of 0.05.

3.4 Use R for the conduct of multiple comparison test provided that 3.3 is significant.

TukeyHSD(res.aov)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Observation ~ Treatment, data = Marv2)
## 
## $Treatment
##                     diff        lwr      upr     p adj
## Group 2-Group 1 2.416667 0.04105701 4.792276 0.0454940
## Group 3-Group 1 6.333333 3.95772367 8.708943 0.0000006
## Group 3-Group 2 3.916667 1.54105701 6.292276 0.0008425

The difference between Group 2 and Group 1 is significant, as shown by the output, with an adjusted p-value of 0.0454940. The difference between Group 3 and Group 1 is significant, as shown by the output, with an adjusted p-value of 0.0000006. The difference between Group 3 and Group 2 is significant, as shown by the output, with an adjusted p-value of 0.0008425.