You are on page 1of 22

# Uji Kontingensi

> smoke
sex smoke asthma
1

f smoking asthma

m nonsm nonasht

m smoking nonasht

f nonsm asthma

m smoking asthma

m smoking asthma

f nonsm nonasht

m smoking asthma

f nonsm asthma

10 f nonsm nonasht
11 m smoking asthma
12 f nonsm nonasht
13 f nonsm nonasht
14 m smoking asthma
15 f nonsm nonasht
16 m nonsm nonasht
> tabel=table(smoke\$sex,smoke\$smoke)
> tabel
nonsm smoking
f

> margin.table(tabel,1)
fm
88
> margin.table(tabel,2)
nonsm smoking
9

> chisq.test(tabel)
Pearson's Chi-squared test with Yates' continuity
correction
data: tabel
X-squared = 4.0635, df = 1, p-value = 0.04382
Warning message:
In chisq.test(tabel) : Chi-squared approximation may be incorrect
> #kesimpulan smoke dan sex dependen atau saling terkait
> fisher.test(tabel)
Fisher's Exact Test for Count Data
data: tabel
p-value = 0.04056
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
1.087594 1088.437009
sample estimates:
odds ratio
16.19942
>

## Pembuktian Hk. Mendel

> obs<-c(70,80)
> null.hyp<-c(1/2,1/2)
> uji_mendel<-chisq.test(obs,p=null.hyp)
> uji_mendel
Chi-squared test for given probabilities
data: obs
X-squared = 0.6667, df = 1, p-value = 0.4142
> uji_mendel\$expected
[1] 75 75
>

>a
hasil b1000gbh gbhpmalai anakan
1 8.0

21

250

16

2 7.8

22

240

17

3 6.7

18

210

15

4 7.0

17

220

14

5 7.2

17

220

15

6 7.5

20

240

16

7 6.9

20

200

16

