Advertisement
titounnes

Rasch-dikotomis

Nov 11th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.72 KB | None | 0 0
  1. # install.packages("eRm")
  2. # install.packages("ltm")
  3. # install.packages("difR")
  4. # install.packages("MASS")
  5. # install.packages("xtable")
  6.  
  7. library("eRm")
  8. library("ltm")
  9. library("difR")
  10. library("xtable")
  11.  
  12. #Pastikan nama file CSV sesuai dengan nama file yang dimiliki
  13. #Kebetulan data kita kolom paling atas bernama Person, nantinya desesiaukan dengan penamaan yang kita berikan
  14. raw <- read.csv(file = 'NilaiTes.csv', row.names = "Person")
  15. sink('log/output.txt')
  16. # Data skor adalah sepuluh kolom pertama setelah person, maka 1:10
  17. score <- raw[,1:24]
  18. print("Data Score: ")
  19. print(score)
  20.  
  21.  
  22. # Menyimpan data log, pastikan nama folder disesuaikan dengan
  23. # memngekspor data ke latex, kalau suatu saat dibutuhkan
  24. print(xtable(score, type = "latex"), file = "log/latex.tex")
  25.  
  26. # Menginisiasi Rasch model untuk 1 parameter logistik (1PL)
  27. res_rm_1 <- RM(score)
  28. # Mencetak data
  29. print("Hasil iterasi dengan Rasg Model 1Pl : ")
  30. print(res_rm_1)
  31. # Mencetak ringkasan data
  32. print("Ringkasan data : ")
  33. summary(res_rm_1)
  34.  
  35. # Menghitung nilai indek kesukaran (difficulty logit)
  36. print("Indek kesukaran butir : ")
  37. betas <- -coef(res_rm_1)
  38.  
  39. # mencetak grafik difficulty logit item no 1-12
  40. # Jika aitemnya bnayk, untuk memudahkan analisis bisa dicetak per-12 item
  41. png(file="plot/ICC_1_12.png", width=600, height=350)
  42. # 1:10 artinya item no 1 - 12
  43. plotjointICC(res_rm_1, item.subset = 1:12, cex = .6)
  44. # Menambahkan sumbu vertikal berwarna abu-abu, silahkan ganti warna sesuai selera
  45. abline(v = -0.18, col = "grey")
  46. # Menambahkan sumbu horizontal berwarna abu-abu, silahkan ganti warna sesuai selera
  47. abline(h = .5, col = "grey")
  48. # Menambahkan sumbu memabtu kita untuk memperlihatkan item fit dan difficulty logit dari setiap item,
  49. # Jika item bersifat normal, berupa garis menyerupai huruf S, dari kiri ke kanan naik
  50. dev.off()
  51.  
  52. # mencetak grafik difficulty logit item no 13-24
  53. png(file="plot/ICC_13_24.png", width=600, height=350)
  54. # 1:10 artinya item no 13 - 24
  55. plotjointICC(res_rm_1, item.subset = 13:24, cex = .6)
  56. # Menambahkan sumbu vertikal berwarna abu-abu, silahkan ganti warna sesuai selera
  57. abline(v = -0.18, col = "grey")
  58. # Menambahkan sumbu horizontal berwarna abu-abu, silahkan ganti warna sesuai selera
  59. abline(h = .5, col = "grey")
  60. # Menambahkan sumbu memabtu kita untuk memperlihatkan item fit dan difficulty logit dari setiap item,
  61. # Jika item bersifat normal, berupa garis menyerupai huruf S, dari kiri ke kanan naik
  62. dev.off()
  63.  
  64. # Mengurutkan nilai indek kesukaran
  65. print("Ringkasan Indek kesukaran : ")
  66. round(sort(betas), 5)
  67. # Menampilkan rata-rata dari indeks kesukaran
  68. print("Nilai rerata: ")
  69. mean(betas[ 1:24]) # Want-items
  70.  
  71. # Menampilkan peta person-item, dari plot ini kita bisa mengetahui item maupun person yang non fit
  72. # Item non fit adalah item yang tidak mengukur sesuai dengan indikator
  73. # Person non fit adalah person yang tidak sungguh-sungguh dalam pengukuran
  74. png(file="plot/Map Person-item.png",width=600, height=350)
  75. plotPImap(res_rm_1, cex.gen = .55)
  76. dev.off()
  77.  
  78. # Map person - item dirutkan, untuk memudahkan
  79. png(file="plot/Map Person-item-sorted.png",width=600, height=350)
  80. plotPImap(res_rm_1, cex.gen = .55, sorted = TRUE)
  81. dev.off()
  82.  
  83. # Menampilkan data normal
  84. tmp1 <- RM(score, sum0 = FALSE)
  85. print("Menampilkan data ability : ")
  86. print(tmp1)
  87. print("Rerata ability person : ")
  88. round(coef(tmp1), 5)
  89.  
  90.  
  91. # Menginisiasi Rasch model untuk 2 parameter logistik (2PL)
  92. res_rm_2 <- rasch(score)
  93. print("Analisis Rasch model 2PL : ")
  94. print(res_rm_2)
  95.  
  96. # Menghitung korelasi antara koefisien logistik 2 PL dengan 1 PL
  97. print("Korelasi antara 2PL dengan 1PL : ")
  98. cor(coef(res_rm_2)[, 1], betas)
  99. # A 2PL model cannot be estimated with eRm, but with the package ltm, for example.
  100. # ltm() takes a formula with a tilde (~) as its first argument. The left-hand side
  101. # must be the data and the right-hand side are the latent variables (only one
  102. # here).
  103.  
  104.  
  105. res_2pl_1 <- ltm(score ~ z1)
  106. print("Menentukan nilai estimasi untuk 2PL : ")
  107. print(res_2pl_1)
  108.  
  109. # Plot karakteristik item
  110. png(file="plot/Item_characteristic_1_24.png",width=600, height=350)
  111. plot(res_2pl_1, items = 1:24)
  112. abline(v = -0.18, col = "grey")
  113. abline(h = .5, col = "grey")
  114. dev.off()
  115.  
  116. # Menentukan nilai analisis ANOVA antara 1 PL dengan 2 PL
  117.  
  118. print("Hasil analsisi anova 1PL dengan 2PL : ")
  119. anova(res_rm_2, res_2pl_1)
  120. # Korelasi antara 1PL dengan 2PL
  121. print("Koefisien korelasi antara 1PL dengan 2PL : ")
  122. cor(coef(res_rm_2)[, 1], coef(res_2pl_1)[, 1])
  123.  
  124.  
  125. # Mereduksi data yang tidak fit
  126.  
  127. lrt_1 <- LRtest(res_rm_1, splitcr = raw$Gender)
  128. png(file="plot/Graphical_model_check.png",width=600, height=350)
  129. plotGOF(lrt_1, conf = list(), tlab = "number", xlab = "Women", ylab = "Men")
  130. dev.off()
  131. print(lrt_1)
  132.  
  133. tmp1 <- RM(score[, -6])
  134. print("Data setelah direduksi: ")
  135. LRtest(tmp1, splitcr = raw$Gender)
  136. print(tmp1)
  137.  
  138. # Uji Wald
  139. Waldtest(res_rm_1, splitcr = raw$Gender)
  140.  
  141. # Uji Item fit
  142. pp_ml_1 <- person.parameter(res_rm_1)
  143. itemfit(pp_ml_1)
  144.  
  145. # Plot item map
  146. png(file="plot/ItemMap.png",width=600, height=350)
  147. plotPWmap(res_rm_1)
  148. dev.off()
  149.  
  150. # Uji Mantel-Haenszel
  151. # Detection of Differential Item Functioning
  152. tmp1 <- difMH(score, group = raw$Gender, focal.name = 1)
  153. tmp1
  154.  
  155. png(file="plot/Uji mantel-Hanzel.png", width=600, height=350)
  156. plot(tmp1)
  157. dev.off()
  158.  
  159. # Pengujian cgi-square untuk uji Lord
  160. print("Nilai Chi-Square Uji Lord 1 PL")
  161. tmp1 <- difLord(score, group = raw$Gender, focal.name = 1, model = "1PL", discr = NULL)
  162.  
  163. # Kurva hasil uji chi-square
  164. png(file="plot/Chi-square Pengaruh Gender.png", width=600, height=350)
  165. plot(tmp1)
  166. dev.off()
  167.  
  168. # Data plot individual, contohnya no. 6
  169. png(file="plot/Item_no_6.png",
  170. width=600, height=350)
  171. plot(tmp1, plot = "itemCurve", item = 6)
  172. dev.off()
  173.  
  174. # Parameter person
  175. # Nilai esrimasi maksimum-likehood untuk person (ML)
  176.  
  177. print("Nilai estimasi maksimum-likehood 1PL: ")
  178. tmp1 <- person.parameter(res_rm_1)
  179. pp_ml <- coef(tmp1)
  180. # MAP dan EAP
  181. pp_map <- factor.scores(res_rm_2, method = "EB", resp.patterns = score)
  182. pp_eap <- factor.scores(res_rm_2, method = "EAP", resp.patterns = score)
  183. tmp1 <- data.frame(ML = pp_ml, MAP = pp_map$score.dat$z1, EAP = pp_eap$score.dat$z1)
  184. round(cor(tmp1), 4)
  185.  
  186. png(file="plot/Kurva_ML.png", width=600, height=350)
  187. plot(tmp1[, 1:2])
  188. dev.off()
  189.  
  190.  
  191. print("Nilai estimasi maksimum-likehood 2PL: ")
  192. pp_2pl <- factor.scores(res_2pl_1, method = "EB", resp.patterns = score)
  193. cor(pp_map$score.dat$z1, pp_2pl$score.dat$z1)
  194. #> [1] 0.9956129
  195.  
  196. # Nilai item tes no 1-10
  197. res_2pl_1
  198. png(file="plot/Item_test_1_10.png",
  199. width=600, height=350)
  200. plot(res_2pl_1, items = 1:10, type = "IIC", ylim = c(0, 1.3))
  201. dev.off()
  202.  
  203. # Kurva standard
  204. png(file="plot/Item_test_standar.png",
  205. width=600, height=350)
  206. plot(res_2pl_1, items = 0, type = "IIC")
  207. dev.off()
  208. sink()
  209.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement