You are on page 1of 5

Problem 1 - A sample of 12 residents was asked about their satisfaction level on garbage collection services

before and after privatization by their local authority. Their rating on a 1 – 10 Likert scale, where 1 represents
“Least Satisfied” and 10 denotes “Completely Satisfied”, are given in Table 3:

At 97.5% confidence level, can we conclude that the residents are more satisfied with the garbage collection
after the privatization?

Significance level, α = 1-confidence level


α = 1- 0.975 = 0.025
To find if they are more satisfied or not, we compare between the average scores :
Ho: μ(after) - μ(before) privatization = 0 (No change in satisfaction)
Hα: μ (after) - μ(before) privatization > 0 (More satisfied)

Paired data (same 12 residents, need to compare) , thus paired t-test.

Input Output

#Data sets for testing > #Data sets for testing


bfrpriv <- c(4,7,6,6,7,5,7,6,8,8,6,6) > bfrpriv <- c(4,7,6,6,7,5,7,6,8,8,6,6)
> aftpriv<- c(4,8,7,9,8,5,7,8,9,8,6,4)
aftpriv<- c(4,8,7,9,8,5,7,8,9,8,6,4)

#inspecting data > setwd("C:/Users/Dex/Downloads/Telegram


print(beforeafter) Desktop/Quantitative test")
> #import data from file
summary(beforeafter)
> library(readr)
> beforeafter <- read.csv("BeforeAfter.csv")
> #inspecting data
> print(beforeafter)
Resident Before After
1 1 4 4
2 2 7 8
3 3 6 7
4 4 6 9
5 5 7 8
6 6 5 5
7 7 7 7
8 8 6 8
9 9 8 9
10 10 8 8
11 11 6 6
12 12 6 4
> summary(beforeafter)
Resident Before After
Min. : 1.00 Min. :4.000 Min. :4.000
1st Qu.: 3.75 1st Qu.:6.000 1st Qu.:5.750
Median : 6.50 Median :6.000 Median :7.500
Mean : 6.50 Mean :6.333 Mean :6.917
3rd Qu.: 9.25 3rd Qu.:7.000 3rd Qu.:8.000
Max. :12.00 Max. :8.000 Max. :9.000

#perform ANOVA > anovaResult <- aov(After ~ Before, data = beforeafter)


anovaResult <- aov(After ~ Before, data = > summary.aov(anovaResult)
Df Sum Sq Mean Sq F value Pr(>F)
beforeafter)
Before 1 18.19 18.189 10.87 0.00805 **
summary.aov(anovaResult) Residuals 10 16.73 1.673
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1
‘ ’ 1
mean difference
-0.5833333

Answer :
p-value = 0.00805 < α = 0.025
Hence, H0 is rejected. The residents are more satisfied with the garbage collection after the privatization. However,
the difference in mean between after and before is 0.58333.
Problem 2 - A study on the annual arrival of Hong Kong tourists to Penang and Johor was conducted. For each of
these states, tourist arrivals (in thousand persons/year) were recorded for six years, between 2014 and 2019.

At 0.05 level of significance, does the average annual tourist arrival from Hong Kong is higher for Penang than for
Johor?

Significance level, α = 0.05


Ho: μ penang-μ johor = 0 ( Higher for Johor)
Hα: μ penang-μ johor > 0 ( Higher for Penang)

Input Output

#Datasets for testing > #Datasets for testing


x1 <- c(35,42,42,43,47,52) > x1 <- c(35,42,42,43,47,52)
> x2 <- c(26,30,32,32,32,34)
x2 <- c(26,30,32,32,32,34)

#hypothesis test Welch Two Sample t-test


t.test(x1,x2,mu=0, alternative="greater",
paired=FALSE,var.equal=FALSE,conf.level=0.95) data: x1 and x2
t = 4.8473, df = 7.2295, p-value = 0.0008502
alternative hypothesis: true difference in
means is greater than 0
95 percent confidence interval:
7.637572 Inf
sample estimates:
mean of x mean of y
43.5 31.0

Mean of x (Penang) is 43.5


Mean of y (Johor) is 31.0
p-value is 0.0008502 < α = 0.05

Thus, H0 is rejected. The average annual tourist arrival from Hong Kong is higher for Penang than for Johor
Problem 3 - A researcher suspected that there is a difference in percentage of local authority budget spent on
garbage collection between states in Peninsular Malaysia. For this purpose, the researcher selected five states
(Kedah, Selangor, Johor, Melaka and Penang) where from each state, several local authorities were selected for the
study. From each of the selected local authorities, their percentages of budget spent on garbage collection were
recorded. From the results below, is there evidence at 95% confidence level that, on average, the percentage of
budget spent by local authorities on garbage collection are different among the states? If yes, which states are
different from the rest?

Input Output

library(readr)
state <- read.csv( "State.csv" )

print(state) State Percentage


summary(state) 1 Kedah 8
2 Kedah 3
3 Kedah 5
4 Kedah 4
5 Kedah 4
6 Selangor 5
7 Selangor 4
8 Selangor 4
9 Selangor 4
10 Selangor 6
11 Johor 9
12 Johor 10
13 Johor 10
14 Johor 10
15 Johor 9
16 Johor 8
17 Johor 8
18 Melaka 4
19 Melaka 6
20 Melaka 8
21 Melaka 5
22 Melaka 9
23 Melaka 5
24 Penang 9
25 Penang 9
26 Penang 4
27 Penang 8
> summary(state)
State Percentage
Length:27 Min. : 3.000
Class :character 1st Qu.: 4.000
Mode :character Median : 6.000
Mean : 6.593
3rd Qu.: 9.000
Max. :10.000

#perform ANOVA > anovaResult <- aov(Percentage ~ State, data


anovaResult <- aov(Percentage ~ State, data = state) = state)
summary.aov(anovaResult) > summary.aov(anovaResult)
Df Sum Sq Mean Sq F value Pr(>F)
State 4 85.83 21.457 8.043 0.000373
***
Residuals 22 58.69 2.668
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’
0.05 ‘.’ 0.1 ‘ ’ 1

H0: µ Kedah =µ Selangor =µ Johor=µ Melaka =µ Penang


Hα: At least two of the means are not equal
α = 0.05
F = 21.457 / 2.668 = 8.043
p = 0.000373
p<α, REJECT H0.

The percentage of budget spent by local authorities on social services ARE NOT EQUAL for some states. OR At
least one mean of budget percentage spent by local authorities on social services is different from the other
means.

You might also like