Y : Keputusan menolak/menerima pelamar kerja pada PT A posisi B X1 : Lama pengalaman kerja sebelumnya (bulan) X2 : Status pekerjaan saat ini (o:tidak bekerja, 1:bekerja) X3 : Tingkat pendidikan (0:tidak kuliah, 1:kuliah) X4 : IPK (skala 4)
X1 : Lama pengalaman kerja sebelumnya (bulan) Membangkitkan variabel X1
set.seed(117) #setseed cuma buat kode biar data yang disimpen hasilnya sama, isinya bebas mau berapa digit
n <- 100
u <- runif(n)
x1 <- round(60*(-(log(1-u)/12)))
x1
## [1] 6 0 4 3 7 1 0 0 3 3 0 2 4 7 3 6 7 2 11 8 7 0 0 1 2
## [26] 1 5 1 3 3 1 3 16 0 2 2 1 11 2 4 4 11 19 3 4 0 2 2 9 0
## [51] 4 7 18 2 9 6 1 6 2 6 2 1 4 3 6 8 1 2 7 8 1 9 10 2 6
## [76] 1 4 2 6 1 1 10 3 3 5 7 10 3 12 15 9 12 12 0 8 5 24 8 5 1
?runif
## starting httpd help server ... done
set.seed(77)
x2 <- round(runif(n))
x2
## [1] 0 1 1 1 1 0 1 1 1 0 1 1 0 0 0 0 1 1 1 0 0 1 0 0 0 0 0 0 1 0 1 1 1 0 1 0 1
## [38] 1 1 0 0 0 1 0 1 1 0 0 0 0 1 1 0 0 0 0 1 0 1 1 0 1 0 0 0 1 0 1 1 1 0 1 1 1
## [75] 0 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 1 0
X3 : Tingkat pendidikan Keterangan yang digunakan (0:tidak kuliah, 1:kuliah)
set.seed(111)
x3 <- round(runif(n))
x3
## [1] 1 1 0 1 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 1 1 0 1 0 0 0 1 0
## [38] 1 1 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 0 0
## [75] 1 0 0 1 0 1 0 1 0 0 0 0 1 1 1 1 1 1 1 1 1 0 1 0 1 1
X4 adalah data IPK pelamar dengan skala 4
set.seed(234)
x4 <- round(rnorm(n,3,0.5),2)
x4
## [1] 3.33 1.97 2.25 3.74 3.73 3.07 3.10 1.48 2.76 2.46 3.03 3.55 2.99 3.26 3.50
## [16] 3.15 2.53 3.04 3.26 3.01 3.10 3.51 3.20 2.65 3.12 3.17 2.49 2.29 2.32 3.44
## [31] 2.83 2.67 2.95 3.35 3.22 3.75 3.11 2.25 3.06 2.48 3.11 2.78 3.74 2.72 2.78
## [46] 3.53 2.49 3.02 2.84 3.25 3.39 2.68 2.78 2.45 2.50 3.30 3.15 2.64 2.52 3.31
## [61] 3.33 3.12 3.21 3.24 2.53 3.04 3.29 2.95 3.21 3.18 3.52 3.10 3.70 2.81 2.51
## [76] 3.12 4.05 2.28 2.45 3.12 3.17 2.17 3.36 3.35 2.16 3.01 3.77 2.44 2.90 2.80
## [91] 2.78 2.53 3.69 3.18 3.51 3.07 3.54 3.58 2.86 3.43
b0 <- -11
b1 <- 3.5
b2 <- 0.5
b3 <- 2.7
b4 <- 3.2
set.seed(7)
datapendukung <- b0+(b1*x1)+(b2*x2)+(b3*x3)+(b4*x4)
datapendukung
## [1] 23.356 -1.496 10.700 14.668 25.936 2.324 -0.580 -3.064 8.832 7.372
## [11] 1.896 10.560 12.568 23.932 10.700 20.080 22.096 8.928 38.432 29.332
## [21] 23.420 0.732 -0.760 0.980 8.684 2.644 17.168 -0.172 10.124 13.208
## [31] 2.056 11.244 54.940 -0.280 6.804 10.700 2.952 37.900 8.992 13.636
## [41] 15.652 36.396 70.668 10.904 15.096 0.796 3.968 8.364 32.288 2.100
## [51] 17.048 25.276 60.896 3.840 31.200 23.260 5.780 18.448 4.564 23.792
## [61] 6.656 2.984 13.272 9.868 20.796 27.228 3.028 5.940 24.272 27.676
## [71] 6.464 33.620 36.340 5.492 20.732 2.984 16.460 6.496 18.340 5.684
## [81] 3.144 33.644 10.252 10.220 13.412 23.132 38.764 10.008 43.480 53.160
## [91] 32.096 42.296 45.508 2.376 31.432 16.324 87.528 28.456 18.852 6.176
p <- exp(datapendukung)/(1+exp(datapendukung))
p
## [1] 1.00000000 0.18302287 0.99997746 0.99999957 1.00000000 0.91084530
## [7] 0.35893259 0.04461689 0.99985404 0.99937179 0.86943813 0.99997407
## [13] 0.99999652 1.00000000 0.99997746 1.00000000 1.00000000 0.99986739
## [19] 1.00000000 1.00000000 1.00000000 0.67524401 0.31864627 0.72710822
## [25] 0.99983076 0.93364022 0.99999997 0.45710570 0.99995990 0.99999816
## [31] 0.88655248 0.99998691 1.00000000 0.43045378 0.99889190 0.99997746
## [37] 0.95035793 1.00000000 0.99987561 0.99999880 0.99999984 1.00000000
## [43] 1.00000000 0.99998162 0.99999972 0.68911819 0.98143978 0.99976694
## [49] 1.00000000 0.89090318 0.99999996 1.00000000 1.00000000 0.97895865
## [55] 1.00000000 1.00000000 0.99692080 0.99999999 0.98968717 1.00000000
## [61] 0.99871537 0.95184604 0.99999828 0.99994820 1.00000000 1.00000000
## [67] 0.95382316 0.99737488 1.00000000 1.00000000 0.99844388 1.00000000
## [73] 1.00000000 0.99589730 1.00000000 0.95184604 0.99999993 0.99849281
## [79] 0.99999999 0.99661159 0.95867165 1.00000000 0.99996471 0.99996357
## [85] 0.99999850 1.00000000 1.00000000 0.99995496 1.00000000 1.00000000
## [91] 1.00000000 1.00000000 1.00000000 0.91497878 1.00000000 0.99999992
## [97] 1.00000000 1.00000000 0.99999999 0.99792559
set.seed(21)
y <- rbinom(n,1,p)
y
## [1] 1 0 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 0 1 1 1
## [38] 1 1 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 1 1 1 1 1 1 1 1
## [75] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
datagab <- data.frame(y,x1,x2,x3,x4)
datagab
## y x1 x2 x3 x4
## 1 1 6 0 1 3.33
## 2 0 0 1 1 1.97
## 3 1 4 1 0 2.25
## 4 1 3 1 1 3.74
## 5 1 7 1 0 3.73
## 6 0 1 0 0 3.07
## 7 0 0 1 0 3.10
## 8 0 0 1 1 1.48
## 9 1 3 1 0 2.76
## 10 1 3 0 0 2.46
## 11 1 0 1 1 3.03
## 12 1 2 1 1 3.55
## 13 1 4 0 0 2.99
## 14 1 7 0 0 3.26
## 15 1 3 0 0 3.50
## 16 1 6 0 0 3.15
## 17 1 7 1 0 2.53
## 18 1 2 1 1 3.04
## 19 1 11 1 0 3.26
## 20 1 8 0 1 3.01
## 21 1 7 0 0 3.10
## 22 1 0 1 0 3.51
## 23 0 0 0 0 3.20
## 24 0 1 0 0 2.65
## 25 1 2 0 1 3.12
## 26 1 1 0 0 3.17
## 27 1 5 0 1 2.49
## 28 1 1 0 0 2.29
## 29 1 3 1 1 2.32
## 30 1 3 0 1 3.44
## 31 1 1 1 0 2.83
## 32 1 3 1 1 2.67
## 33 1 16 1 0 2.95
## 34 0 0 0 0 3.35
## 35 1 2 1 0 3.22
## 36 1 2 0 1 3.75
## 37 1 1 1 0 3.11
## 38 1 11 1 1 2.25
## 39 1 2 1 1 3.06
## 40 1 4 0 1 2.48
## 41 1 4 0 1 3.11
## 42 1 11 0 0 2.78
## 43 1 19 1 1 3.74
## 44 1 3 0 1 2.72
## 45 1 4 1 1 2.78
## 46 0 0 1 0 3.53
## 47 1 2 0 0 2.49
## 48 1 2 0 1 3.02
## 49 1 9 0 1 2.84
## 50 1 0 0 1 3.25
## 51 1 4 1 1 3.39
## 52 1 7 1 1 2.68
## 53 1 18 0 0 2.78
## 54 1 2 0 0 2.45
## 55 1 9 0 1 2.50
## 56 1 6 0 1 3.30
## 57 1 1 1 1 3.15
## 58 1 6 0 0 2.64
## 59 1 2 1 0 2.52
## 60 1 6 1 1 3.31
## 61 1 2 0 0 3.33
## 62 1 1 1 0 3.12
## 63 1 4 0 0 3.21
## 64 1 3 0 0 3.24
## 65 1 6 0 1 2.53
## 66 1 8 1 0 3.04
## 67 1 1 0 0 3.29
## 68 1 2 1 0 2.95
## 69 1 7 1 0 3.21
## 70 1 8 1 0 3.18
## 71 1 1 0 1 3.52
## 72 1 9 1 1 3.10
## 73 1 10 1 0 3.70
## 74 1 2 1 0 2.81
## 75 1 6 0 1 2.51
## 76 1 1 1 0 3.12
## 77 1 4 1 0 4.05
## 78 1 2 1 1 2.28
## 79 1 6 1 0 2.45
## 80 1 1 1 1 3.12
## 81 1 1 1 0 3.17
## 82 1 10 0 1 2.17
## 83 1 3 0 0 3.36
## 84 1 3 0 0 3.35
## 85 1 5 0 0 2.16
## 86 1 7 0 0 3.01
## 87 1 10 0 1 3.77
## 88 1 3 0 1 2.44
## 89 1 12 1 1 2.90
## 90 1 15 0 1 2.80
## 91 1 9 0 1 2.78
## 92 1 12 1 1 2.53
## 93 1 12 0 1 3.69
## 94 1 0 1 1 3.18
## 95 1 8 1 1 3.51
## 96 1 5 0 0 3.07
## 97 1 24 1 1 3.54
## 98 1 8 0 0 3.58
## 99 1 5 1 1 2.86
## 100 1 1 0 1 3.43
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) -16.035 6.997 -2.292 0.0219 *
## x1 5.798 2.542 2.281 0.0226 *
## x2 2.337 1.995 1.172 0.2414
## x3 5.108 2.597 1.967 0.0492 *
## x4 3.781 1.799 2.101 0.0356 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 55.754 on 99 degrees of freedom
## Residual deviance: 13.317 on 95 degrees of freedom
## AIC: 23.317
##
## Number of Fisher Scoring iterations: 12
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
You can also embed plots, for example:
Note that the echo = FALSE
parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.