#Operasi aljabar sederhana vektor numerik
x1 <- c(2,6,9,5)
x1
## [1] 2 6 9 5
x2 <- 1:4
x2
## [1] 1 2 3 4
x3 <- x1 + 1:2
x3
## [1] 3 8 10 7
x4 <- x1 + 1:3
## Warning in x1 + 1:3: longer object length is not a multiple of shorter object
## length
x4
## [1] 3 8 12 6
x5 <- x1*x2
x5
## [1] 2 12 27 20
x6 <- x1 %*% x1 #setara x'x
x6
## [,1]
## [1,] 146
x7 <- x1 %o% x1 #setara xx'
x7
## [,1] [,2] [,3] [,4]
## [1,] 4 12 18 10
## [2,] 12 36 54 30
## [3,] 18 54 81 45
## [4,] 10 30 45 25
#Operasi dasar vektor karakter
y1 <- c("Institut Pertanian Bogor")
y1
## [1] "Institut Pertanian Bogor"
n1 <- nchar(y1) #menghitung banyak karakter y1
n1
## [1] 24
y2 <- c("Adam","Pramesti","Fathi","Ririn")
y2
## [1] "Adam" "Pramesti" "Fathi" "Ririn"
n2 <- nchar(y2) #menghitung banyak karakter y2
n2
## [1] 4 8 5 5
y3 <- substr(y1,15,18) #”nian”
y4 <- substring(y1,15) #”nian Bogor”
y5 <- substring(y1,4,8) #”titut
y3
## [1] "nian"
y4
## [1] "nian Bogor"
y5
## [1] "titut"
#Operasi dasar matriks
Z1 <- matrix(1:6,2,3)
Z2 <- matrix(1:6,3,2,byrow=T) #Transpos matriks
Z3 <- matrix(6:9,2,2)
Z1
## [,1] [,2] [,3]
## [1,] 1 3 5
## [2,] 2 4 6
Z2
## [,1] [,2]
## [1,] 1 2
## [2,] 3 4
## [3,] 5 6
Z3
## [,1] [,2]
## [1,] 6 8
## [2,] 7 9
Z4 <- Z1 %*% Z2
Z5 <- Z3 * Z4
Z4
## [,1] [,2]
## [1,] 35 44
## [2,] 44 56
Z5
## [,1] [,2]
## [1,] 210 352
## [2,] 308 504
INVZ <- solve(Z4) #invers
INVZ
## [,1] [,2]
## [1,] 2.333333 -1.833333
## [2,] -1.833333 1.458333
INVZ %*% Z4 #identitas
## [,1] [,2]
## [1,] 1 2.842171e-14
## [2,] 0 1.000000e+00
h <- c(5,11)
p <- solve(Z4,h) #solusi SPL Zp=h
h
## [1] 5 11
p
## [1] -8.500 6.875
e <- eigen(Z4) #eigen value & eigen vector dr Z4
e
## eigen() decomposition
## $values
## [1] 90.7354949 0.2645051
##
## $vectors
## [,1] [,2]
## [1,] 0.6196295 -0.7848945
## [2,] 0.7848945 0.6196295
e$values #akses eigen values
## [1] 90.7354949 0.2645051
e[[2]] #akses eigen vectors
## [,1] [,2]
## [1,] 0.6196295 -0.7848945
## [2,] 0.7848945 0.6196295
#Pengulangan
for (i in 1:5) print(i^2)
## [1] 1
## [1] 4
## [1] 9
## [1] 16
## [1] 25
i<-1
while (i<=5) { print(i^2)
i=i+1 }
## [1] 1
## [1] 4
## [1] 9
## [1] 16
## [1] 25
y=runif(20)
for (i in y) { if(i<0.5){ print(100*i) }
else print(i/100) }
## [1] 27.40573
## [1] 36.56212
## [1] 0.00525826
## [1] 48.41477
## [1] 45.08935
## [1] 9.455897
## [1] 0.005111383
## [1] 0.007260875
## [1] 0.00534577
## [1] 7.416762
## [1] 49.78544
## [1] 0.009779029
## [1] 44.22923
## [1] 0.3765245
## [1] 0.009295468
## [1] 6.466755
## [1] 4.925134
## [1] 0.00500856
## [1] 0.009948316
## [1] 0.008307119
y
## [1] 0.274057273 0.365621231 0.525825958 0.484147745 0.450893492 0.094558972
## [7] 0.511138272 0.726087474 0.534577018 0.074167622 0.497854407 0.977902883
## [13] 0.442292265 0.003765245 0.929546756 0.064667545 0.049251335 0.500856015
## [19] 0.994831629 0.830711904
z=0
while(z<=10) {
y=runif(20)
z=sum(y)
print(z) }
## [1] 10.7582
y
## [1] 0.07564899 0.45931860 0.12675569 0.74614707 0.76653846 0.54677895
## [7] 0.90534658 0.67301442 0.30773777 0.29160904 0.95390614 0.13764809
## [13] 0.94110697 0.76672948 0.68919315 0.84290275 0.64252095 0.08792219
## [19] 0.02529926 0.77207164
z
## [1] 10.7582
#mengambil 1 bilangan acak dari 1-5
acak <- sample(1:5,1)
acak
## [1] 3
acak5<- sample(1:10,5) #mengambil 5 bilangan acak dari 1-10
acak5
## [1] 5 1 2 4 7
switch(EXPR=acak, "1" = "a", "2" = "z",
"3" = "m", "4" = "h", "5" = "t")
## [1] "m"
Z6 <- matrix(1:25,5,5)
Z6
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 6 11 16 21
## [2,] 2 7 12 17 22
## [3,] 3 8 13 18 23
## [4,] 4 9 14 19 24
## [5,] 5 10 15 20 25
apply(Z6,1,sum)
## [1] 55 60 65 70 75
apply(Z6,2,sd)
## [1] 1.581139 1.581139 1.581139 1.581139 1.581139
Tentukan hasil dari setiap perintah berikut :
a<-0
for(i in 1:5)
{ b<-a+i
print(b)
a<-b
}
## [1] 1
## [1] 3
## [1] 6
## [1] 10
## [1] 15
i<-1
z<-1
while(z<15)
{ y<-z+i
z<-y
print(z)
i<-i+1
}
## [1] 2
## [1] 4
## [1] 7
## [1] 11
## [1] 16
i<-1
m<-2
repeat
{ m<-m+i
print(m)
i<-i+1
if(m>15)
break
}
## [1] 3
## [1] 5
## [1] 8
## [1] 12
## [1] 17
#dasar plot
x <- 1:40
y <- rnorm(40,5,1)
x
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
## [26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
y
## [1] 4.234674 5.045281 3.742623 3.212392 4.913786 7.429494 5.667342 5.599784
## [9] 4.793590 4.207770 6.576658 4.781458 3.319291 3.102879 3.244672 4.129224
## [17] 4.011525 4.369007 4.314956 6.475283 3.878012 4.474232 3.900920 5.313918
## [25] 4.072919 4.028624 5.247557 4.280288 5.125766 5.775056 5.365630 8.152290
## [33] 4.845234 4.310365 6.323295 4.703948 4.804159 5.426433 4.244818 5.149500
plot(x,y,type="p") #for point
plot(x,y,type="o") #for overplotted
plot(x,y,type="n") #for no plotting
plot(x,y,type="p",xlab="Sumbu x",ylab="Sumbu y",
main="Bilangan Acak Normal",col=2,pch=16)
plot(x,y,type="p",xlab="Sumbu x",ylab="Sumbu y",
main="Bilangan Acak Normal",col=rainbow(40), pch=16,cex=2,xlim=c(0,50),ylim=c(2.5,7.5))
#menambahkan amatan
x1 <- 41:50
y1 <- rnorm(10,5,1)
points(x1,y1,cex=2)
#menambahkan garis
x2 <- rep(40.5,20)
y2 <- seq(min(c(y,y1)),max(c(y,y1)),length=20)
lines(x2,y2,col=4,lwd=2,lty=2)
#menambahkan garis lurus
abline(h=mean(y),col="red",lwd=2.5) #horizontal
abline(a=2,b=1/10,col="maroon3",lwd=2,lty=2)
#tanda panah
arrows(x0=30,y0=3.5,x1=40,y1=mean(y)-.1,lwd=2)
#tulisan
text(x=29,y=3.3,labels="Titik potong",cex=0.7)
text(x=3,y=7.3,labels="Data awal",cex=0.7)
text(x=46,y=7.3,labels="Data baru",cex=0.7)
Could you explain what are these programs do for?
plot(sin,-pi, 2*pi)
Program tersebut bertujuan untuk membuat plot fungsi sin dari -pi sampai 2pi radian
plot(table(rpois(100,5)),type="h",col="red", lwd=1,main="rpois(100,lambda=5)")
Program tersebut bertujuan untuk membuat plot sebaran poisson dengan 100 bilangan acak dan lambda=5
Create some programs to make the graps below
a1<- 1:25
a2<- rnorm(25,4,2)
plot(a1,a2,pch="w",main="w")
plot(a1,a2,type="n",main="W")
text(a1,a2,labels=paste("w",1:25,sep=""),col=rainbow(25),cex=0.8)
Create some programs to make the graph below, using 100 observation of X~X^2(4)
x <- rchisq(100,df=4)
x
## [1] 3.4933215 1.3626299 6.5302825 3.6120663 8.1453919 7.5443066
## [7] 3.2005349 10.8950446 1.0861531 1.7994687 3.9314404 1.8975365
## [13] 1.8885371 9.8114818 5.4799555 4.5860184 2.1931406 0.5207948
## [19] 9.1297292 5.5542412 0.7347181 2.7203485 3.2189007 2.9532336
## [25] 2.8438104 7.0425398 3.6118302 6.4135076 6.1700265 4.0753225
## [31] 5.7840967 1.8033431 1.7657121 0.7882950 4.8456095 1.9559897
## [37] 3.4925063 5.6665453 7.3159196 0.6996988 2.8929291 3.1576918
## [43] 5.0040180 2.4603210 6.1569206 1.3247213 1.4778722 3.6479331
## [49] 2.7237644 2.9900865 4.6244921 3.0151901 2.3877685 12.9533745
## [55] 2.9712670 8.4752688 4.5542931 1.4919848 8.8113935 3.3117914
## [61] 1.0281404 1.2092221 1.1228898 1.9952925 3.1984110 3.3686557
## [67] 3.7655544 1.9578538 4.7401708 0.5828176 3.7772269 1.5593790
## [73] 5.1265272 1.2721239 0.7634711 2.6239260 11.2985477 5.3137191
## [79] 11.2928753 3.6972193 3.0184624 3.5968279 8.6131203 6.9418389
## [85] 3.1723409 3.7441886 5.2362133 8.4440890 2.5331676 8.2022748
## [91] 7.8593254 7.6201201 0.8223481 1.3411365 10.5530088 10.3629853
## [97] 9.4265477 8.8793937 1.9247447 1.0411644
hist(x,freq=FALSE,ylim=c(0,0.2))
curve(dchisq(x,df=4),col=2,lty=2,lwd=2,add=TRUE)
par(mfrow=c(2,2))
plot(1:40,y,type="p",xlab="Sumbu x",ylab="Sumbu y", main="Bilangan Acak Normal",col=2,pch=16)
plot(sin,-pi, 2*pi)
plot(table(rpois(100,5)),type="h",col="red", lwd=1,main="rpois(100,lambda=5)")
plot(a1,a2,type="n",main="W")
text(a1,a2,labels=paste("w",1:25,sep=""), col=rainbow(25),cex=0.8)
par(mfcol=c(2,2))
plot(1:40,y,type="p",xlab="Sumbu x",ylab="Sumbu y", main="Bilangan Acak Normal",col=2,pch=16)
plot(sin,-pi, 2*pi)
plot(table(rpois(100,5)),type="h",col="red",lwd=1, main="rpois(100,lambda=5)")
plot(a1,a2,type="n",main="W")
text(a1,a2,labels=paste("w",1:25,sep=""), col=rainbow(25),cex=0.8)
Create 4 graph in one window from 100 random numbers which follow N(5,1), with format described bellow
windows()
yb <- rnorm(100,5,1)
yb
## [1] 4.436432 5.048504 4.657759 5.590929 4.793209 5.612193 4.859444 4.258881
## [9] 5.402087 5.626166 4.414992 5.419831 4.344335 3.613112 6.425258 5.590017
## [17] 5.820852 6.093880 5.477373 3.383090 3.982334 5.115569 4.188172 5.914734
## [25] 6.315315 2.385613 4.566937 5.749491 6.116379 7.073034 6.606017 5.470197
## [33] 4.570344 5.991720 4.588650 4.892243 5.624474 5.248280 5.753527 2.936410
## [41] 4.702788 4.690073 5.887584 6.686884 5.366472 4.866518 4.679018 5.587819
## [49] 5.433237 4.735069 4.947328 5.613326 5.245006 4.726965 4.360708 5.409282
## [57] 4.306155 5.520975 6.706624 4.558114 5.198812 4.914151 3.848264 4.903293
## [65] 4.320575 3.087128 5.284844 5.658293 6.143642 4.134128 4.179891 4.110491
## [73] 6.383220 5.790501 5.873830 5.746224 5.101481 5.341766 5.219781 3.186482
## [81] 5.150712 6.032349 6.346911 5.338346 6.204219 6.121677 5.361985 6.503236
## [89] 4.877752 5.964138 5.254686 3.916535 4.368766 4.416602 5.334276 5.495053
## [97] 4.610769 3.351959 5.888647 5.900017
split.screen(c(2,2))
## [1] 1 2 3 4
screen(3)
boxplot(yb)
title("Boxplot Bilangan Acak Normal",cex.main=0.7)
screen(4)
xb <- 1:100
plot(xb,yb,type="l",lwd=2,col="blue")
title("Line Plot Bilangan Acak Normal",cex.main=0.7)
screen(2)
hist(yb,freq=FALSE,main=NULL,ylim=c(0,0.5))
x <- yb
curve(dnorm(x,5,1),col="red",lty=2,lwd=2,add=TRUE)
title("Histogram Bilangan Acak Normal",cex.main=0.7)
screen(1)
plot(xb,yb,pch=16,col=rainbow(100))
title("Scatter Plot Bilangan Acak Normal",cex.main=0.7)
#pembangkitan bilangan acak (rnorm,rbinom, dll)
x<- rnorm(10) # x~N(0,1)
x
## [1] 1.0122878 0.7567546 -0.1095764 -0.1887524 -0.4457450 0.1077562
## [7] 0.7413795 -2.1777504 -1.4395385 -0.5543962
x1<- rnorm(10,3,2) # x1~N(3,sd=2)
x1
## [1] 3.3452689 4.4165359 1.0279127 5.0597543 3.1528866 0.2022921 3.7239274
## [8] 2.6611298 0.8268575 3.1090650
x2<- rbinom(10,1,0.4) # x2~Bernoulli(p=0.4)
x2
## [1] 0 0 0 0 1 1 1 1 0 0
#mencari nilai peluang peubah acak (pnorm,pbinom,punif,dll)
p1<-pnorm(1.645) #P(Z<1.645) = 0.95
p1
## [1] 0.9500151
p2 <- pnorm(1.96) #P(Z<1.975)=0.975
p2
## [1] 0.9750021
p3 <- pnorm(-1.96)
p3
## [1] 0.0249979
p4 <- pf(15,df1=10,df2=15)
p4
## [1] 0.9999955
#mencari nilai kuantil dari peluang peubah acak (qnorm,qunif,qbinom,dll)
q1 <- qnorm(0.975)
q2 <- qnorm(0.95,2,1) # X~N(2,1), P(X<x)=0.95
#mencari nilai density peubah acak
##plot density normal (fkp)
a <- seq(-4,4,length=1000)
da <- dnorm(a)
plot(a,da)
Keunggulan: bisa digunakan untuk berbagai sebaran (termasuk sebaran diskret)
Kesulitan utama: memperoleh kebalikan dari fungsi sebaran kumulatif
#menggunakan set.seed
set.seed(10) #Agar hasilnya selalu sama setiap menjalankan program maka gunakan set.seed ini
Membangkitkan bilangan acak Eksponensial (lambda)
#Eksponensial(lambda=3)
eks <- function(n,lambda){
U <- runif(n)
X <- -log(1-U)/lambda
return(X)
}
yy1 <- eks(1000,3) #inverse transform method
yy2 <- rexp(1000,rate=3) #fungsi bawaan R
par(mfrow=c(1,2))
hist(yy1,main="Exp dari Inverse Transform")
hist(yy2,main="Exp dari fungsi rexp")
Bangkitkan bilangan acak yang memiliki fkp f(y)= 3y2 ; 0 < y < 1 menggunakan acceptance-rejection method!
ar <-function(n,x0,x1,f) {
xx <- seq(x0,x1,length=10000)
F <- max(f(xx))
terima <-0; iterasi<-0
hasil <- numeric(n)
while(terima<n) {
x <- runif(1,x0,x1)
y1<- runif(1,0,F)
y2<- f(x)
if(y1<=y2) {
terima <- terima+1
hasil[terima]<-x}
iterasi <- iterasi+1}
list(hasil=hasil,iterasi=iterasi)
}
set.seed(10)
f <- function(x) {3*x^2}
yyy <- ar(100,0,1,f)
yyy
## $hasil
## [1] 0.8647212 0.7751099 0.8382877 0.7707715 0.5355970 0.8613824 0.2036477
## [8] 0.7979930 0.7438394 0.3443435 0.9837322 0.6935082 0.6331153 0.8880315
## [15] 0.7690405 0.6483695 0.8795432 0.9360689 0.7233519 0.7620444 0.9868082
## [22] 0.8760261 0.7240640 0.8140516 0.5588949 0.8900940 0.7456896 0.8480646
## [29] 0.8703302 0.8223331 0.8508123 0.7709219 0.8953595 0.5803863 0.5982260
## [36] 0.9235285 0.7367755 0.6898170 0.8301572 0.9293209 0.9095163 0.5347576
## [43] 0.3478601 0.8759762 0.7286815 0.8749293 0.6988356 0.8312562 0.5572238
## [50] 0.6647687 0.7400502 0.9806898 0.3800746 0.7553169 0.5184889 0.8879149
## [57] 0.9177773 0.8084086 0.8537441 0.4232184 0.7604306 0.3405763 0.3886568
## [64] 0.4774175 0.5387605 0.9485434 0.7124685 0.9081691 0.9457656 0.7716899
## [71] 0.6946655 0.5368832 0.8481593 0.8242752 0.5123742 0.3152032 0.9924487
## [78] 0.9327120 0.9892809 0.6283590 0.5254605 0.8810815 0.5291748 0.5765517
## [85] 0.7231807 0.8761180 0.3995670 0.8986123 0.9335217 0.7859216 0.7784128
## [92] 0.6955333 0.9060413 0.9916424 0.4729846 0.9770567 0.9386110 0.9959093
## [99] 0.8543663 0.8309547
##
## $iterasi
## [1] 322
hist(yyy$hasil, main="f(x)=3*x^2")
Memanfaatkan beberapa fungsi transformasi dari berbagai sebaran yang ada
#membangkitkan bilangan acak Y~U(3,5); dengan Y=2X+3 ; X~U(0,1)
x<- runif(1000)
y<- 2*x+3
x
## [1] 0.797825431 0.584105766 0.432789951 0.184224183 0.342946933 0.084464446
## [7] 0.616232814 0.235762393 0.408317743 0.716011365 0.327048376 0.012941041
## [13] 0.508899982 0.322516995 0.517734042 0.610396073 0.684642654 0.888747016
## [19] 0.737487884 0.689914271 0.022710082 0.229486351 0.244891027 0.541362925
## [25] 0.448027994 0.781770059 0.365328471 0.363040445 0.479099880 0.118028502
## [31] 0.538288923 0.291478881 0.605037134 0.363013173 0.710482037 0.486796506
## [37] 0.891667697 0.349029623 0.612229021 0.315482072 0.323191441 0.375130329
## [43] 0.733514780 0.185734785 0.234534372 0.846513820 0.947321398 0.640187209
## [49] 0.268725079 0.895056379 0.649711262 0.759947507 0.982764620 0.025754627
## [55] 0.151841507 0.453398596 0.187596533 0.570851089 0.898161645 0.188545941
## [61] 0.054237505 0.209667592 0.869126890 0.540226126 0.984553125 0.928419838
## [67] 0.665764208 0.457998605 0.885159054 0.036603725 0.848891340 0.706611684
## [73] 0.743403587 0.623274679 0.977894336 0.693796329 0.863160582 0.193288500
## [79] 0.766206065 0.996617361 0.080808013 0.187778729 0.098908640 0.698711418
## [85] 0.166418462 0.109024159 0.041221326 0.789316619 0.797210099 0.879441000
## [91] 0.223940304 0.790037822 0.984422095 0.042393012 0.336053200 0.442041019
## [97] 0.497746013 0.035648652 0.655554946 0.406714054 0.357302757 0.118415777
## [103] 0.333909273 0.471162778 0.596654524 0.551235504 0.986783017 0.975748222
## [109] 0.623341939 0.471480626 0.286450202 0.746195281 0.068679755 0.491225544
## [115] 0.661038335 0.375819898 0.298727569 0.500884383 0.362992764 0.697829736
## [121] 0.767494940 0.853763524 0.288892113 0.968609868 0.073562654 0.283470321
## [127] 0.146400593 0.132155369 0.247354411 0.172719345 0.269957624 0.013073025
## [133] 0.970673138 0.926739111 0.442193378 0.025226722 0.261273665 0.155160499
## [139] 0.340471727 0.515688480 0.634122479 0.790110164 0.128555324 0.299820401
## [145] 0.526339070 0.513562848 0.515156062 0.701760655 0.821491682 0.943026604
## [151] 0.983618091 0.461239024 0.274310795 0.188615575 0.893332351 0.821365678
## [157] 0.468334556 0.509380016 0.881347855 0.181505094 0.985597462 0.663976280
## [163] 0.657692968 0.307070185 0.230148136 0.031048517 0.025203922 0.372042812
## [169] 0.025585336 0.677386655 0.173352993 0.362733950 0.884499976 0.763239111
## [175] 0.266235194 0.417301033 0.447148228 0.899110630 0.493130185 0.117339626
## [181] 0.322891172 0.043288423 0.929615964 0.025221514 0.984970790 0.093809772
## [187] 0.001343566 0.684716536 0.038198476 0.556393340 0.357615710 0.403115226
## [193] 0.645996385 0.157688719 0.108586936 0.560222995 0.682568529 0.282359838
## [199] 0.891222840 0.170626095 0.276547525 0.727723331 0.774053375 0.277410173
## [205] 0.729746177 0.645382040 0.409567622 0.046271072 0.240455108 0.368645362
## [211] 0.890560809 0.228434073 0.935557702 0.692329942 0.910702592 0.356703963
## [217] 0.450779764 0.154249999 0.824822890 0.760693366 0.507777616 0.928810467
## [223] 0.796971409 0.891108522 0.380375528 0.043726370 0.476364036 0.719662484
## [229] 0.843127909 0.642096933 0.084133276 0.934762793 0.157640454 0.575359234
## [235] 0.490713336 0.718750809 0.939037899 0.521182625 0.223817643 0.822206384
## [241] 0.842982788 0.557735155 0.608040269 0.187675599 0.467966578 0.647974489
## [247] 0.183116372 0.173097281 0.681945173 0.314169101 0.917505904 0.407746970
## [253] 0.513858897 0.695419633 0.098077310 0.754421851 0.877781410 0.476329833
## [259] 0.063831259 0.243152183 0.005895551 0.975002018 0.239618830 0.563414425
## [265] 0.386890443 0.257517410 0.331669324 0.434146591 0.365769602 0.782391679
## [271] 0.484321261 0.752662813 0.812451399 0.175556776 0.359442866 0.074529275
## [277] 0.233014820 0.438409899 0.960091223 0.302242459 0.465717871 0.425965461
## [283] 0.865715282 0.874719012 0.492349621 0.221868293 0.067658387 0.754617625
## [289] 0.996539658 0.316486538 0.228530679 0.959759393 0.856606143 0.946967829
## [295] 0.487203438 0.249053015 0.294612416 0.144091930 0.027074448 0.812843817
## [301] 0.843232292 0.115938071 0.390032320 0.922732178 0.105729089 0.420434420
## [307] 0.894074371 0.907938152 0.423787531 0.987304236 0.819109381 0.635950426
## [313] 0.015453434 0.977437671 0.901407043 0.113635276 0.334285533 0.452302351
## [319] 0.399360427 0.890764521 0.907771827 0.328402319 0.799178390 0.526428843
## [325] 0.071460367 0.033736566 0.268863875 0.633840456 0.542250810 0.850074773
## [331] 0.032590346 0.598522812 0.053001459 0.577232908 0.590051207 0.525655342
## [337] 0.821531351 0.277172997 0.370245410 0.891136917 0.900993634 0.692093648
## [343] 0.522831279 0.246509740 0.013764526 0.107445429 0.300518321 0.330314094
## [349] 0.860103683 0.822427018 0.403947956 0.687933005 0.181557226 0.450180770
## [355] 0.192615193 0.971526137 0.807706325 0.710179209 0.248249193 0.509782969
## [361] 0.568758601 0.331568202 0.436661891 0.199697074 0.786256548 0.784722279
## [367] 0.954900646 0.619593676 0.892506512 0.232518464 0.511741869 0.530108281
## [373] 0.951261943 0.574386406 0.871019407 0.939295087 0.080396326 0.768369621
## [379] 0.562287124 0.161637964 0.807168301 0.089309047 0.486743532 0.868764625
## [385] 0.829974517 0.981608536 0.870782264 0.223493906 0.653097736 0.416614082
## [391] 0.646841980 0.169172698 0.400619894 0.081654963 0.692902650 0.604882528
## [397] 0.091791516 0.721271849 0.452915192 0.529043586 0.263285697 0.481480425
## [403] 0.751016296 0.442069628 0.382896706 0.542716803 0.734972563 0.392188383
## [409] 0.953368481 0.123325639 0.008197486 0.010542308 0.088533191 0.980120715
## [415] 0.885319765 0.481836975 0.902140120 0.687789408 0.476239360 0.981351349
## [421] 0.246652287 0.984327460 0.073050916 0.188407644 0.902189146 0.383730082
## [427] 0.880236349 0.069347247 0.806218433 0.763002168 0.010817016 0.372420735
## [433] 0.081989973 0.315523982 0.082892273 0.341842973 0.141625049 0.368556490
## [439] 0.173243423 0.847526097 0.278791850 0.265163969 0.849600435 0.556518764
## [445] 0.676869344 0.901693325 0.116347554 0.621799911 0.785787379 0.631747651
## [451] 0.038171977 0.194351817 0.278359311 0.356986643 0.099856391 0.340993174
## [457] 0.377469093 0.042728769 0.242346234 0.821880772 0.004098451 0.838202964
## [463] 0.795320562 0.141095259 0.620550269 0.345270485 0.476858595 0.762485631
## [469] 0.822924931 0.211851986 0.413445043 0.582372665 0.839677543 0.904570353
## [475] 0.027219037 0.321701344 0.146235772 0.287267414 0.813373829 0.228739133
## [481] 0.999800799 0.714307123 0.770808086 0.523044725 0.417820916 0.603939167
## [487] 0.571399561 0.334126617 0.923118473 0.086975750 0.328822549 0.474062871
## [493] 0.643261345 0.373658695 0.756729747 0.742407375 0.824704802 0.836006944
## [499] 0.932135887 0.994831033 0.876878468 0.242845924 0.589708797 0.799913914
## [505] 0.097579898 0.745062760 0.474971364 0.741071007 0.839713956 0.176089985
## [511] 0.157224397 0.197913438 0.226330860 0.451127320 0.959421887 0.380681999
## [517] 0.117495504 0.180848074 0.338350024 0.329158308 0.058228483 0.036738474
## [523] 0.389556920 0.945514445 0.279163946 0.283739268 0.745475496 0.015059696
## [529] 0.261895521 0.570171285 0.294935957 0.963317566 0.829329824 0.723717836
## [535] 0.457957857 0.223546208 0.354176394 0.288958525 0.430055615 0.260022928
## [541] 0.608911563 0.234975203 0.593412705 0.504829429 0.980380614 0.831797779
## [547] 0.098514921 0.169682304 0.716064381 0.817178198 0.962900974 0.636466431
## [553] 0.584313213 0.977037362 0.811838655 0.588685742 0.183536334 0.477115994
## [559] 0.478168835 0.516750728 0.087429582 0.725148573 0.624465680 0.111300903
## [565] 0.918600450 0.707329456 0.112904819 0.230896503 0.419121402 0.007355710
## [571] 0.060277139 0.146877102 0.697788187 0.786120305 0.337666423 0.233596452
## [577] 0.043683515 0.183735601 0.993488921 0.600052539 0.690769868 0.202007335
## [583] 0.250197557 0.226672129 0.187544458 0.115156938 0.041692239 0.964778396
## [589] 0.727260691 0.381266551 0.191801985 0.967899078 0.765878773 0.273147335
## [595] 0.487741644 0.224614233 0.453341919 0.308915472 0.539122371 0.066551879
## [601] 0.249248277 0.047849421 0.480361487 0.146580632 0.287494295 0.388425821
## [607] 0.991783519 0.517482704 0.464194431 0.148616886 0.205638512 0.897763023
## [613] 0.387070801 0.298595831 0.552222652 0.213391709 0.144098785 0.899373630
## [619] 0.768397939 0.537192357 0.626535821 0.200359750 0.363552248 0.745217634
## [625] 0.900346017 0.269215459 0.155174963 0.193659793 0.305003215 0.760561115
## [631] 0.433618240 0.561771848 0.381071529 0.309692743 0.978641702 0.794670156
## [637] 0.816180754 0.367068900 0.553863670 0.095465433 0.420236320 0.031776777
## [643] 0.209880275 0.550602012 0.740252528 0.167775563 0.368186941 0.778173526
## [649] 0.041663178 0.707119256 0.603308696 0.385133817 0.179650566 0.338011567
## [655] 0.284825876 0.077645206 0.193294318 0.285405942 0.795454376 0.762324813
## [661] 0.211817081 0.094137460 0.835425663 0.504422369 0.996533815 0.285248506
## [667] 0.446151922 0.641389915 0.457778811 0.226670153 0.089463881 0.385751832
## [673] 0.671161193 0.238483034 0.831753520 0.037347161 0.404608676 0.487851708
## [679] 0.533056295 0.971358297 0.358778860 0.719296729 0.630757472 0.934176400
## [685] 0.604729982 0.689226571 0.998706206 0.593340403 0.365148631 0.422050627
## [691] 0.856008652 0.802360088 0.232791353 0.547266124 0.522547254 0.978083874
## [697] 0.680046814 0.365007143 0.354706248 0.285933800 0.583229262 0.142737696
## [703] 0.901406659 0.205281045 0.051885583 0.965335327 0.216656059 0.314928788
## [709] 0.695294049 0.323206718 0.888316947 0.221770811 0.619858532 0.029389213
## [715] 0.583280743 0.778404063 0.680417278 0.075875743 0.028432790 0.685524173
## [721] 0.892216526 0.947363833 0.652100972 0.938373667 0.487555454 0.028431833
## [727] 0.052745094 0.803746426 0.674101175 0.412795853 0.244831991 0.523572512
## [733] 0.920055592 0.690995985 0.044439327 0.672292780 0.576225082 0.691330376
## [739] 0.241041351 0.076061883 0.209385333 0.336467491 0.261672155 0.549042250
## [745] 0.958836893 0.062516009 0.011895796 0.176030960 0.053429622 0.724240018
## [751] 0.743360394 0.976612319 0.816705402 0.257548373 0.774758038 0.251072323
## [757] 0.410285443 0.235544262 0.243224235 0.689799303 0.693798866 0.108965332
## [763] 0.731130049 0.332675448 0.047769209 0.351264369 0.368339577 0.879955414
## [769] 0.693985692 0.090275428 0.044811409 0.595566809 0.418033353 0.131588286
## [775] 0.345095081 0.024986028 0.117294653 0.562088297 0.674569138 0.671848764
## [781] 0.582225329 0.686953854 0.113115972 0.370606778 0.778582606 0.928774181
## [787] 0.274577211 0.208900323 0.059265092 0.404403529 0.159706700 0.848057668
## [793] 0.862858198 0.736808290 0.820466114 0.810490418 0.219746585 0.504215653
## [799] 0.317095677 0.073028705 0.129090026 0.243355862 0.334021498 0.284598551
## [805] 0.200570940 0.178941309 0.273924429 0.828640277 0.219497694 0.485102583
## [811] 0.186064548 0.538692169 0.485748083 0.783887539 0.380496106 0.502846988
## [817] 0.001296962 0.428922080 0.022293869 0.468521739 0.481507108 0.585031639
## [823] 0.359596681 0.076353459 0.422687999 0.313789707 0.064953325 0.219410739
## [829] 0.186187605 0.958292271 0.194149431 0.549257066 0.709510115 0.736756560
## [835] 0.425346648 0.213407594 0.372535012 0.169061953 0.295655065 0.168155713
## [841] 0.355140987 0.552336170 0.765100773 0.604607831 0.886031838 0.783895554
## [847] 0.881823772 0.343042344 0.748950389 0.665171093 0.880103046 0.230442706
## [853] 0.574768017 0.413251807 0.691132707 0.955206723 0.025730323 0.832721444
## [859] 0.663026524 0.111268727 0.879697564 0.124415321 0.074056130 0.872401548
## [865] 0.356902308 0.302648950 0.271661313 0.268132571 0.625467084 0.660818976
## [871] 0.864300754 0.152447568 0.342357839 0.989406576 0.992040043 0.753888255
## [877] 0.876751503 0.627067150 0.632465192 0.060359554 0.675868776 0.008465241
## [883] 0.376743562 0.304173969 0.919891789 0.263038729 0.340803967 0.127819607
## [889] 0.464897597 0.393787646 0.627362390 0.051398529 0.882011007 0.156798806
## [895] 0.399165165 0.051408559 0.811772765 0.572651731 0.312576235 0.777207138
## [901] 0.233497776 0.619481664 0.117366426 0.131746569 0.295308399 0.782484086
## [907] 0.547501448 0.165919199 0.906277980 0.654630895 0.925501112 0.277019541
## [913] 0.598329749 0.236685807 0.792664795 0.992570110 0.231289188 0.752520403
## [919] 0.601855692 0.648989530 0.196868257 0.547494795 0.585369223 0.684783146
## [925] 0.239097017 0.611762676 0.761416216 0.277628395 0.327303294 0.687681226
## [931] 0.367569202 0.008997192 0.697503388 0.032729117 0.539313192 0.381379283
## [937] 0.771466651 0.421717234 0.390295038 0.519312088 0.705081302 0.456792172
## [943] 0.464803435 0.965527930 0.227906953 0.873800255 0.059370674 0.650921306
## [949] 0.860586143 0.437771027 0.009614646 0.302243152 0.581723770 0.376208710
## [955] 0.777787578 0.121342294 0.016790444 0.432113756 0.698878845 0.439663402
## [961] 0.481486590 0.485067643 0.125180761 0.263289118 0.735436206 0.041427899
## [967] 0.233774898 0.110224787 0.349593817 0.114379097 0.250882768 0.296273240
## [973] 0.816042613 0.918389915 0.812417928 0.862844728 0.651834546 0.880179007
## [979] 0.176830515 0.883565239 0.772117733 0.504648566 0.689637872 0.659070292
## [985] 0.491251313 0.240787322 0.721741343 0.720009986 0.775322587 0.357831365
## [991] 0.310643811 0.731149515 0.231682971 0.190155928 0.499592916 0.884346952
## [997] 0.789828319 0.680114039 0.866351627 0.482601980
y
## [1] 4.595651 4.168212 3.865580 3.368448 3.685894 3.168929 4.232466 3.471525
## [9] 3.816635 4.432023 3.654097 3.025882 4.017800 3.645034 4.035468 4.220792
## [17] 4.369285 4.777494 4.474976 4.379829 3.045420 3.458973 3.489782 4.082726
## [25] 3.896056 4.563540 3.730657 3.726081 3.958200 3.236057 4.076578 3.582958
## [33] 4.210074 3.726026 4.420964 3.973593 4.783335 3.698059 4.224458 3.630964
## [41] 3.646383 3.750261 4.467030 3.371470 3.469069 4.693028 4.894643 4.280374
## [49] 3.537450 4.790113 4.299423 4.519895 4.965529 3.051509 3.303683 3.906797
## [57] 3.375193 4.141702 4.796323 3.377092 3.108475 3.419335 4.738254 4.080452
## [65] 4.969106 4.856840 4.331528 3.915997 4.770318 3.073207 4.697783 4.413223
## [73] 4.486807 4.246549 4.955789 4.387593 4.726321 3.386577 4.532412 4.993235
## [81] 3.161616 3.375557 3.197817 4.397423 3.332837 3.218048 3.082443 4.578633
## [89] 4.594420 4.758882 3.447881 4.580076 4.968844 3.084786 3.672106 3.884082
## [97] 3.995492 3.071297 4.311110 3.813428 3.714606 3.236832 3.667819 3.942326
## [105] 4.193309 4.102471 4.973566 4.951496 4.246684 3.942961 3.572900 4.492391
## [113] 3.137360 3.982451 4.322077 3.751640 3.597455 4.001769 3.725986 4.395659
## [121] 4.534990 4.707527 3.577784 4.937220 3.147125 3.566941 3.292801 3.264311
## [129] 3.494709 3.345439 3.539915 3.026146 4.941346 4.853478 3.884387 3.050453
## [137] 3.522547 3.310321 3.680943 4.031377 4.268245 4.580220 3.257111 3.599641
## [145] 4.052678 4.027126 4.030312 4.403521 4.642983 4.886053 4.967236 3.922478
## [153] 3.548622 3.377231 4.786665 4.642731 3.936669 4.018760 4.762696 3.363010
## [161] 4.971195 4.327953 4.315386 3.614140 3.460296 3.062097 3.050408 3.744086
## [169] 3.051171 4.354773 3.346706 3.725468 4.769000 4.526478 3.532470 3.834602
## [177] 3.894296 4.798221 3.986260 3.234679 3.645782 3.086577 4.859232 3.050443
## [185] 4.969942 3.187620 3.002687 4.369433 3.076397 4.112787 3.715231 3.806230
## [193] 4.291993 3.315377 3.217174 4.120446 4.365137 3.564720 4.782446 3.341252
## [201] 3.553095 4.455447 4.548107 3.554820 4.459492 4.290764 3.819135 3.092542
## [209] 3.480910 3.737291 4.781122 3.456868 4.871115 4.384660 4.821405 3.713408
## [217] 3.901560 3.308500 4.649646 4.521387 4.015555 4.857621 4.593943 4.782217
## [225] 3.760751 3.087453 3.952728 4.439325 4.686256 4.284194 3.168267 4.869526
## [233] 3.315281 4.150718 3.981427 4.437502 4.878076 4.042365 3.447635 4.644413
## [241] 4.685966 4.115470 4.216081 3.375351 3.935933 4.295949 3.366233 3.346195
## [249] 4.363890 3.628338 4.835012 3.815494 4.027718 4.390839 3.196155 4.508844
## [257] 4.755563 3.952660 3.127663 3.486304 3.011791 4.950004 3.479238 4.126829
## [265] 3.773781 3.515035 3.663339 3.868293 3.731539 4.564783 3.968643 4.505326
## [273] 4.624903 3.351114 3.718886 3.149059 3.466030 3.876820 4.920182 3.604485
## [281] 3.931436 3.851931 4.731431 4.749438 3.984699 3.443737 3.135317 4.509235
## [289] 4.993079 3.632973 3.457061 4.919519 4.713212 4.893936 3.974407 3.498106
## [297] 3.589225 3.288184 3.054149 4.625688 4.686465 3.231876 3.780065 4.845464
## [305] 3.211458 3.840869 4.788149 4.815876 3.847575 4.974608 4.638219 4.271901
## [313] 3.030907 4.954875 4.802814 3.227271 3.668571 3.904605 3.798721 4.781529
## [321] 4.815544 3.656805 4.598357 4.052858 3.142921 3.067473 3.537728 4.267681
## [329] 4.084502 4.700150 3.065181 4.197046 3.106003 4.154466 4.180102 4.051311
## [337] 4.643063 3.554346 3.740491 4.782274 4.801987 4.384187 4.045663 3.493019
## [345] 3.027529 3.214891 3.601037 3.660628 4.720207 4.644854 3.807896 4.375866
## [353] 3.363114 3.900362 3.385230 4.943052 4.615413 4.420358 3.496498 4.019566
## [361] 4.137517 3.663136 3.873324 3.399394 4.572513 4.569445 4.909801 4.239187
## [369] 4.785013 3.465037 4.023484 4.060217 4.902524 4.148773 4.742039 4.878590
## [377] 3.160793 4.536739 4.124574 3.323276 4.614337 3.178618 3.973487 4.737529
## [385] 4.659949 4.963217 4.741565 3.446988 4.306195 3.833228 4.293684 3.338345
## [393] 3.801240 3.163310 4.385805 4.209765 3.183583 4.442544 3.905830 4.058087
## [401] 3.526571 3.962961 4.502033 3.884139 3.765793 4.085434 4.469945 3.784377
## [409] 4.906737 3.246651 3.016395 3.021085 3.177066 4.960241 4.770640 3.963674
## [417] 4.804280 4.375579 3.952479 4.962703 3.493305 4.968655 3.146102 3.376815
## [425] 4.804378 3.767460 4.760473 3.138694 4.612437 4.526004 3.021634 3.744841
## [433] 3.163980 3.631048 3.165785 3.683686 3.283250 3.737113 3.346487 4.695052
## [441] 3.557584 3.530328 4.699201 4.113038 4.353739 4.803387 3.232695 4.243600
## [449] 4.571575 4.263495 3.076344 3.388704 3.556719 3.713973 3.199713 3.681986
## [457] 3.754938 3.085458 3.484692 4.643762 3.008197 4.676406 4.590641 3.282191
## [465] 4.241101 3.690541 3.953717 4.524971 4.645850 3.423704 3.826890 4.164745
## [473] 4.679355 4.809141 3.054438 3.643403 3.292472 3.574535 4.626748 3.457478
## [481] 4.999602 4.428614 4.541616 4.046089 3.835642 4.207878 4.142799 3.668253
## [489] 4.846237 3.173952 3.657645 3.948126 4.286523 3.747317 4.513459 4.484815
## [497] 4.649410 4.672014 4.864272 4.989662 4.753757 3.485692 4.179418 4.599828
## [505] 3.195160 4.490126 3.949943 4.482142 4.679428 3.352180 3.314449 3.395827
## [513] 3.452662 3.902255 4.918844 3.761364 3.234991 3.361696 3.676700 3.658317
## [521] 3.116457 3.073477 3.779114 4.891029 3.558328 3.567479 4.490951 3.030119
## [529] 3.523791 4.140343 3.589872 4.926635 4.658660 4.447436 3.915916 3.447092
## [537] 3.708353 3.577917 3.860111 3.520046 4.217823 3.469950 4.186825 4.009659
## [545] 4.960761 4.663596 3.197030 3.339365 4.432129 4.634356 4.925802 4.272933
## [553] 4.168626 4.954075 4.623677 4.177371 3.367073 3.954232 3.956338 4.033501
## [561] 3.174859 4.450297 4.248931 3.222602 4.837201 4.414659 3.225810 3.461793
## [569] 3.838243 3.014711 3.120554 3.293754 4.395576 4.572241 3.675333 3.467193
## [577] 3.087367 3.367471 4.986978 4.200105 4.381540 3.404015 3.500395 3.453344
## [585] 3.375089 3.230314 3.083384 4.929557 4.454521 3.762533 3.383604 4.935798
## [593] 4.531758 3.546295 3.975483 3.449228 3.906684 3.617831 4.078245 3.133104
## [601] 3.498497 3.095699 3.960723 3.293161 3.574989 3.776852 4.983567 4.034965
## [609] 3.928389 3.297234 3.411277 4.795526 3.774142 3.597192 4.104445 3.426783
## [617] 3.288198 4.798747 4.536796 4.074385 4.253072 3.400720 3.727104 4.490435
## [625] 4.800692 3.538431 3.310350 3.387320 3.610006 4.521122 3.867236 4.123544
## [633] 3.762143 3.619385 4.957283 4.589340 4.632362 3.734138 4.107727 3.190931
## [641] 3.840473 3.063554 3.419761 4.101204 4.480505 3.335551 3.736374 4.556347
## [649] 3.083326 4.414239 4.206617 3.770268 3.359301 3.676023 3.569652 3.155290
## [657] 3.386589 3.570812 4.590909 4.524650 3.423634 3.188275 4.670851 4.008845
## [665] 4.993068 3.570497 3.892304 4.282780 3.915558 3.453340 3.178928 3.771504
## [673] 4.342322 3.476966 4.663507 3.074694 3.809217 3.975703 4.066113 4.942717
## [681] 3.717558 4.438593 4.261515 4.868353 4.209460 4.378453 4.997412 4.186681
## [689] 3.730297 3.844101 4.712017 4.604720 3.465583 4.094532 4.045095 4.956168
## [697] 4.360094 3.730014 3.709412 3.571868 4.166459 3.285475 4.802813 3.410562
## [705] 3.103771 4.930671 3.433312 3.629858 4.390588 3.646413 4.776634 3.443542
## [713] 4.239717 3.058778 4.166561 4.556808 4.360835 3.151751 3.056866 4.371048
## [721] 4.784433 4.894728 4.304202 4.876747 3.975111 3.056864 3.105490 4.607493
## [729] 4.348202 3.825592 3.489664 4.047145 4.840111 4.381992 3.088879 4.344586
## [737] 4.152450 4.382661 3.482083 3.152124 3.418771 3.672935 3.523344 4.098084
## [745] 4.917674 3.125032 3.023792 3.352062 3.106859 4.448480 4.486721 4.953225
## [753] 4.633411 3.515097 4.549516 3.502145 3.820571 3.471089 3.486448 4.379599
## [761] 4.387598 3.217931 4.462260 3.665351 3.095538 3.702529 3.736679 4.759911
## [769] 4.387971 3.180551 3.089623 4.191134 3.836067 3.263177 3.690190 3.049972
## [777] 3.234589 4.124177 4.349138 4.343698 4.164451 4.373908 3.226232 3.741214
## [785] 4.557165 4.857548 3.549154 3.417801 3.118530 3.808807 3.319413 4.696115
## [793] 4.725716 4.473617 4.640932 4.620981 3.439493 4.008431 3.634191 3.146057
## [801] 3.258180 3.486712 3.668043 3.569197 3.401142 3.357883 3.547849 4.657281
## [809] 3.438995 3.970205 3.372129 4.077384 3.971496 4.567775 3.760992 4.005694
## [817] 3.002594 3.857844 3.044588 3.937043 3.963014 4.170063 3.719193 3.152707
## [825] 3.845376 3.627579 3.129907 3.438821 3.372375 4.916585 3.388299 4.098514
## [833] 4.419020 4.473513 3.850693 3.426815 3.745070 3.338124 3.591310 3.336311
## [841] 3.710282 4.104672 4.530202 4.209216 4.772064 4.567791 4.763648 3.686085
## [849] 4.497901 4.330342 4.760206 3.460885 4.149536 3.826504 4.382265 4.910413
## [857] 3.051461 4.665443 4.326053 3.222537 4.759395 3.248831 3.148112 4.744803
## [865] 3.713805 3.605298 3.543323 3.536265 4.250934 4.321638 4.728602 3.304895
## [873] 3.684716 4.978813 4.984080 4.507777 4.753503 4.254134 4.264930 3.120719
## [881] 4.351738 3.016930 3.753487 3.608348 4.839784 3.526077 3.681608 3.255639
## [889] 3.929795 3.787575 4.254725 3.102797 4.764022 3.313598 3.798330 3.102817
## [897] 4.623546 4.145303 3.625152 4.554414 3.466996 4.238963 3.234733 3.263493
## [905] 3.590617 4.564968 4.095003 3.331838 4.812556 4.309262 4.851002 3.554039
## [913] 4.196659 3.473372 4.585330 4.985140 3.462578 4.505041 4.203711 4.297979
## [921] 3.393737 4.094990 4.170738 4.369566 3.478194 4.223525 4.522832 3.555257
## [929] 3.654607 4.375362 3.735138 3.017994 4.395007 3.065458 4.078626 3.762759
## [937] 4.542933 3.843434 3.780590 4.038624 4.410163 3.913584 3.929607 4.931056
## [945] 3.455814 4.747601 3.118741 4.301843 4.721172 3.875542 3.019229 3.604486
## [953] 4.163448 3.752417 4.555575 3.242685 3.033581 3.864228 4.397758 3.879327
## [961] 3.962973 3.970135 3.250362 3.526578 4.470872 3.082856 3.467550 3.220450
## [969] 3.699188 3.228758 3.501766 3.592546 4.632085 4.836780 4.624836 4.725689
## [977] 4.303669 4.760358 3.353661 4.767130 4.544235 4.009297 4.379276 4.318141
## [985] 3.982503 3.481575 4.443483 4.440020 4.550645 3.715663 3.621288 4.462299
## [993] 3.463366 3.380312 3.999186 4.768694 4.579657 4.360228 4.732703 3.965204
#Membangkitkan bil.acak ~khi kuadrat (1)
y<-rnorm(1000)
x<- y^2
hist(x,prob=T)
sbx<-seq(0,13,0.01)
lines(sbx,dchisq(sbx,df=1),col="red")
set.seed(123)
X1 <- runif(25,10,25)
X2 <- runif(25,90,200)
Y <- 10 + 2.3*X1 + 0.7*X2 + rnorm(25,0,9)
model1 <- lm(Y~X1)
summary(model1)
##
## Call:
## lm(formula = Y ~ X1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -29.991 -17.738 -2.632 17.896 33.171
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 131.846 19.741 6.679 8.18e-07 ***
## X1 1.049 1.015 1.033 0.312
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 22.42 on 23 degrees of freedom
## Multiple R-squared: 0.04433, Adjusted R-squared: 0.002775
## F-statistic: 1.067 on 1 and 23 DF, p-value: 0.3124
model2 <- lm(Y~X2)
summary(model2)
##
## Call:
## lm(formula = Y ~ X2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -31.804 -4.850 -1.606 10.011 20.569
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 70.83913 13.86879 5.108 3.57e-05 ***
## X2 0.58213 0.09767 5.960 4.46e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.38 on 23 degrees of freedom
## Multiple R-squared: 0.607, Adjusted R-squared: 0.5899
## F-statistic: 35.52 on 1 and 23 DF, p-value: 4.464e-06
model3 <- lm(Y~X1+X2)
summary(model3)
##
## Call:
## lm(formula = Y ~ X1 + X2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -14.8291 -4.5994 -0.4576 5.0602 20.5307
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.62881 13.40229 -0.047 0.963
## X1 2.72951 0.40701 6.706 9.67e-07 ***
## X2 0.72459 0.06105 11.869 4.91e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.427 on 22 degrees of freedom
## Multiple R-squared: 0.8709, Adjusted R-squared: 0.8592
## F-statistic: 74.21 on 2 and 22 DF, p-value: 1.66e-10
model4 <- lm(Y~X1:X2)
summary(model4)
##
## Call:
## lm(formula = Y ~ X1:X2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -20.929 -7.009 -1.430 2.856 37.374
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 80.645221 10.481428 7.694 8.32e-08 ***
## X1:X2 0.027491 0.003929 6.997 3.94e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 12.97 on 23 degrees of freedom
## Multiple R-squared: 0.6804, Adjusted R-squared: 0.6665
## F-statistic: 48.96 on 1 and 23 DF, p-value: 3.942e-07
model5 <- lm(Y~X1*X2)
summary(model5)
##
## Call:
## lm(formula = Y ~ X1 * X2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -14.4425 -4.5808 -0.6702 4.6431 20.2409
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 11.625896 37.941991 0.306 0.7623
## X1 2.063573 1.967526 1.049 0.3062
## X2 0.635870 0.263687 2.411 0.0251 *
## X1:X2 0.004905 0.014165 0.346 0.7326
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.6 on 21 degrees of freedom
## Multiple R-squared: 0.8716, Adjusted R-squared: 0.8533
## F-statistic: 47.53 on 3 and 21 DF, p-value: 1.548e-09
R2 <- matrix(c(summary(model1)$r.squared,
summary(model1)$adj.r.squared,
summary(model2)$r.squared,
summary(model2)$adj.r.squared,
summary(model3)$r.squared,
summary(model3)$adj.r.squared,
summary(model4)$r.squared,
summary(model4)$adj.r.squared,
summary(model5)$r.squared,
summary(model5)$adj.r.squared), 5, byrow=T)
colnames(R2)<-c("R2","R2.adj"); R2*100
## R2 R2.adj
## [1,] 4.432592 0.2774876
## [2,] 60.699195 58.9904640
## [3,] 87.090357 85.9167529
## [4,] 68.036265 66.6465370
## [5,] 87.163648 85.3298839
coef(model3)
## (Intercept) X1 X2
## -0.6288095 2.7295126 0.7245911
confint(model3)
## 2.5 % 97.5 %
## (Intercept) -28.4234482 27.1658292
## X1 1.8854322 3.5735929
## X2 0.5979779 0.8512044
cbind(coef(model3), confint(model3))
## 2.5 % 97.5 %
## (Intercept) -0.6288095 -28.4234482 27.1658292
## X1 2.7295126 1.8854322 3.5735929
## X2 0.7245911 0.5979779 0.8512044
anova(model3)
par(mfrow=c(2,2)); plot(model3)
#Membuat Ridgelineplot
library(ggridges)
library(ggplot2)
ggplot(diamonds, aes(x = price, y = cut, fill = cut)) +
geom_density_ridges() + theme_ridges() + theme(legend.position = "none")
## Picking joint bandwidth of 458
#Kasus : Melihat pengaruh pengalaman (X1) dan Semangat (X2) karyawan terhadap kinerja (Y)
#Analisis regresi
karyawan<-c(1,2,3,4,5,6,7,8,9,10)
pengalaman<-c(6,5,4,8,9,3,2,8,3,9)
semangat<-c(10,6,7,4,3,5,8,4,10,3)
kinerja<-c(17,13,12,17,15,11,11,16,12,15)
datax<-data.frame(karyawan,pengalaman,semangat,kinerja)
datax
#membuat model regresi linier
modelreg<-lm(kinerja~pengalaman+semangat,datax)
summary(modelreg)
##
## Call:
## lm(formula = kinerja ~ pengalaman + semangat, data = datax)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.0081 -0.8552 0.0141 0.5839 1.5845
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.5704 1.9242 2.375 0.049223 *
## pengalaman 1.1013 0.1757 6.267 0.000417 ***
## semangat 0.5087 0.1759 2.893 0.023233 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.001 on 7 degrees of freedom
## Multiple R-squared: 0.8621, Adjusted R-squared: 0.8228
## F-statistic: 21.89 on 2 and 7 DF, p-value: 0.0009728
Diperoleh : kinerja = 4.5704 + 1.1013 pengalaman + 0.5087 semangat