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:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
Y : Keputusan menolak/menerima pelamar kerja pada PTA posisi B X1 : Lama pengalaman kerja sebelumnya (bulan) X2 : Status pekerjaan saat ini (0: Bekerja, 1: Tidak bekerja) X3 : Tingkat pendidikan (0: Lulusan Sekolah Menengah, 1: Lulusan Perguruan Tinggi) X4 : IPK (skala 4)
X1 : Lama pengalaman kerja sebelumnya (bulan)
set.seed(123)
xcontoh <- rnorm(100,50,20)
xcontoh
## [1] 38.790487 45.396450 81.174166 51.410168 52.585755 84.301300 59.218324
## [8] 24.698775 36.262943 41.086761 74.481636 57.196277 58.015429 52.213654
## [15] 38.883177 85.738263 59.957010 10.667657 64.027118 40.544172 28.643526
## [22] 45.640502 29.479911 35.422175 37.499215 16.266134 66.755741 53.067462
## [29] 27.237261 75.076298 58.529284 44.098570 67.902513 67.562670 66.431622
## [36] 63.772805 61.078353 48.761766 43.880747 42.390580 36.105860 45.841654
## [43] 24.692073 93.379119 74.159240 27.537828 41.942303 40.666893 65.599302
## [50] 48.332619 55.066370 49.429065 49.142591 77.372046 45.484580 80.329412
## [57] 19.024944 61.692275 52.477085 54.318831 57.592790 39.953531 43.335852
## [64] 29.628492 28.564175 56.070573 58.964196 51.060085 68.445349 91.001694
## [71] 40.179377 3.816622 70.114770 35.815985 36.239828 70.511427 44.304540
## [78] 25.585646 53.626070 47.222173 50.115284 57.705608 42.586799 62.887531
## [85] 45.590269 56.635639 71.936780 58.703630 43.481368 72.976152 69.870077
## [92] 60.967939 54.774635 37.441878 77.213049 37.994808 93.746660 80.652213
## [99] 45.285993 29.471582
X1 : Lama pengalaman kerja sebelumnya (bulan) Membangkitkan variabel X1 dengan lama pekerjaan 0-60 bulan dengan nilai tengah 12 dan banyak pelamar adalah 100
set.seed(100)
n <- 100
u <- runif(n)
x1 <- round(60*(-(log(1-u)/12)))
x1
## [1] 2 1 4 0 3 3 8 2 4 1 5 11 2 3 7 6 1 2 2 6 4 6 4 7 3
## [26] 1 7 11 4 2 3 13 2 15 6 11 1 5 23 1 2 10 8 9 5 3 8 11 1 2
## [51] 2 1 1 2 4 1 1 1 5 1 3 5 16 6 3 2 3 3 1 6 3 2 4 17 5
## [76] 5 10 7 9 0 3 5 13 20 0 4 7 1 2 7 12 1 2 3 12 2 4 1 0 7
X2 : Status pekerjaan Keterangan yang digunakan (0=Tidak bekerja) dan (1=Bekerja)
set.seed(12345)
x2 <- round(runif(n))
x2
## [1] 1 1 1 1 0 0 0 1 1 1 0 0 1 0 0 0 0 0 0 1 0 0 1 1 1 0 1 1 0 0 1 0 0 1 0 0 1
## [38] 1 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 0 1 0 1 1 1 0 1 0 1 1 1 1 0 0
## [75] 0 1 1 1 1 0 1 1 0 0 0 0 1 1 1 0 1 1 0 1 1 1 1 1 0 0
X3 : Tingkat pendidikan Keterangan yang digunakan (0=lulus SMA/Tidak kuliah) dan (1= lulus kuliah)
set.seed(123)
x3 <- round(runif(n))
x3
## [1] 0 1 0 1 1 0 1 1 1 0 1 0 1 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 0 0 1
## [38] 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 0 1 1 1 0
## [75] 0 0 0 1 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 0 0 1 0 0 1
X4 adalah data IPK dengan skala 4
set.seed(123)
x4 <- round(rnorm(n,3,0.5),2)
x4
## [1] 2.72 2.88 3.78 3.04 3.06 3.86 3.23 2.37 2.66 2.78 3.61 3.18 3.20 3.06 2.72
## [16] 3.89 3.25 2.02 3.35 2.76 2.47 2.89 2.49 2.64 2.69 2.16 3.42 3.08 2.43 3.63
## [31] 3.21 2.85 3.45 3.44 3.41 3.34 3.28 2.97 2.85 2.81 2.65 2.90 2.37 4.08 3.60
## [46] 2.44 2.80 2.77 3.39 2.96 3.13 2.99 2.98 3.68 2.89 3.76 2.23 3.29 3.06 3.11
## [61] 3.19 2.75 2.83 2.49 2.46 3.15 3.22 3.03 3.46 4.03 2.75 1.85 3.50 2.65 2.66
## [76] 3.51 2.86 2.39 3.09 2.93 3.00 3.19 2.81 3.32 2.89 3.17 3.55 3.22 2.84 3.57
## [91] 3.50 3.27 3.12 2.69 3.68 2.70 4.09 3.77 2.88 2.49
b0 <- -10
b1 <- 3.5
b2 <- 0.5
b3 <- 2.7
b4 <- 2.2
set.seed(1)
datapendukung <- b0+(b1*x1)+(b2*x2)+(b3*x3)+(b4*x4)
datapendukung
## [1] 3.484 3.036 12.816 -0.112 9.932 8.992 27.806 5.414 13.052 0.116
## [11] 18.142 35.496 7.240 9.932 20.484 22.258 0.650 1.444 4.370 20.272
## [21] 12.134 20.058 12.678 23.508 9.618 0.952 25.224 38.476 9.346 4.986
## [31] 10.762 44.470 7.290 53.268 18.502 35.848 3.916 14.534 77.270 -0.318
## [41] 3.330 31.380 23.714 30.976 15.420 5.868 24.160 34.594 0.958 6.712
## [51] 4.386 0.578 2.756 5.096 13.558 1.772 -1.094 3.438 16.932 0.342
## [61] 10.718 13.550 52.726 16.978 9.112 3.930 10.784 9.866 4.312 20.366
## [71] 9.750 4.270 14.400 55.330 13.352 15.722 31.792 22.958 28.798 -3.554
## [81] 7.600 17.718 41.682 70.004 -3.642 10.974 25.510 3.784 6.448 22.354
## [91] 40.200 3.894 3.864 9.618 40.596 3.440 16.198 2.294 -3.664 22.678
p <- exp(datapendukung)/(1+exp(datapendukung))
p
## [1] 0.97022908 0.95417424 0.99999728 0.47202923 0.99995141 0.99987561
## [7] 1.00000000 0.99556596 0.99999785 0.52896753 0.99999999 1.00000000
## [13] 0.99928320 0.99995141 1.00000000 1.00000000 0.65701046 0.80907331
## [19] 0.98750681 1.00000000 0.99999463 1.00000000 0.99999688 1.00000000
## [25] 0.99993348 0.72151722 1.00000000 1.00000000 0.99991269 0.99321343
## [31] 0.99997881 1.00000000 0.99931814 1.00000000 0.99999999 1.00000000
## [37] 0.98046846 0.99999951 1.00000000 0.42116324 0.96544377 1.00000000
## [43] 1.00000000 1.00000000 0.99999980 0.99717945 1.00000000 1.00000000
## [49] 0.72272119 0.99878525 0.98770268 0.64060708 0.94025131 0.99391606
## [55] 0.99999871 0.85470621 0.25086580 0.96887125 0.99999996 0.58467626
## [61] 0.99997786 0.99999870 1.00000000 0.99999996 0.99988968 0.98073477
## [67] 0.99997927 0.99994809 0.98677065 1.00000000 0.99994171 0.98621101
## [73] 0.99999944 1.00000000 0.99999841 0.99999985 1.00000000 1.00000000
## [79] 1.00000000 0.02781421 0.99949980 0.99999998 1.00000000 1.00000000
## [85] 0.02553098 0.99998286 1.00000000 0.97777366 0.99841882 1.00000000
## [91] 1.00000000 0.98004268 0.97944738 0.99993348 1.00000000 0.96893152
## [97] 0.99999991 0.90837890 0.02498932 1.00000000
set.seed(2)
y <- rbinom(n,1,p)
y
## [1] 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## [38] 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## [75] 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
datagab <- data.frame(y,x1,x2,x3,x4)
datagab
## y x1 x2 x3 x4
## 1 1 2 1 0 2.72
## 2 1 1 1 1 2.88
## 3 1 4 1 0 3.78
## 4 0 0 1 1 3.04
## 5 1 3 0 1 3.06
## 6 1 3 0 0 3.86
## 7 1 8 0 1 3.23
## 8 1 2 1 1 2.37
## 9 1 4 1 1 2.66
## 10 0 1 1 0 2.78
## 11 1 5 0 1 3.61
## 12 1 11 0 0 3.18
## 13 1 2 1 1 3.20
## 14 1 3 0 1 3.06
## 15 1 7 0 0 2.72
## 16 1 6 0 1 3.89
## 17 0 1 0 0 3.25
## 18 1 2 0 0 2.02
## 19 1 2 0 0 3.35
## 20 1 6 1 1 2.76
## 21 1 4 0 1 2.47
## 22 1 6 0 1 2.89
## 23 1 4 1 1 2.49
## 24 1 7 1 1 2.64
## 25 1 3 1 1 2.69
## 26 1 1 0 1 2.16
## 27 1 7 1 1 3.42
## 28 1 11 1 1 3.08
## 29 1 4 0 0 2.43
## 30 1 2 0 0 3.63
## 31 1 3 1 1 3.21
## 32 1 13 0 1 2.85
## 33 1 2 0 1 3.45
## 34 1 15 1 1 3.44
## 35 1 6 0 0 3.41
## 36 1 11 0 0 3.34
## 37 1 1 1 1 3.28
## 38 1 5 1 0 2.97
## 39 1 23 1 0 2.85
## 40 1 1 0 0 2.81
## 41 1 2 1 0 2.65
## 42 1 10 0 0 2.90
## 43 1 8 1 0 2.37
## 44 1 9 1 0 4.08
## 45 1 5 0 0 3.60
## 46 1 3 0 0 2.44
## 47 1 8 0 0 2.80
## 48 1 11 0 0 2.77
## 49 0 1 0 0 3.39
## 50 1 2 1 1 2.96
## 51 1 2 1 0 3.13
## 52 1 1 1 0 2.99
## 53 1 1 0 1 2.98
## 54 1 2 0 0 3.68
## 55 1 4 1 1 2.89
## 56 1 1 0 0 3.76
## 57 0 1 1 0 2.23
## 58 1 1 0 1 3.29
## 59 1 5 0 1 3.06
## 60 0 1 0 0 3.11
## 61 1 3 1 1 3.19
## 62 1 5 0 0 2.75
## 63 1 16 1 0 2.83
## 64 1 6 1 0 2.49
## 65 1 3 1 1 2.46
## 66 1 2 0 0 3.15
## 67 1 3 1 1 3.22
## 68 1 3 0 1 3.03
## 69 1 1 1 1 3.46
## 70 1 6 1 0 4.03
## 71 1 3 1 1 2.75
## 72 1 2 1 1 1.85
## 73 1 4 0 1 3.50
## 74 1 17 0 0 2.65
## 75 1 5 0 0 2.66
## 76 1 5 1 0 3.51
## 77 1 10 1 0 2.86
## 78 1 7 1 1 2.39
## 79 1 9 1 0 3.09
## 80 0 0 0 0 2.93
## 81 1 3 1 0 3.00
## 82 1 5 1 1 3.19
## 83 1 13 0 0 2.81
## 84 1 20 0 1 3.32
## 85 0 0 0 0 2.89
## 86 1 4 0 0 3.17
## 87 1 7 1 1 3.55
## 88 1 1 1 1 3.22
## 89 1 2 1 1 2.84
## 90 1 7 0 0 3.57
## 91 1 12 1 0 3.50
## 92 1 1 1 1 3.27
## 93 1 2 0 0 3.12
## 94 1 3 1 1 2.69
## 95 1 12 1 0 3.68
## 96 1 2 1 0 2.70
## 97 1 4 1 1 4.09
## 98 1 1 1 0 3.77
## 99 0 0 0 0 2.88
## 100 1 7 0 1 2.49
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) -51.146 10396.253 -0.005 0.996
## x1 41.652 10396.249 0.004 0.997
## x2 1.426 1.828 0.780 0.435
## x3 22.379 6830.931 0.003 0.997
## x4 2.765 2.236 1.237 0.216
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 60.508 on 99 degrees of freedom
## Residual deviance: 10.052 on 95 degrees of freedom
## AIC: 20.052
##
## Number of Fisher Scoring iterations: 25