> smoke=read.table("D:/R/independensi.txt",header=T)
> 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
>
> a=read.table("D:/R/korelasi.txt",header=T)
>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)
Loading required package: grid
Loading required package: lattice
Error: package survival 2.37-4 was found, but >= 2.37.6 is required by Hmisc
In addition: Warning message:
package Hmisc was built under R version 3.1.1
> utils:::menuInstallLocal()
Error in install.packages(choose.files("", filters = Filters[c("zip", :
no packages were specified
> utils:::menuInstallPkgs()
--- Please select a CRAN mirror for use in this session ---
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
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
> utils:::menuInstallPkgs()
Error in install.packages(NULL, .libPaths()[1L], dependencies = NA, type = type) :
no packages were specified
> utils:::menuInstallPkgs()
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
downloaded 23 Kb
package ppcor successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Siti\AppData\Local\Temp\RtmpWkmqxu\downloaded_packages
> library(ppcor)
> pcor(a)
$estimate
hasil b1000gbh gbhpmalai
hasil
anakan
$p.value
hasil
hasil
b1000gbh
gbhpmalai
hasil
0.668644338
b1000gbh 0.002610175
gbhpmalai 0.564718072
anakan
0.000000000
$statistic
hasil b1000gbh gbhpmalai
hasil
anakan
$n
[1] 7
$gp
[1] 2
$method
[1] "pearson"
> pcor.test(a$hasil,a$gbhpmalai,a[,c("anakan")])
estimate
> b=read.table("D:/R/regresi.txt",header=T)
>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
> c=read.table("D:/R/t_independen.txt",header=T)
>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=read.table("D:/R/t_dependen.txt",header=T)
>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=read.table("D:/R/crd.txt",header=T)
>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)
Residuals 25 625.0
25.0
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)
Error in is.factor(x) : object 'blok' not found
> 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 *
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