Menjalankan Data

skenario

Y : Keputusan menolak/menerima pelamar kerja pada PT A posisi B X1 : Lama pengalaman kerja sebelum (bulan) X2 : Status pekerjaan saat ini (0: Bekerja, 1: Tidak bekerja) X3 : Tingkat pendidikan (0: Lulusan Sekolah Menengah, 1: Tidak bekerja) x4 : IPK (skala 4)

Menjalankan Data X1

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
?runif
## starting httpd help server ... done

Menjalankan data X2

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

Menjalankan Data

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

Menjalankan Data X4

X4 adalah data IPK Pelamar dengan skala 4

set.seed
## function (seed, kind = NULL, normal.kind = NULL, sample.kind = NULL) 
## {
##     kinds <- c("Wichmann-Hill", "Marsaglia-Multicarry", "Super-Duper", 
##         "Mersenne-Twister", "Knuth-TAOCP", "user-supplied", "Knuth-TAOCP-2002", 
##         "L'Ecuyer-CMRG", "default")
##     n.kinds <- c("Buggy Kinderman-Ramage", "Ahrens-Dieter", "Box-Muller", 
##         "user-supplied", "Inversion", "Kinderman-Ramage", "default")
##     s.kinds <- c("Rounding", "Rejection", "default")
##     if (length(kind)) {
##         if (!is.character(kind) || length(kind) > 1L) 
##             stop("'kind' must be a character string of length 1 (RNG to be used).")
##         if (is.na(i.knd <- pmatch(kind, kinds) - 1L)) 
##             stop(gettextf("'%s' is not a valid abbreviation of an RNG", 
##                 kind), domain = NA)
##         if (i.knd == length(kinds) - 1L) 
##             i.knd <- -1L
##     }
##     else i.knd <- NULL
##     if (!is.null(normal.kind)) {
##         if (!is.character(normal.kind) || length(normal.kind) != 
##             1L) 
##             stop("'normal.kind' must be a character string of length 1")
##         normal.kind <- pmatch(normal.kind, n.kinds) - 1L
##         if (is.na(normal.kind)) 
##             stop(gettextf("'%s' is not a valid choice", normal.kind), 
##                 domain = NA)
##         if (normal.kind == 0L) 
##             stop("buggy version of Kinderman-Ramage generator is not allowed", 
##                 domain = NA)
##         if (normal.kind == length(n.kinds) - 1L) 
##             normal.kind <- -1L
##     }
##     if (!is.null(sample.kind)) {
##         if (!is.character(sample.kind) || length(sample.kind) != 
##             1L) 
##             stop("'sample.kind' must be a character string of length 1")
##         sample.kind <- pmatch(sample.kind, s.kinds) - 1L
##         if (is.na(sample.kind)) 
##             stop(gettextf("'%s' is not a valid choice", sample.kind), 
##                 domain = NA)
##         if (sample.kind == 0L) 
##             warning("non-uniform 'Rounding' sampler used", domain = NA)
##         if (sample.kind == length(s.kinds) - 1L) 
##             sample.kind <- -1L
##     }
##     .Internal(set.seed(seed, i.knd, normal.kind, sample.kind))
## }
## <bytecode: 0x00000297b9cde978>
## <environment: namespace:base>
x4 <- round(rnorm(n,3,0.5),2)
x4
##   [1] 3.13 2.99 2.98 3.68 2.89 3.76 2.23 3.29 3.06 3.11 3.19 2.75 2.83 2.49 2.46
##  [16] 3.15 3.22 3.03 3.46 4.03 2.75 1.85 3.50 2.65 2.66 3.51 2.86 2.39 3.09 2.93
##  [31] 3.00 3.19 2.81 3.32 2.89 3.17 3.55 3.22 2.84 3.57 3.50 3.27 3.12 2.69 3.68
##  [46] 2.70 4.09 3.77 2.88 2.49 2.64 3.13 2.88 2.83 2.52 2.98 2.61 2.17 2.81 3.46
##  [61] 2.71 3.30 2.19 2.97 3.26 3.15 3.05 2.68 2.58 2.49 3.06 2.53 2.75 2.87 3.92
##  [76] 2.67 3.12 3.04 2.52 2.96 3.72 3.23 3.02 2.79 1.97 3.57 2.27 3.37 3.95 2.28
##  [91] 3.35 2.87 2.21 2.24 2.20 2.73 2.27 3.34 4.05 2.36

