You are on page 1of 4

praktikum 6

2023-10-03
library(readxl)
data<-read_excel("D:/Documents/Perkuliahan/Semester 5/APG/tabel7_1.xlsx")
fish_score<-data.frame(data)
head(fish_score)

## y1 y2 y3 y4 Method
## 1 5.4 6.0 6.3 6.7 1
## 2 5.2 6.2 6.0 5.8 1
## 3 6.1 5.9 6.0 7.0 1
## 4 4.8 5.0 4.9 5.0 1
## 5 5.0 5.7 5.0 6.5 1
## 6 5.7 6.1 6.0 6.6 1

#UjiKenormalan
library(mvnormtest)
matU<-as.matrix(t(fish_score[1:12,-5]))
mshapiro.test(matU)

##
## Shapiro-Wilk normality test
##
## data: Z
## W = 0.84313, p-value = 0.03023

matU<-as.matrix(t(fish_score[13:24,-5]))
mshapiro.test(matU)

##
## Shapiro-Wilk normality test
##
## data: Z
## W = 0.85443, p-value = 0.04166

matU<-as.matrix(t(fish_score[25:36,-5]))
mshapiro.test(matU)

##
## Shapiro-Wilk normality test
##
## data: Z
## W = 0.85674, p-value = 0.04451

library("biotools")

## Loading required package: MASS


## ---
## biotools version 4.2

boxM(fish_score[,c(1:4)],fish_score[,5])

##
## Box's M-test for Homogeneity of Covariance Matrices
##
## data: fish_score[, c(1:4)]
## Chi-Sq (approx.) = 13.462, df = 20, p-value = 0.8567

Terlihat p-value = 0,8567 > 0,05, maka kita gagal tolak H0 berarti ada matriks kovarians
ketiga metode sama, sehingga kita bisa melanjutkan uji Manova.
#Manova Test #H0=miu1=miu2=miu3 #H1: terdapat metode dengan vektor mean berbeda
MetRes<-manova(cbind(y1,y2,y3,y4)~Method, data=fish_score)
summary(MetRes, test="Wilks")

## Df Wilks approx F num Df den Df Pr(>F)


## Method 1 0.27885 20.043 4 31 3.082e-08 ***
## Residuals 34
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Dari output terlihat bahwa P-value < (α = 0.05), sehingga H0 kita tolak.
#Contoh 3
#Vektor Mean
xbar<-c(95.52,164.38,55.69,93.39,17.98,31.13)
#Matriks kovarians
S<-
matrix(c(3266.46,1343.97,731.54,1175.50,162.68,238.37,1343.97,721.91,324.25,5
37.35,80.17,117.73,731.54,324.25,179.28,281.17,39.15,56.80,1175.50,53735,281.
17,474.98,63.73,94.85,162.68,80.17,39.15,63.73,9.95,13.88,238.37,117.73,56.80
,94.85,13.88,21.26),nrow=6)
p<-6
n<-61
#vektor a
a1<-c(1,0,0,0,0,0)
a2<-c(0,1,0,0,0,0)
a3<-c(0,0,1,0,0,0)
a4<-c(0,0,0,1,0,0)
a5<-c(0,0,0,0,1,0)
a6<-c(0,0,0,0,0,1)
#hitung degree of freedom
df1<-p
df2<-(n-p)

new_alp<-0.05/(2*p)
#var 1
#hitung lower bound
Lbound1_Bfr<-(t(a1)%*%xbar)-qt((1-new_alp),df=n-1)*sqrt((t(a1)%*%S%*%a1)/n)
#hitung upperbound
Ubound1_Bfr<-(t(a1)%*%xbar)+qt((1-new_alp),df=n-1)*sqrt((t(a1)%*%S%*%a1)/n)

#var 2
#hitung lower bound
Lbound2_Bfr<-(t(a2)%*%xbar)-qt((1-new_alp),df=n-1)*sqrt((t(a2)%*%S%*%a2)/n)
#hitung upperbound
Ubound2_Bfr<-(t(a2)%*%xbar)+qt((1-new_alp),df=n-1)*sqrt((t(a2)%*%S%*%a2)/n)

#var 3
#hitung lower bound
Lbound3_Bfr<-(t(a3)%*%xbar)-qt((1-new_alp),df=n-1)*sqrt((t(a3)%*%S%*%a3)/n)
#hitung upperbound
Ubound3_Bfr<-(t(a3)%*%xbar)+qt((1-new_alp),df=n-1)*sqrt((t(a3)%*%S%*%a3)/n)

#var 4
#hitung lower bound
Lbound4_Bfr<-(t(a4)%*%xbar)-qt((1-new_alp),df=n-1)*sqrt((t(a4)%*%S%*%a4)/n)
#hitung upperbound
Ubound4_Bfr<-(t(a4)%*%xbar)+qt((1-new_alp),df=n-1)*sqrt((t(a4)%*%S%*%a4)/n)

#var 5
#hitung lower bound
Lbound5_Bfr<-(t(a5)%*%xbar)-qt((1-new_alp),df=n-1)*sqrt((t(a5)%*%S%*%a5)/n)
#hitung upperbound
Ubound5_Bfr<-(t(a5)%*%xbar)+qt((1-new_alp),df=n-1)*sqrt((t(a5)%*%S%*%a5)/n)

#var 6
#hitung lower bound
Lbound6_Bfr<-(t(a6)%*%xbar)-qt((1-new_alp),df=n-1)*sqrt((t(a6)%*%S%*%a6)/n)
#hitung upperbound
Ubound6_Bfr<-(t(a6)%*%xbar)+qt((1-new_alp),df=n-1)*sqrt((t(a6)%*%S%*%a6)/n)

#interval kepercayaan
cat("95% Bonferronu simultaneius confidence interval for each variabele:\n\
n",
Lbound1_Bfr," < mu1 < ",Ubound1_Bfr,"\n",
Lbound2_Bfr," < mu2 < ",Ubound2_Bfr,"\n",
Lbound3_Bfr," < mu3 < ",Ubound3_Bfr,"\n",
Lbound4_Bfr," < mu4 < ",Ubound4_Bfr,"\n",
Lbound5_Bfr," < mu5 < ",Ubound5_Bfr,"\n",
Lbound6_Bfr," < mu6 < ",Ubound6_Bfr)

## 95% Bonferronu simultaneius confidence interval for each variabele:


##
## 75.55331 < mu1 < 115.4867
## 154.9934 < mu2 < 173.7666
## 51.01229 < mu3 < 60.36771
## 85.77614 < mu4 < 101.0039
## 16.87801 < mu5 < 19.08199
## 29.51917 < mu6 < 32.74083

You might also like