R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Membangkitkan Data X1

set.seed(12345)
n <- 50
u <- runif(n)

x1 <- round(40*(-(log(1-u)/12)))
x1
##  [1]  4  7  5  7  2  1  1  2  4 15  0  1  4  0  2  2  2  2  1 10  2  1 11  4  3
## [26]  2  4  3  1  2  5  0  1  4  2  1  7  8  3  0  5  2  9  5  1  1  0  0  0  3

Membangkitkan Data X2

set.seed(123456)
x2 <- round(runif(n))
x2
##  [1] 1 1 0 0 0 0 1 0 1 0 1 1 1 1 1 1 1 0 0 1 0 0 0 0 0 1 1 1 1 0 1 1 0 0 1 0 1 1
## [39] 1 1 0 1 1 0 1 0 1 1 1 0

Membangkitkan Data X3

set.seed(1234)
x3 <- round(runif(n))
x3
##  [1] 0 1 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 1 0 0
## [39] 1 1 1 1 0 1 0 1 1 0 0 1

Membangkitkan Data X4

set.seed(222)
x4 <- round(rnorm(n,3,0.5),2)
x4
##  [1] 3.74 3.00 3.69 2.81 3.09 2.88 2.39 3.78 3.21 2.40 3.53 2.35 2.65 3.30 2.90
## [16] 2.41 2.00 3.00 3.26 2.63 3.36 3.36 2.67 3.75 2.28 1.92 3.20 2.80 2.85 3.67
## [31] 2.59 3.34 2.89 2.94 2.90 3.20 3.33 3.05 2.91 3.47 3.10 3.25 2.72 3.56 4.10
## [46] 3.16 2.53 3.41 2.81 3.17
set.seed(222)
x44 <- round(rnorm(n,2.8,0.5),2)
x44
##  [1] 3.54 2.80 3.49 2.61 2.89 2.68 2.19 3.58 3.01 2.20 3.33 2.15 2.45 3.10 2.70
## [16] 2.21 1.80 2.80 3.06 2.43 3.16 3.16 2.47 3.55 2.08 1.72 3.00 2.60 2.65 3.47
## [31] 2.39 3.14 2.69 2.74 2.70 3.00 3.13 2.85 2.71 3.27 2.90 3.05 2.52 3.36 3.90
## [46] 2.96 2.33 3.21 2.61 2.97
summary(x44)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.720   2.540   2.825   2.826   3.138   3.900

Membangkitkan Data Y Menentukan Koef

b0 <- -11
b1 <- 3.5
b2 <- 0.5
b3 <- 2.8
b4 <- 2.2
set.seed(1)
datapendukung <- b0+(b1*x1)+(b2*x2)+(b3*x3)+(b4*x4)
datapendukung
##  [1] 11.728 23.400 17.418 22.482  5.598  1.636 -1.742  4.316 13.362 49.580
## [11]  0.066  0.970  9.330 -0.440  2.880  4.602  0.900  2.600 -0.328 30.286
## [21]  3.392 -0.108 33.374 11.250  4.516  3.524 13.340  8.960  2.070  4.074
## [31] 12.698 -3.152 -1.142 12.268  2.880  2.340 21.326 24.210  9.202 -0.066
## [41] 16.120  6.450 26.984 17.132  2.020  2.252 -2.134 -2.998 -4.318  9.274
p <- exp(datapendukung)/(1+exp(datapendukung))
p
##  [1] 0.99999194 1.00000000 0.99999997 1.00000000 0.99630841 0.83698992
##  [7] 0.14905908 0.98682277 0.99999843 1.00000000 0.51649401 0.72511950
## [13] 0.99991129 0.39174097 0.94684886 0.99006788 0.71094950 0.93086158
## [19] 0.41872733 1.00000000 0.96745358 0.47302621 1.00000000 0.99998699
## [25] 0.98918556 0.97136298 0.99999839 0.99987157 0.88795296 0.98327526
## [31] 0.99999694 0.04101254 0.24195335 0.99999530 0.94684886 0.91213609
## [37] 1.00000000 1.00000000 0.99989917 0.48350599 0.99999990 0.99842197
## [43] 1.00000000 0.99999996 0.88288101 0.90482291 0.10583586 0.04751631
## [49] 0.01315125 0.99990618
set.seed(2)
y <- rbinom(n,1,p)
y
##  [1] 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1
## [39] 1 1 1 1 1 1 1 0 0 1 0 1
datagab <- data.frame(y,x1,x2,x3,x4)
datagab
##    y x1 x2 x3   x4
## 1  1  4  1  0 3.74
## 2  1  7  1  1 3.00
## 3  1  5  0  1 3.69
## 4  1  7  0  1 2.81
## 5  1  2  0  1 3.09
## 6  0  1  0  1 2.88
## 7  0  1  1  0 2.39
## 8  1  2  0  0 3.78
## 9  1  4  1  1 3.21
## 10 1 15  0  1 2.40
## 11 0  0  1  1 3.53
## 12 1  1  1  1 2.35
## 13 1  4  1  0 2.65
## 14 1  0  1  1 3.30
## 15 1  2  1  0 2.90
## 16 1  2  1  1 2.41
## 17 0  2  1  0 2.00
## 18 0  2  0  0 3.00
## 19 0  1  0  0 3.26
## 20 1 10  1  0 2.63
## 21 1  2  0  0 3.36
## 22 1  1  0  0 3.36
## 23 1 11  0  0 2.67
## 24 1  4  0  0 3.75
## 25 1  3  0  0 2.28
## 26 1  2  1  1 1.92
## 27 1  4  1  1 3.20
## 28 1  3  1  1 2.80
## 29 1  1  1  1 2.85
## 30 1  2  0  0 3.67
## 31 1  5  1  0 2.59
## 32 0  0  1  0 3.34
## 33 0  1  0  0 2.89
## 34 1  4  0  1 2.94
## 35 1  2  1  0 2.90
## 36 1  1  0  1 3.20
## 37 1  7  1  0 3.33
## 38 1  8  1  0 3.05
## 39 1  3  1  1 2.91
## 40 1  0  1  1 3.47
## 41 1  5  0  1 3.10
## 42 1  2  1  1 3.25
## 43 1  9  1  0 2.72
## 44 1  5  0  1 3.56
## 45 1  1  1  0 4.10
## 46 0  1  0  1 3.16
## 47 0  0  1  1 2.53
## 48 1  0  1  0 3.41
## 49 0  0  1  0 2.81
## 50 1  3  0  1 3.17

Analisis Regresi Logistik

modelreglog <- glm(y~x1+x2+x3+x4, family = binomial(link = "logit"), data=datagab)
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
summary(modelreglog)
## 
## Call:
## glm(formula = y ~ x1 + x2 + x3 + x4, family = binomial(link = "logit"), 
##     data = datagab)
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)  
## (Intercept)  -20.620      8.581  -2.403   0.0163 *
## x1             3.569      1.404   2.541   0.0110 *
## x2             3.835      1.837   2.088   0.0368 *
## x3             2.069      1.199   1.726   0.0844 .
## x4             4.753      2.127   2.234   0.0255 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 52.691  on 49  degrees of freedom
## Residual deviance: 21.366  on 45  degrees of freedom
## AIC: 31.366
## 
## Number of Fisher Scoring iterations: 9

```