Skip to content

Commit

Permalink
aligning scripts for the model evaluation with the code presented in …
Browse files Browse the repository at this point in the history
…the tutorial page
  • Loading branch information
czopluoglu committed Sep 28, 2023
1 parent ab01186 commit 17cdad1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 81 deletions.
47 changes: 20 additions & 27 deletions script/beta_irt/2_assess_fit.r
Original file line number Diff line number Diff line change
Expand Up @@ -257,20 +257,13 @@ mean(SSE_test)
obs_ <- c() # The observed average item score in the test data
pred_ <- c() # The posterior mean of average item scores in the test data

for(item in 1:50){

loc1 <- which(d_test$item==item)
obs <- d_test$resp[loc1]
obs_[item] <- mean(obs)

pred <- c()
for(item in 1:50){ # iterate over items

for(j in 1:3000){
pred[j] <- mean(Yhat_test[j,loc1])
}

pred_[item] <- mean(pred)
loc1 <- which(d_test$item==item)
obs <- d_test$resp[loc1]
obs_[item] <- mean(obs)

pred_[item] <- mean(rowMeans(Yhat_test[,loc1]))
}


Expand All @@ -291,17 +284,22 @@ pred_ <- c() # The posterior mean of standard deviation in the test data

for(item in 1:50){

loc1 <- which(d_test$item==item)
obs <- d_test$resp[loc1]
obs_[item] <- sd(obs)
loc1 <- which(d_test$item==item)
obs <- d_test$resp[loc1]
obs_[item] <- sd(obs)

pred <- c()
Yhat_test[,loc1]

for(j in 1:3000){
pred[j] <- sd(Yhat_test[j,loc1])
}
# Var[E(Y|params)], variance of expected grade conditional on model parameters

pred_[item] <- mean(pred)
comp1 <- var(colMeans(Yhat_test[,loc1]))

# E[Var(Y|params)], expected value of variance of grades conditional on model parameters

comp2 <- mean(apply(Yhat_test[,loc1],1,var))


pred_[item] <- sqrt(comp1 + comp2)

}

Expand Down Expand Up @@ -332,14 +330,9 @@ for(p in 1:1000){

loc1 <- which(d_train$id==d_train_wide$id[p])

tmp <- c()

for(j in 1:3000){
tmp[j] <- mean(Yhat_train[j,loc1])
}
tmp <- rowMeans(Yhat_train[,loc1])

score_posterior[p] <- mean(tmp)
setTxtProgressBar(pb, p)
score_posterior[p] <- sample(tmp,1)
}

cor(obs_score,score_posterior)
Expand Down
49 changes: 22 additions & 27 deletions script/sb_irt/2_assess_fit.r
Original file line number Diff line number Diff line change
Expand Up @@ -256,26 +256,21 @@ mean(SSE_test)

# Recovery of Average Item Scores


obs_ <- c() # The observed average item score in the test data
pred_ <- c() # The posterior mean of average item scores in the test data

for(item in 1:50){
for(item in 1:50){ # iterate over items

loc1 <- which(d_test$item==item)
obs <- d_test$resp[loc1]
obs_[item] <- mean(obs)

pred <- c()

for(j in 1:3000){
pred[j] <- mean(Yhat_test[j,loc1])
}

pred_[item] <- mean(pred)
loc1 <- which(d_test$item==item)
obs <- d_test$resp[loc1]
obs_[item] <- mean(obs)

pred_[item] <- mean(rowMeans(Yhat_test[,loc1]))
}



ggplot() +
geom_point(aes(y = obs_, x = pred_)) +
geom_abline(intercept = 0, slope = 1, linetype = "dashed") +
Expand All @@ -293,17 +288,22 @@ pred_ <- c() # The posterior mean of standard deviation in the test data

for(item in 1:50){

loc1 <- which(d_test$item==item)
obs <- d_test$resp[loc1]
obs_[item] <- sd(obs)
loc1 <- which(d_test$item==item)
obs <- d_test$resp[loc1]
obs_[item] <- sd(obs)

pred <- c()
Yhat_test[,loc1]

for(j in 1:3000){
pred[j] <- sd(Yhat_test[j,loc1])
}
# Var[E(Y|params)], variance of expected grade conditional on model parameters

comp1 <- var(colMeans(Yhat_test[,loc1]))

# E[Var(Y|params)], expected value of variance of grades conditional on model parameters

comp2 <- mean(apply(Yhat_test[,loc1],1,var))

pred_[item] <- mean(pred)

pred_[item] <- sqrt(comp1 + comp2)

}

Expand Down Expand Up @@ -334,14 +334,9 @@ for(p in 1:1000){

loc1 <- which(d_train$id==d_train_wide$id[p])

tmp <- c()

for(j in 1:3000){
tmp[j] <- mean(Yhat_train[j,loc1])
}
tmp <- rowMeans(Yhat_train[,loc1])

score_posterior[p] <- mean(tmp)
setTxtProgressBar(pb, p)
score_posterior[p] <- sample(tmp,1)
}

cor(obs_score,score_posterior)
Expand Down
48 changes: 21 additions & 27 deletions script/simplex_irt/2_assess_fit.r
Original file line number Diff line number Diff line change
Expand Up @@ -444,23 +444,17 @@ mean(SSE_test)

# Recovery of Average Item Scores


obs_ <- c() # The observed average item score in the test data
pred_ <- c() # The posterior mean of average item scores in the test data

for(item in 1:50){
for(item in 1:50){ # iterate over items

loc1 <- which(d_test$item==item)
obs <- d_test$resp[loc1]
obs_[item] <- mean(obs)

pred <- c()

for(j in 1:3000){
pred[j] <- mean(Yhat_test[j,loc1])
}

pred_[item] <- mean(pred)
loc1 <- which(d_test$item==item)
obs <- d_test$resp[loc1]
obs_[item] <- mean(obs)

pred_[item] <- mean(rowMeans(Yhat_test[,loc1]))
}


Expand All @@ -481,17 +475,22 @@ pred_ <- c() # The posterior mean of standard deviation in the test data

for(item in 1:50){

loc1 <- which(d_test$item==item)
obs <- d_test$resp[loc1]
obs_[item] <- sd(obs)
loc1 <- which(d_test$item==item)
obs <- d_test$resp[loc1]
obs_[item] <- sd(obs)

pred <- c()
Yhat_test[,loc1]

for(j in 1:3000){
pred[j] <- sd(Yhat_test[j,loc1])
}
# Var[E(Y|params)], variance of expected grade conditional on model parameters

pred_[item] <- mean(pred)
comp1 <- var(colMeans(Yhat_test[,loc1]))

# E[Var(Y|params)], expected value of variance of grades conditional on model parameters

comp2 <- mean(apply(Yhat_test[,loc1],1,var))


pred_[item] <- sqrt(comp1 + comp2)

}

Expand Down Expand Up @@ -522,14 +521,9 @@ for(p in 1:1000){

loc1 <- which(d_train$id==d_train_wide$id[p])

tmp <- c()

for(j in 1:3000){
tmp[j] <- mean(Yhat_train[j,loc1])
}
tmp <- rowMeans(Yhat_train[,loc1])

score_posterior[p] <- mean(tmp)
#print(p)
score_posterior[p] <- sample(tmp,1)
}

cor(obs_score,score_posterior)
Expand Down

0 comments on commit 17cdad1

Please sign in to comment.