Membangkitkan data Y

Melakukan koefisien

b0 <- -11
b1 <- 3.5
b2 <- 0.5
b3 <- 2.7
b4 <- 3.2
set.seed(1)
datapendukung <- b0+(b1*x1)+(b2*x2)+(b3*X3)+(b4*x4)
datapendukung
##   [1]  6.516  5.268 13.036  3.976 11.448 11.532 26.836  9.728 15.992  2.952
##  [11] 19.408 36.300  8.256 10.168 21.372 22.780  2.804  5.696  7.072 26.096
##  [21] 14.500 18.620 17.400 25.180 11.212  6.432 25.852 38.348 12.888  5.376
##  [31] 12.300 47.408  7.692 55.324 19.248 37.644  7.060 17.304 79.088  3.924
##  [41]  7.700 34.464 27.484 29.608 18.276  8.140 30.088 39.564  1.716  7.168
##  [51]  4.948  3.016  4.416  5.056 14.264  2.036  1.352  2.144 18.192  3.572
##  [61] 11.372 17.060 52.508 20.004 13.132  6.080 12.460 10.776  3.956 18.468
##  [71] 12.492  7.296 14.500 57.684 19.044 15.544 34.484 26.428 29.064 -1.528
##  [81] 11.904 20.036 44.164 70.628 -4.696 14.424 23.964  6.484 11.840 20.796
##  [91] 42.220  4.884  3.072  9.868 38.540  5.236 13.464  3.688  1.960 23.752
p <- exp(datapendukung)/(1+exp(datapendukung))
p
##   [1] 0.998522610 0.994872518 0.999997820 0.981584945 0.999989329 0.999990189
##   [7] 1.000000000 0.999940412 0.999999887 0.950357929 0.999999996 1.000000000
##  [13] 0.999740372 0.999961622 0.999999999 1.000000000 0.942891594 0.996651872
##  [19] 0.999152185 1.000000000 0.999999496 0.999999992 0.999999972 1.000000000
##  [25] 0.999986489 0.998393356 1.000000000 1.000000000 0.999997472 0.995395014
##  [31] 0.999995448 1.000000000 0.999543744 1.000000000 0.999999996 1.000000000
##  [37] 0.999141959 0.999999969 1.000000000 0.980621075 0.999547378 1.000000000
##  [43] 1.000000000 1.000000000 0.999999988 0.999708448 1.000000000 1.000000000
##  [49] 0.847612893 0.999229731 0.992952431 0.953291742 0.988061778 0.993669340
##  [55] 0.999999361 0.884525335 0.794456411 0.895106767 0.999999987 0.972668408
##  [61] 0.999988487 0.999999961 1.000000000 0.999999998 0.999998019 0.997717047
##  [67] 0.999996121 0.999979105 0.981219922 0.999999990 0.999996243 0.999322213
##  [73] 0.999999496 1.000000000 0.999999995 0.999999822 1.000000000 1.000000000
##  [79] 1.000000000 0.178286498 0.999993237 0.999999998 1.000000000 1.000000000
##  [85] 0.009049097 0.999999456 1.000000000 0.998474643 0.999992790 0.999999999
##  [91] 1.000000000 0.992490138 0.955722883 0.999948196 1.000000000 0.994706668
##  [97] 0.999998579 0.975588820 0.876532952 1.000000000
set.seed(2)
y <- rbinom(n,1,p)
y
##   [1] 1 1 1 1 1 1 1 1 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
##  [38] 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 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 3.13
## 2   1  1  1  1 2.99
## 3   1  4  1  0 2.98
## 4   1  0  1  1 3.68
## 5   1  3  0  1 2.89
## 6   1  3  0  0 3.76
## 7   1  8  0  1 2.23
## 8   1  2  1  1 3.29
## 9   1  4  1  1 3.06
## 10  1  1  1  0 3.11
## 11  1  5  0  1 3.19
## 12  1 11  0  0 2.75
## 13  1  2  1  1 2.83
## 14  1  3  0  1 2.49
## 15  1  7  0  0 2.46
## 16  1  6  0  1 3.15
## 17  0  1  0  0 3.22
## 18  1  2  0  0 3.03
## 19  1  2  0  0 3.46
## 20  1  6  1  1 4.03
## 21  1  4  0  1 2.75
## 22  1  6  0  1 1.85
## 23  1  4  1  1 3.50
## 24  1  7  1  1 2.65
## 25  1  3  1  1 2.66
## 26  1  1  0  1 3.51
## 27  1  7  1  1 2.86
## 28  1 11  1  1 2.39
## 29  1  4  0  0 3.09
## 30  1  2  0  0 2.93
## 31  1  3  1  1 3.00
## 32  1 13  0  1 3.19
## 33  1  2  0  1 2.81
## 34  1 15  1  1 3.32
## 35  1  6  0  0 2.89
## 36  1 11  0  0 3.17
## 37  1  1  1  1 3.55
## 38  1  5  1  0 3.22
## 39  1 23  1  0 2.84
## 40  1  1  0  0 3.57
## 41  1  2  1  0 3.50
## 42  1 10  0  0 3.27
## 43  1  8  1  0 3.12
## 44  1  9  1  0 2.69
## 45  1  5  0  0 3.68
## 46  1  3  0  0 2.70
## 47  1  8  0  0 4.09
## 48  1 11  0  0 3.77
## 49  1  1  0  0 2.88
## 50  1  2  1  1 2.49
## 51  1  2  1  0 2.64
## 52  1  1  1  0 3.13
## 53  1  1  0  1 2.88
## 54  1  2  0  0 2.83
## 55  1  4  1  1 2.52
## 56  1  1  0  0 2.98
## 57  1  1  1  0 2.61
## 58  1  1  0  1 2.17
## 59  1  5  0  1 2.81
## 60  1  1  0  0 3.46
## 61  1  3  1  1 2.71
## 62  1  5  0  0 3.30
## 63  1 16  1  0 2.19
## 64  1  6  1  0 2.97
## 65  1  3  1  1 3.26
## 66  1  2  0  0 3.15
## 67  1  3  1  1 3.05
## 68  1  3  0  1 2.68
## 69  1  1  1  1 2.58
## 70  1  6  1  0 2.49
## 71  1  3  1  1 3.06
## 72  1  2  1  1 2.53
## 73  1  4  0  1 2.75
## 74  1 17  0  0 2.87
## 75  1  5  0  0 3.92
## 76  1  5  1  0 2.67
## 77  1 10  1  0 3.12
## 78  1  7  1  1 3.04
## 79  1  9  1  0 2.52
## 80  0  0  0  0 2.96
## 81  1  3  1  0 3.72
## 82  1  5  1  1 3.23
## 83  1 13  0  0 3.02
## 84  1 20  0  1 2.79
## 85  0  0  0  0 1.97
## 86  1  4  0  0 3.57
## 87  1  7  1  1 2.27
## 88  1  1  1  1 3.37
## 89  1  2  1  1 3.95
## 90  1  7  0  0 2.28
## 91  1 12  1  0 3.35
## 92  1  1  1  1 2.87
## 93  1  2  0  0 2.21
## 94  1  3  1  1 2.24
## 95  1 12  1  0 2.20
## 96  1  2  1  0 2.73
## 97  1  4  1  1 2.27
## 98  1  1  1  0 3.34
## 99  0  0  0  0 4.05
## 100 1  7  0  1 2.36
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) -1.965e+01  5.757e+03  -0.003    0.997
## x1           2.092e+01  5.757e+03   0.004    0.997
## x2           2.104e+01  2.038e+04   0.001    0.999
## X3           2.082e+01  2.084e+04   0.001    0.999
## x4           3.538e-02  4.206e+00   0.008    0.993
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 33.589  on 99  degrees of freedom
## Residual deviance:  5.004  on 95  degrees of freedom
## AIC: 15.004
## 
## Number of Fisher Scoring iterations: 24

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:

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

Including Plots

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.