> cor.test(a\$hasil,a\$anakan,method="pearson")
Pearson's product-moment correlation
data: a\$hasil and a\$anakan
t = 1.8448, df = 5, p-value = 0.1244
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.2240240 0.9393007
sample estimates:
cor
0.6363961
> library(Hmisc)
Error: package survival 2.37-4 was found, but >= 2.37.6 is required by Hmisc
package Hmisc was built under R version 3.1.1
Error in install.packages(choose.files("", filters = Filters[c("zip", :
no packages were specified
--- Please select a CRAN mirror for use in this session ---

## Error in install.packages(NULL, .libPaths()[1L], dependencies = NA, type = type) :

no packages were specified
Error in install.packages(choose.files("", filters = Filters[c("zip", :
no packages were specified
also installing the dependencies RColorBrewer, survival, Formula, latticeExtra,
acepack
trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/RColorBrewer_1.0-5.zip'
Content type 'application/zip' length 25286 bytes (24 Kb)
opened URL
trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/survival_2.37-7.zip'
Content type 'application/zip' length 4570668 bytes (4.4 Mb)
opened URL
trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/Formula_1.1-2.zip'
Content type 'application/zip' length 160797 bytes (157 Kb)
opened URL
trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/latticeExtra_0.6-26.zip'
Content type 'application/zip' length 2061939 bytes (2.0 Mb)
opened URL
trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/acepack_1.3-3.3.zip'
Content type 'application/zip' length 69085 bytes (67 Kb)
opened URL

## trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/Hmisc_3.14-5.zip'

Content type 'application/zip' length 1565948 bytes (1.5 Mb)
opened URL
package RColorBrewer successfully unpacked and MD5 sums checked
package survival successfully unpacked and MD5 sums checked
package Formula successfully unpacked and MD5 sums checked
package latticeExtra successfully unpacked and MD5 sums checked
package acepack successfully unpacked and MD5 sums checked
package Hmisc successfully unpacked and MD5 sums checked
> library(Hmisc)
Attaching package: Hmisc
The following objects are masked from package:base:
format.pval, round.POSIXt, trunc.POSIXt, units
Warning messages:
1: package Hmisc was built under R version 3.0.3
2: package Formula was built under R version 3.0.3
> rcorr(as.matrix(a),type="pearson")
hasil b1000gbh gbhpmalai anakan
hasil

1.00

0.72

0.93 0.64

b1000gbh 0.72

1.00

0.55 0.94

gbhpmalai 0.93

0.55

1.00 0.44

anakan

0.64

0.94

0.44 1.00

n= 7

P
hasil b1000gbh gbhpmalai anakan
hasil

0.0704 0.0022

## b1000gbh 0.0704 0.1992

gbhpmalai 0.0022 0.1992
anakan

0.1244
0.0018
0.3181

## 0.1244 0.0018 0.3181

> #korelasi yang nyata adalah antara hasil vs gbhpmalai dan anakan vs b1000gbh
>

> library(ppcor)
Error in library(ppcor) : there is no package called ppcor
Error in install.packages(NULL, .libPaths()[1L], dependencies = NA, type = type) :
no packages were specified
trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/ppcor_1.0.zip'
Content type 'application/zip' length 24133 bytes (23 Kb)
opened URL
package ppcor successfully unpacked and MD5 sums checked
> library(ppcor)
> pcor(a)
\$estimate
hasil b1000gbh gbhpmalai
hasil

anakan

## b1000gbh 0.1160821 1.00000000 0.05545861 0.8667636

gbhpmalai 0.9263471 0.05545861 1.00000000 -0.3154868
anakan

\$p.value
hasil
hasil

b1000gbh

gbhpmalai

## b1000gbh 8.395817e-01 0.000000000 9.233576e-01

gbhpmalai 2.047628e-05 0.923357602 0.000000e+00
anakan

## 6.686443e-01 0.002610175 5.647181e-01

anakan

hasil

0.668644338

b1000gbh 0.002610175
gbhpmalai 0.564718072

anakan

0.000000000

\$statistic
hasil b1000gbh gbhpmalai
hasil

anakan

## b1000gbh 0.2024285 0.0000000 0.0962052 3.0102677

gbhpmalai 4.2596331 0.0962052 0.0000000 -0.5758478
anakan

## 0.4280093 3.0102677 -0.5758478 0.0000000

\$n
[1] 7
\$gp
[1] 2
\$method
[1] "pearson"
> pcor.test(a\$hasil,a\$gbhpmalai,a[,c("anakan")])
estimate

## 1 0.9405813 3.027109e-08 5.539862 7 1 pearson

> pcor.test(a\$hasil,a\$gbhpmalai,a[,c("anakan","b1000gbh")])
estimate

## 1 0.9263471 2.047628e-05 4.259633 7 2 pearson

>

>b
gum_arab xanthan minyak_jeruk diam_butiran kepekatan
1

20.00

0.50

10.00

1329

250.1

13.00

0.50

14.00

1336

230.0

13.00

0.30

10.00

1036

91.8

16.50

0.40

12.00

1238

178.8

20.00

0.30

14.00

1260

272.9

16.50

0.40

12.00

1233

181.5

13.00

0.50

10.00

1175

223.8

20.00

0.50

14.00

1572

436.4

20.00

0.30

10.00

1325

240.8

10

13.00

0.30

14.00

1264

176.7

11

16.50

0.40

12.00

1340

221.1

12

16.50

0.40

12.00

1350

219.0

13

16.50

0.40

12.00

1339

205.0

14

16.50

0.40

12.00

1337

223.8

15

16.50

0.24

12.00

1218

163.2

16

10.78

0.40

12.00

1203

205.5

17

16.50

0.40

15.27

1411

270.0

18

16.50

0.40

8.73

19

22.22

0.40

12.00

1465

366.2

20

16.50

0.56

12.00

1466

325.1

BJ
1 1.05
2 1.02
3 1.03
4 1.03
5 1.03
6 1.04
7 1.03
8 1.04
9 1.05
10 1.02

1176

168.9

11 1.03
12 1.04
13 1.04
14 1.03
15 1.04
16 1.02
17 1.03
18 1.04
19 1.05
20 1.03
> reg1<-lm(BJ~gum_arab,data=b)
> summary(reg1)
Call:
lm(formula = BJ ~ gum_arab, data = b)
Residuals:
Min

1Q

Median

3Q

Max

## -0.013421 -0.004500 0.000500 0.005500 0.006579

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.9924415 0.0077683 127.755 < 2e-16 ***
gum_arab

## --Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1

Residual standard error: 0.005931 on 18 degrees of freedom
Multiple R-squared: 0.6265,

## F-statistic: 30.19 on 1 and 18 DF, p-value: 3.223e-05

>c
perlakuan hasil
1

15

16

17

16

20

12

10

12

11

36

12

38

13

17

14

16

15

45

16

27

17

31

18

30

> var.test(c\$hasil~c\$perlakuan,data=c)
F test to compare two variances
data: c\$hasil by c\$perlakuan
F = 0.36, num df = 9, denom df = 7, p-value = 0.1557
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.07463898 1.51093679
sample estimates:
ratio of variances
0.36

> t.test(c\$hasil~c\$perlakuan,var.equal=T,data=c)
Two Sample t-test
data: c\$hasil by c\$perlakuan
t = -4.7434, df = 16, p-value = 0.0002204
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-26.044475 -9.955525
sample estimates:
mean in group A mean in group B
12

30

>d
perlakuan hasil
1

Sebelum

10

Sebelum

Sebelum

Sebelum

Sebelum

Sebelum

Sebelum

Sebelum

Sebelum

10 Sesudah

11

11 Sesudah

15

12 Sesudah

18

13 Sesudah

17

14 Sesudah

11

15 Sesudah

16 Sesudah

17 Sesudah

15

18 Sesudah

> t.test(d\$hasil~d\$perlakuan,paired=T,data=d)
Paired t-test
data: d\$hasil by d\$perlakuan
t = -3, df = 8, p-value = 0.01707
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-10.612008 -1.387992
sample estimates:
mean of the differences
-6
>

>a
perlakuan hasil
1

A 6.0

A 7.0

A 2.0

A 7.0

A 3.0

A 9.0

A 1.0

B 9.0

B 26.0

10

B 12.0

11

B 22.0

12

B 16.0

13

C 23.0

14

C 6.0

15

C 20.0

16

C 10.0

17

C 16.0

18

C 22.0

19

C 8.0

20

D 9.5

21

D 3.5

22

D 9.0

23

D 2.5

24

D 9.5

25

D 4.0

26

D 10.0

27

D 3.0

28

D 6.5

29

D 7.5

> shapiro.test(a\$hasil)

## Shapiro-Wilk normality test

data: a\$hasil
W = 0.8906, p-value = 0.00587
> attach(a)
> qqnorm(hasil)
> qqline(hasil)
> boxplot(hasil~perlakuan,data=a)
> stripchart(hasil~perlakuan,vertical=T)
> boxplot(hasil~perlakuan,data=a)
Error in file(file, "rt") : cannot open the connection
In file(file, "rt") : cannot open file 'D:/R/ls': No such file or directory
Error in file(file, "rt") : cannot open the connection
In file(file, "rt") :
cannot open file 'D:/R/ls.txt': No such file or directory
> bartlett.test(hasil~perlakuan,data=a)
Bartlett test of homogeneity of variances
data: hasil by perlakuan
Bartlett's K-squared = 8.0127, df = 3, p-value = 0.04575
> stripchart(hasil~perlakuan,vertical=T)
> library(car)
Warning message:
package car was built under R version 3.1.1
> with(a,levene.test(y=hasil,group=perlakuan,center="mean"))

## Levene's Test for Homogeneity of Variance (center = "mean")

Df F value Pr(>F)
group 3 6.0718 0.002988 **
25
--Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
Warning message:
'levene.test' is deprecated.
See help("Deprecated") and help("car-deprecated").
> kruskal.test(hasil~perlakuan,data=a)
Kruskal-Wallis rank sum test
data: hasil by perlakuan
Kruskal-Wallis chi-squared = 14.6464, df = 3, p-value = 0.002145
> crd=aov(hasil~perlakuan,data=a)
> summary(crd)
Df Sum Sq Mean Sq F value Pr(>F)
perlakuan

## 3 717.5 239.2 9.567 0.000219 ***

Residuals 25 625.0

25.0

## --Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1

> library(agricolae)
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
there is no package called klaR
package agricolae was built under R version 3.1.1
Error: package or namespace load failed for agricolae
also installing the dependencies combinat, sp, LearnBayes, deldir, coda,
klaR, spdep

## trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/combinat_0.0-8.zip'

Content type 'application/zip' length 28913 bytes (28 Kb)
opened URL
trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/sp_1.0-15.zip'
Content type 'application/zip' length 1487613 bytes (1.4 Mb)
opened URL
trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/LearnBayes_2.15.zip'
Content type 'application/zip' length 1129612 bytes (1.1 Mb)
opened URL
trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/deldir_0.1-6.zip'
Content type 'application/zip' length 146051 bytes (142 Kb)
opened URL
trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/coda_0.16-1.zip'
Content type 'application/zip' length 196759 bytes (192 Kb)
opened URL
trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/klaR_0.6-12.zip'
Content type 'application/zip' length 319405 bytes (311 Kb)
opened URL
trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/spdep_0.5-77.zip'
Content type 'application/zip' length 3627933 bytes (3.5 Mb)
opened URL

## trying URL 'http://cran.unej.ac.id/bin/windows/contrib/3.0/agricolae_1.2-1.zip'

Content type 'application/zip' length 897285 bytes (876 Kb)
opened URL
package combinat successfully unpacked and MD5 sums checked
package sp successfully unpacked and MD5 sums checked
package LearnBayes successfully unpacked and MD5 sums checked
package deldir successfully unpacked and MD5 sums checked
package coda successfully unpacked and MD5 sums checked
package klaR successfully unpacked and MD5 sums checked
package spdep successfully unpacked and MD5 sums checked
package agricolae successfully unpacked and MD5 sums checked
> library(agricolae)
Warning message:
package agricolae was built under R version 3.0.3
> cv.model(crd)
[1] 50
>b
perlakuan blok hasil
1

Kontrol

Kontrol

Kontrol

4 Pengawet_X

5 Pengawet_X

14

6 Pengawet_X

7 Pengawet_Y

11

8 Pengawet_Y

13

9 Pengawet_Y

12

10 Pengawet_Z

10

11 Pengawet_Z

13

12 Pengawet_Z

10

> as.factor(blok)
> b\$blok=as.factor(b\$blok)
> rcbd=aov(hasil~blok+perlakuan,data=b)
> summary(rcbd)
Df Sum Sq Mean Sq F value Pr(>F)
blok

32 16.000

6.00 0.0370 *

perlakuan

42 14.000

Residuals

16 2.667

5.25 0.0409 *

## --Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1

>c
perlakuan blokbaris blokkolom hasil
1

13

10

13

11

17

12

13

14

13

15

13

16

> c\$blokbaris=as.factor(c\$blokbaris)
> c\$blokkolom=as.factor(c\$blokkolom)
> ls=aov(hasil~blokbaris+blokkolom+perlakuan,data=c)

> summary(ls)
Df Sum Sq Mean Sq F value Pr(>F)
blokbaris

blokkolom

perlakuan

Residuals

6 32.88

5.48

>