Module: 208251 Regression Analysis and Non-Parametric
Statistics
Instructor: Wisunee Puggard
Affiliation: Department of Statistics, Faculty of Science,
Chiang Mai University.
data=read.csv('/Users/wisuneepuggard/Desktop/LAB208251/JobSatisfaction.csv',header=TRUE)
data
## Obs Age Gender Status Education Smoke Income Life.Satisfaction
## 1 1 33 Male Married Undergrad No 15050 3
## 2 2 27 Male Married Undergrad Yes 20600 2
## 3 3 22 Female Single Master Yes 15200 4
## 4 4 34 Male Married Undergrad No 22500 3
## 5 5 24 Female Single High school No 30400 4
## 6 6 37 Female Divorced Undergrad No 33850 3
## 7 7 25 Female Single Master Yes 15100 2
## 8 8 31 Male Married Undergrad Yes 34900 1
## 9 9 40 Male Married Undergrad No 23200 1
## 10 10 26 Male Single Secondary school Yes 32000 1
## 11 11 41 Female Married High school Yes 18650 2
## 12 12 38 Male Married High school No 28570 2
## 13 13 28 Female Single Undergrad No 26000 2
## 14 14 44 Male Divorced High school Yes 39560 3
## 15 15 21 Female Married Undergrad Yes 18000 4
## 16 16 25 Male Single Undergrad No 13500 2
## 17 17 30 Female Single Secondary school No 22350 1
## 18 18 42 Male Married Undergrad Yes 35000 3
## 19 19 43 Female Married Undergrad No 28000 4
## 20 20 20 Male Single Master No 15000 3
## Job.Satisfaction
## 1 3
## 2 4
## 3 1
## 4 4
## 5 3
## 6 3
## 7 3
## 8 2
## 9 3
## 10 3
## 11 1
## 12 3
## 13 4
## 14 2
## 15 3
## 16 1
## 17 1
## 18 3
## 19 3
## 20 4
#Set the variable
Age=data$Age
Gender=data$Gender
Status=data$Status
Education=data$Education
Smoke=data$Smoke
Income=data$Income
Life.Satisfaction=data$Life.Satisfaction
Job.Satisfaction=data$Job.Satisfaction
#Q1
wilcox.test(x=Age, mu=30, alternative = "two.sided")
## Warning in wilcox.test.default(x = Age, mu = 30, alternative = "two.sided"):
## cannot compute exact p-value with ties
## Warning in wilcox.test.default(x = Age, mu = 30, alternative = "two.sided"):
## cannot compute exact p-value with zeroes
##
## Wilcoxon signed rank test with continuity correction
##
## data: Age
## V = 116, p-value = 0.4092
## alternative hypothesis: true location is not equal to 30
#Q2
wilcox.test(x=Income, mu=20000, alternative = "greater")
##
## Wilcoxon signed rank exact test
##
## data: Income
## V = 159, p-value = 0.02203
## alternative hypothesis: true location is greater than 20000
#Q3
wilcox.test(x=Income[Gender=="Male"], y=Income[Gender=="Female"],
paired = FALSE, alternative = "two.sided")
##
## Wilcoxon rank sum exact test
##
## data: Income[Gender == "Male"] and Income[Gender == "Female"]
## W = 56, p-value = 0.6556
## alternative hypothesis: true location shift is not equal to 0
#Q4
wilcox.test(x=Life.Satisfaction[Smoke=="No"], y=Life.Satisfaction[Smoke=="Yes"],
paired = FALSE, alternative = "two.sided")
## Warning in wilcox.test.default(x = Life.Satisfaction[Smoke == "No"], y =
## Life.Satisfaction[Smoke == : cannot compute exact p-value with ties
##
## Wilcoxon rank sum test with continuity correction
##
## data: Life.Satisfaction[Smoke == "No"] and Life.Satisfaction[Smoke == "Yes"]
## W = 52.5, p-value = 0.8441
## alternative hypothesis: true location shift is not equal to 0
#Q5
kruskal.test(Income ~ Education)
##
## Kruskal-Wallis rank sum test
##
## data: Income by Education
## Kruskal-Wallis chi-squared = 5.6472, df = 3, p-value = 0.1301
#Q6
cor.test( ~ Job.Satisfaction + Income
,method = "spearman")
## Warning in cor.test.default(x = c(3L, 4L, 1L, 4L, 3L, 3L, 3L, 2L, 3L, 3L, :
## Cannot compute exact p-value with ties
##
## Spearman's rank correlation rho
##
## data: Job.Satisfaction and Income
## S = 1312.7, p-value = 0.9567
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.01297123
#Q7
chisq.test(Status,Life.Satisfaction)
## Warning in chisq.test(Status, Life.Satisfaction): Chi-squared approximation may
## be incorrect
##
## Pearson's Chi-squared test
##
## data: Status and Life.Satisfaction
## X-squared = 5.8333, df = 6, p-value = 0.4421
#Q8
freq = table(Status)
prob = c(1/3,1/3,1/3)
chisq.test(freq,p=prob)
##
## Chi-squared test for given probabilities
##
## data: freq
## X-squared = 5.2, df = 2, p-value = 0.07427
data1=read.csv('/Users/wisuneepuggard/Desktop/LAB208251/Music_Data2.csv',header=TRUE)
data1
## Runner None Classical Dance
## 1 1 8 8 7
## 2 2 7 6 6
## 3 3 6 8 6
## 4 4 8 9 7
## 5 5 5 8 5
## 6 6 9 7 7
## 7 7 7 7 7
## 8 8 8 7 7
## 9 9 8 6 8
## 10 10 7 6 6
## 11 11 7 8 6
## 12 12 9 9 6
None=data1$None
Classical=data1$Classical
Dance=data1$Dance
#A
dataFT <- data.frame(None, Classical, Dance)
friedman.test(as.matrix(dataFT))
##
## Friedman rank sum test
##
## data: as.matrix(dataFT)
## Friedman chi-squared = 7.6, df = 2, p-value = 0.02237
#B
wilcox.test(x=None, y=Classical,
paired = TRUE, alternative = "two.sided")
## Warning in wilcox.test.default(x = None, y = Classical, paired = TRUE,
## alternative = "two.sided"): cannot compute exact p-value with ties
## Warning in wilcox.test.default(x = None, y = Classical, paired = TRUE,
## alternative = "two.sided"): cannot compute exact p-value with zeroes
##
## Wilcoxon signed rank test with continuity correction
##
## data: None and Classical
## V = 23, p-value = 1
## alternative hypothesis: true location shift is not equal to 0
#C
wilcox.test(x=None, y=Dance,
paired = TRUE, alternative = "two.sided")
## Warning in wilcox.test.default(x = None, y = Dance, paired = TRUE, alternative
## = "two.sided"): cannot compute exact p-value with ties
## Warning in wilcox.test.default(x = None, y = Dance, paired = TRUE, alternative
## = "two.sided"): cannot compute exact p-value with zeroes
##
## Wilcoxon signed rank test with continuity correction
##
## data: None and Dance
## V = 36, p-value = 0.01038
## alternative hypothesis: true location shift is not equal to 0
#D
wilcox.test(x=Classical, y=Dance,
paired = TRUE, alternative = "two.sided")
## Warning in wilcox.test.default(x = Classical, y = Dance, paired = TRUE, :
## cannot compute exact p-value with ties
## Warning in wilcox.test.default(x = Classical, y = Dance, paired = TRUE, :
## cannot compute exact p-value with zeroes
##
## Wilcoxon signed rank test with continuity correction
##
## data: Classical and Dance
## V = 24.5, p-value = 0.08461
## alternative hypothesis: true location shift is not equal to 0