在考试中多次进行相同的练习并确保不同代

问题描述 投票:0回答:1

我有很多措辞非常相似的问题,我不想为每个问题都做练习。在一次考试中,我想给每个学生出 k 个这样的问题,所以我必须在每次考试中调用该练习三次。由于我不希望学生多次收到相同的问题,因此我想我会在每 k 次调用中选择一个包含 k 个问题的新样本。我已经放置了一个计数到 k 的计数器,但是在 exams2nops 运行代码两次时遇到了一些麻烦,因此计数器从 2 开始。这意味着最后一个问题可能是第一个 k-1 的重复。我想出了一种解决方法,但它不是很优雅。希望有更优雅的方法。

这是我现在提出的练习(用一些虚拟文本替换了确切的问题,以缩短本文的长度)。

```{r data generation, echo = FALSE, results = "hide"}
## parameters

k <- 3

envir <- .GlobalEnv
N <- envir$N

if (length(N)==0) {
list1 <- envir$list1 <- c("Option1","Option2","Option3","Option4","Option5","Option6","Option7","Option8","Option9","Option10","Option11","Option12","Option13","Option14","Option15")
list2 <- envir$list2 <- rep(c("001","010","100"),each=5)}

if (length(N)!=k)  {
  N <- envir$N <- sample(1:15,size=k)

  envir$no <- 0
} # Starts the counter over again and generates a new sample whenever a rotation is through.

envir$no <- envir$no+1

if (envir$no==k) N <- envir$N <- 1:100
# The 1:100 is kinda random. Just needs to be larger than any reasonable k.

if (envir$no==2&length(envir$M)==0) 
{
  envir$no <- 1
  envir$M <- 0
}# This is my solution to the counter issue. When the counter first hits 2, it's set back to 1, but because M exists afterwards, this is never called again.

```

Question
========

`r list1[N[no]]`

Answerlist
----------
* A
* B
* C

Meta-information
================
extype: schoice
exsolution: `r list2[N[no]]`
exname: questions
exshuffle: 3
r r-exams
1个回答
0
投票

使用通用环境共享信息:

我不确定我是否遵循您代码的所有细节,但我认为您可以通过设置各种

envir = ...
接口的
exams2xyz()
参数来完成您想做的事情。这样做,您可以在
knit
进行练习时重新使用相同的环境来运行 R 代码。因此,您可以存储在先前运行中使用了哪些选项的信息,并将它们从后续运行中排除。

确定新迭代何时开始:

然后您只需在运行一定次数后使用此信息重置变量即可。如果您不想在练习中固定练习的次数,您可以使用

match_exams_iteration()
便利功能。这会告诉您当前处于
n
的哪一个
exams2xyz()
运行中。 (备注:该函数在包的 2.4-1 版本中引入,但尚未在命名空间中导出。因此我们需要三冒号 ::: 来访问它。我们将在 2.4-2 版本中导出它。 )

演示练习:

因为我不确定您问题中练习的所有细节,所以我在这里介绍一个新练习

superhero.Rmd
。它包含关于不同超级英雄群体的七个不同的多项选择任务。

```{r, include=FALSE}
## seven superhero multiple-choice tasks
tasks <- rbind(
  c("Which of the following characters is part of the Justice League?", "Batman", "Aquaman", "Wonder Woman", "Wolverine", "Black Widow", "11100"),
  c("Which of the following characters is part of the Avengers?", "Iron Man", "Ant-Man", "Superman", "Magneto", "Deadpool", "11000"),
  c("Which of the following characters is part of the X-Men?", "Cyclops", "Beast", "Spider-Man", "Captain America", "The Flash", "11000"),
  c("Which of the following characters is part of the Guardians of the Galaxy?", "Star-Lord", "Groot", "Nebula", "Professor X", "Cyborg", "11100"),
  c("Which of the following villains are adversaries of Batman?", "Penguin", "Bane", "Poison Ivy", "Riddler", "Thanos", "11110"),
  c("Which of the following villains are adversaries of the Avengers?", "Ultron", "Lex Luthor", "Joker", "Harley Quinn", "General Zod", "10000"),
  c("Which of the following characters are romantic interests of Spider-Man?", "Mary Jane Watson", "Gwen Stacy", "Selina Kyle", "Lois Lane", "Pepper Potts", "11000")
)
colnames(tasks) <- c("question", paste0("answer", 1:5), "solution")

## initialization of iteration and reset the task id used
if(!exists("iter")) iter <- 0
if(exams:::match_exams_iteration() > iter) id_used <- NULL

## query current iteration and sample task id
iter <- exams:::match_exams_iteration()
id <- sample(setdiff(1:nrow(tasks), id_used), 1)

## update the task id used so far
id_used <- c(id_used, id)
```

Question
========
Iteration: `r iter`.

Task IDs used: `r paste(id_used, collapse = ", ")`.

`r tasks[id, "question"]`

```{r, echo = FALSE, results = "asis"}
answerlist(tasks[id, 2:6], markup = "markdown")
```

Meta-information
================
exname: superhero
extype: mchoice
exsolution: `r tasks[id, "solution"]`
exshuffle: TRUE

请注意,为了便于理解正在发生的情况,我显示了当前迭代和问题中迄今为止使用的任务 ID。

与 exams2nops 一起使用:

为了表明该练习可以在同一考试中重复使用,我设置了一个考试,该练习包含五次。然后我用这五个练习生成三个随机版本的 NOPS 考试。

library("exams")
set.seed(0)
shared_env <- new.env()
exams2nops(rep("superhero.Rmd", 5), n = 3, env = shared_env)

生成的 PDF 的屏幕截图链接如下(点击查看大图)。这表明第一个屏幕截图始终具有迭代 1 以及所选任务 ID 如何演变。第二个和第三个屏幕截图与此类似。

nops1.pdf screenshot nops2.pdf screenshot nops3.pdf screenshot

当您不共享环境时,该练习也有效,但它总是随机采样七个任务之一。另请注意,

.GlobalEnv
不受这些影响。如果您想要的话,您也可以使用
envir = .GlobalEnv

© www.soinside.com 2019 - 2024. All rights reserved.