R/exams 中未找到真实数据
Real data not found in R/exams
我正在尝试根据适合真实数据集的 Logit 模型的结果开发考试。我尝试加载数据集,拟合模型,并使用 r varname
语法包含从模型中提取的一些变量。
我首先使用练习中生成的人工数据开发了一个小示例。效果很好,这是相应的 Rmd 文件:
```{r data generation, echo = FALSE, results = "hide"}
library(tidyverse)
d <- tibble(y = rbinom(100, 1, 0.6), x1 = rnorm(100), x2=rnorm(100))
# randomize exams
nsize <- sample(50:150, 1)
sampled_dat <- sample(1:nrow(d), nsize, replace = TRUE)
fd <- d[sampled_dat, ]
fmodel <- glm(y ~ x1 + x2, data = fd, family = binomial("logit"))
```
Question
========
`r nrow(fd)`
```{r}
summary(fmodel)
```
Choose the correct answer.
Answerlist
----------
* sol1 `r nrow(fd)`
* sol2
Meta-information
================
exname: bdvDeviance
extype: schoice
exsolution: 10
exshuffle: TRUE
```
这在启动时按预期工作
elearn_exam <- c("ess3.Rmd")
set.seed(1234567)
exams2nops(elearn_exam, n = 2, language = "en",
institution = "U", title = "Exam",
dir = "nops_pdf", name = "BDV", date = "2018-01-08", duplex = FALSE)
但是,这是加载真实数据集的类似练习:
```{r data generation, echo = FALSE, results = "hide"}
load("d.Rdata")
# randomize exams
nsize <- sample(180:250, 1)
sampled_dat <- sample(1:nrow(d), nsize, replace = TRUE)
fd <- d[sampled_dat, ]
logitModel <- glm(Adopted ~ CultArea + Trained + LabRice+ Education + ExtContact, data = fd, family=binomial("logit"))
```
Question
========
`r nrow(fd)`
Choose the correct answer.
Answerlist
----------
* When adding variables, the deviance did not change. The variables did not bring some useful information.
* sol2 `r nrow(fd)`
Meta-information
================
exname: bdvDeviance
extype: schoice
exsolution: 10
exshuffle: TRUE
```
这一次,我得到以下错误:
> elearn_exam <- c("ess4.Rmd")
> set.seed(1234567)
> exams2nops(elearn_exam, n = 2, language = "en",
+ institution = "Uu", title = "Exam",
+ dir = "nops_pdf", name = "BDV_R", date = "2018-01-08", duplex = FALSE)
Quitting from lines 14-35 (ess4.Rmd)
Error in nrow(fd) : object 'fd' not found
我不明白第二种情况是什么问题。显然,将 fd
变量包含在 r fd
中时未找到该变量。问题不是来自回归,因为在编织 Rmd 文件时它工作正常。
您使用真实数据集的第二个示例只是通过 load("d.Rdata")
加载相应的数据文件,假设它在当前工作目录中。但是,当使用任何 exams2xyz()
界面时,练习都在一个临时目录中处理,以免弄乱用户的工作空间。因此,在该目录中找不到 d.Rdata
文件,因此无法加载。并且由于这个问题,无法创建和插入 fd
对象。简而言之,r fd
代码运行良好,问题在于加载数据。
为避免此问题,您必须在 load("/path/to/d.Rdata")
中指定数据文件的完整绝对路径,或者您需要在加载数据之前将数据复制到临时目录。对于后者,有方便的功能 include_supplement()
将补充文件复制到临时目录。默认情况下,它从练习所在的目录中获取它们。因此您只需添加:
include_supplement("d.Rdata")
加载数据文件之前。请注意,当文件不在练习目录本身而是某个子目录中时,您可以添加参数 recursive = TRUE
。然后递归搜索子目录。
我正在尝试根据适合真实数据集的 Logit 模型的结果开发考试。我尝试加载数据集,拟合模型,并使用 r varname
语法包含从模型中提取的一些变量。
我首先使用练习中生成的人工数据开发了一个小示例。效果很好,这是相应的 Rmd 文件:
```{r data generation, echo = FALSE, results = "hide"}
library(tidyverse)
d <- tibble(y = rbinom(100, 1, 0.6), x1 = rnorm(100), x2=rnorm(100))
# randomize exams
nsize <- sample(50:150, 1)
sampled_dat <- sample(1:nrow(d), nsize, replace = TRUE)
fd <- d[sampled_dat, ]
fmodel <- glm(y ~ x1 + x2, data = fd, family = binomial("logit"))
```
Question
========
`r nrow(fd)`
```{r}
summary(fmodel)
```
Choose the correct answer.
Answerlist
----------
* sol1 `r nrow(fd)`
* sol2
Meta-information
================
exname: bdvDeviance
extype: schoice
exsolution: 10
exshuffle: TRUE
```
这在启动时按预期工作
elearn_exam <- c("ess3.Rmd")
set.seed(1234567)
exams2nops(elearn_exam, n = 2, language = "en",
institution = "U", title = "Exam",
dir = "nops_pdf", name = "BDV", date = "2018-01-08", duplex = FALSE)
但是,这是加载真实数据集的类似练习:
```{r data generation, echo = FALSE, results = "hide"}
load("d.Rdata")
# randomize exams
nsize <- sample(180:250, 1)
sampled_dat <- sample(1:nrow(d), nsize, replace = TRUE)
fd <- d[sampled_dat, ]
logitModel <- glm(Adopted ~ CultArea + Trained + LabRice+ Education + ExtContact, data = fd, family=binomial("logit"))
```
Question
========
`r nrow(fd)`
Choose the correct answer.
Answerlist
----------
* When adding variables, the deviance did not change. The variables did not bring some useful information.
* sol2 `r nrow(fd)`
Meta-information
================
exname: bdvDeviance
extype: schoice
exsolution: 10
exshuffle: TRUE
```
这一次,我得到以下错误:
> elearn_exam <- c("ess4.Rmd")
> set.seed(1234567)
> exams2nops(elearn_exam, n = 2, language = "en",
+ institution = "Uu", title = "Exam",
+ dir = "nops_pdf", name = "BDV_R", date = "2018-01-08", duplex = FALSE)
Quitting from lines 14-35 (ess4.Rmd)
Error in nrow(fd) : object 'fd' not found
我不明白第二种情况是什么问题。显然,将 fd
变量包含在 r fd
中时未找到该变量。问题不是来自回归,因为在编织 Rmd 文件时它工作正常。
您使用真实数据集的第二个示例只是通过 load("d.Rdata")
加载相应的数据文件,假设它在当前工作目录中。但是,当使用任何 exams2xyz()
界面时,练习都在一个临时目录中处理,以免弄乱用户的工作空间。因此,在该目录中找不到 d.Rdata
文件,因此无法加载。并且由于这个问题,无法创建和插入 fd
对象。简而言之,r fd
代码运行良好,问题在于加载数据。
为避免此问题,您必须在 load("/path/to/d.Rdata")
中指定数据文件的完整绝对路径,或者您需要在加载数据之前将数据复制到临时目录。对于后者,有方便的功能 include_supplement()
将补充文件复制到临时目录。默认情况下,它从练习所在的目录中获取它们。因此您只需添加:
include_supplement("d.Rdata")
加载数据文件之前。请注意,当文件不在练习目录本身而是某个子目录中时,您可以添加参数 recursive = TRUE
。然后递归搜索子目录。