I created a cloze question combining mchoice and num. However I cannot import the question in Moodle as it says
Error importing question Invalid embedded answers (Cloze) question (One of the answers should have a score of 100% so it is possible to get full marks for this question.).
If I turn it into a single mchoice question (deleting the num question) or I turn it into a single num chestion (deleting the mchoice part) it works. I could not find such an example on r-exams.org, that is why I turned here.
This is my Code:
```{r data generation, echo = FALSE, results = "hide"}
library(exams)
Fragen=data.frame(
Fragen=c(
"Vergleich Schlachtgewicht (g) männlicher und weiblicher Hühner (Hähne/Hennen) der gleichen Linie.",
"Untersuchung der Anzahl Insektenarten, welche auf unterschiedlichen Feldern vorkommen (Magerwiese, Klee, je 10 Felder).",
"Untersuchung Sulfatgehalt (mg) bei Wasserproben aus der Limmat. Die Proben wurden an zwei unterschiedlichen Stellen entnommen (Limmatquai, Werdinsel, während 14 Tagen)",
"Untersuchung Kürbisgewicht (kg) bei Düngung mit Gülle oder Kompost"),
Stichprobe1=c("Hahn","Magerwiese","Limmatquai","Guelle"),
Stichprobe2=c("Henne","Klee","Werdinsel","Kompost"),
mean1=c(2500,50,250,10),
mean2=c(2000,20,200,12),
sd1=c(300,20,50,5),
sd2=c(300,10,40,5),
n=c(20,10,14,16)
)
n=sample(4,1)
## DATA
x1=abs(round(rnorm(Fragen$n[n],Fragen$mean1[n],Fragen$sd1[n])))
x2=abs(round(rnorm(Fragen$n[n],Fragen$mean2[n],Fragen$sd2[n])))
datadf=data.frame(x1,x2)
names(datadf)=c(as.character(Fragen$Stichprobe1[n]),as.character(Fragen$Stichprobe2[n]))
write.csv(datadf, "stichproben.csv", row.names = FALSE, quote = FALSE)
alpha=0.05
ps1=shapiro.test(x1)$p.value
ps2=shapiro.test(x2)$p.value
pf=var.test(x1,x2)$p.value
if (ps1 > alpha & ps2 > alpha) {
if (pf > alpha) {
p=t.test(x1,x2,var.equal = TRUE)$p.value
}else{
p=t.test(x1,x2,var.equal = FALSE)$p.value
}
}else{
p=wilcox.test(x1,x2)$p.value
}
p
msol=c(ps1>alpha & ps2>alpha, pf>alpha,TRUE)
msol
```
Question
========
`r Fragen$Fragen[n]`
Die Daten sind im File [stichproben.csv](stichproben.csv).
Answerlist
----------
* Die Stichproben sind normalverteilt
* Die Varianzen sind homogen
* Die Stichproben sind unabhängig
* Führe den am besten geeigneten Test durch und kopiere den p-Wert ins Feld:
Solution
========
```{r solutionlist, echo = FALSE, results = "asis"}
```
Meta-information
================
exname: t-Test unabhaengig
extype: cloze
exsolution: `r mchoice2string(msol)`|`r format(p)`
exclozetype: mchoice|num
extol: `r format(0.01*p)`
New answer (Edit: 2020-06-07)
Version 2.4-0 of R/exams has been improved for better support of mchoice elements in cloze questions. Running your exams2moodle("stichproben.Rmd") yields an exercise like this in Moodle:
Caveat: By default this uses Moodle's evaluation rule for multiple-choice questions where each incorrect checkbox eliminates one correct checkbox. In principle, it is possible to change the eval rule in exams2moodle() but this does not work in all settings. Apparently, if the Moodle percentages only add up approximately but not exactly to 100%, they are not read correctly. My reading is that this is a bug in Moodle. See also below.
Old answer (2020-05-17)
Multiple-choice questions where multiple answers are correct are a bit tricky within Moodle cloze exercises. My understanding is that these were not actually allowed up to a certain point (see the discussion at https://moodle.org/mod/forum/discuss.php?d=213016). Hence, we have only examples with cloze exercises containing single-choice elements but not multiple-choice-elements.
[Note: Jargon is not unified across systems. "Single choice" in R/exams is called "multiple choice, single answer" in Moodle. And "multiple choice" in R/exams is called "multiple choice, multiple answer" in Moodle. Here, I use the shorter jargon as employed by R/exams.]
Actually, I thought that Moodle still didn't support multiple-choice questions as elements in cloze exercises. This would also be consistent with the error message you got, requesting exactly one correct answer yielding 100%.
However, it turns out that under certain conditions it actually works. First, you need to choose a MULTIRESPONSE rather than MULTICHOICE type in exams2moodle() (i.e., this could be fixed on the R/exams side). Second, the percentages of the correct answers needs to sum to exactly 100%. Unfortunately, this conflicts with Moodle requiring 33.33333% as the input for 1/3 of the points. I didn't find a solution to this - other than avoiding the situation where exactly three answers are correct.
As an example I copied your code above into a file stichproben.Rmd and then ran:
set.seed(77)
exams2moodle("stichproben.Rmd", name = "stichproben", cloze = list(
cloze_mchoice_display = "MULTIRESPONSE",
eval = list(partial = TRUE, rule = "false2")
))
Note that the seed is important as it leads to only two out of three items in the multiple-choice question being correct. The eval rule is chosen such that 50% of the points are subtracted if the incorrect item is chosen. This all works as intended in Moodle.
However, running the code above using set.seed(1) before, leads to all three items in the multiple-choice question being correct. Then I still get the error message quoted in your question and - as pointed out above - I don't know if/how this can be avoided. I didn't find a solution. Hence, personally, I would rather avoid mchoice elements in cloze questions and use several schoice elements instead.
Related
how to assign a very long string to a variable in r?
Following works fine
testVar <- "test;test;"
But the following gives a weird + in the RStudio console.
testVar <- "test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;test;"
When I hit Esc button, and print testVar, it prints only test;test;
In "An Introduction to R" manual (help.start()), Section 1.8:
Command lines entered at the console are limited to about 4095 bytes (not characters).
[footnote] Some of the consoles will not allow you to enter more, and amongst those which do some will silently discard the excess and some will use it as the start of the next line.
Based on the comments, there does indeed seem to be some variation across consoles in how this is handled. From the OP, we can conclude that RStudio does not allow you to enter more bytes. Currently, RStudio does not acknowledge or intend to address this.
I also found a 2006 conversation in the R devel mailing list where Brian D. Ripley explained the issue and the documentation above. It looks like the limit has changed since then (when it was 1024 bytes).
It's worth noting that it works fine in a sourced script (even when "hard coded"). Only the REPL seems to be at fault.
Please see below my reference to a previous question asked along these lines.
I am running the library taxize in R. Taxize includes a function for getting a stable number associated with a scientific name, get_tsn().
I can run this in interactive mode or non-interactive mode so that I am either
prompted or not, respectively, to choose among multiple hits.
Interactive:
> tax.num <- get_tsn("Acer rubrum", ask=TRUE)
Retrieving data for taxon 'Acer rubrum'
tsn target commonNames nameUsage
1 28728 Acer rubrum red maple accepted
2 28730 Acer rubrum ssp. drummondii NA not accepted
3 526853 Acer rubrum var. drummondii Drummond's maple accepted
...
More than one TSN found for taxon 'Acer rubrum'!
Enter rownumber of taxon (other inputs will return 'NA'):
Non-interactive:
> tax.num <- get_tsn("Acer rubrum", ask=TRUE)
Retrieving data for taxon 'Acer rubrum'
Warning message:
> 1 result; no direct match found
I need to run this library in interactive mode so that I do not get an empty result when there is more than one match. However, babysitting this script is totally unrealistic for the size of my data, which are in the millions of scientific names. Thus, I want to automate a response to the prompt so that the answer is always 1. This will be the right answer for probably 99% of cases and will ultimately still lead to the right answer downstream in 100% of cases for reasons that are probably beyond the scope of this question.
Thus, how can I automate the response to always be 1?
I looked at this question and tried modifying my code accordingly.
options(httr_oauth_cache=T)
tax.num <- get_tsn("Acer rubrum",ask=T)
However, this gave the same result shown for interactive mode above.
Your help is appreciated.
UPDATE: Ignore below. Obviously Nathan Werth posted the best answer in a comment above.
tax.num <- get_tsn_(searchterm = "Acer rubrum", rows = 1)
works wonderfully!
...
I decided to modify the source code to handle this. I suspect that there is a more desirable solution, but this one meets my needs.
Thus, in the file get_tsn.R from the source, I replaced the following block of code
# prompt
message("\n\n")
print(tsn_df)
message("\nMore than one TSN found for taxon '", x, "'!\n
Enter rownumber of taxon (other inputs will return 'NA'):\n")
# prompt
take <- scan(n = 1, quiet = TRUE, what = 'raw')
with
take <- 1
I could have deleted other echoing to screen bits, that are unnecessary and now not true.
The revised function, which I tested using trace("get_tsn",edit=TRUE), returns as follows:
> print(tax.num)
[1] "28728"
attr(,"match")
[1] "found"
attr(,"multiple_matches")
[1] TRUE
attr(,"pattern_match")
[1] FALSE
attr(,"uri")
[1] "http://www.itis.gov/servlet/SingleRpt/SingleRpt?
search_topic=TSN&search_value=28728"
attr(,"class")
[1] "tsn"
I will recompile and install it on Linux now with the edit for use with this particular project.
I still welcome other, better answers.
the question seems very basic, i'm sorry but i could not find an answer in the documentation.
the content of both files test.sage and test.spyx is identical; it's just
a = 1/sqrt(2)
print a
if i run test.sage with
$ sage test.sage
i get
1/2*sqrt(2)
but the outcome is different from if i run the file test.spyx with
$ sage test.spyx
where i get
Compiling test.spyx...
0.707106781187
how can i prevent sage from numerically evaluating 1/\sqrt(2) in .spyx mode?
(i asked the question on ask.sagemath.org as well but got no answer yet...)
I do not like the automatic indentation of comments in
ESS (Emacs Speaks Statistics) mode, because it is so far to the right.
normalize <- function(values){
# comment
return(2* values / (max(values) - min(values)) )
}
Python uses also docstrings for comments. And I play around with it in R.
normalize <- function(values){
"comment
line 2 of comment"
return(2* values / (max(values) - min(values)) )
}
I am sure I could fix the ESS indentation of comments too, but I like the idea of multiline
comments. Are there any downsides with docstrings in GNU R?
Comments that begin with ## instead of # will be auto-indented in line with the current level of indentation.
j <- function(x) {
# One hash auto-indents to column 40
## Two hashes auto-indent to current level
### Three hashes auto-indent to BOL
rnorm(x)
}
How do I set the symbol for the angle or annuity operation in LaTeX? Specifically, this is the actuarial a angle s = (1-vs)/i.
I've looked at Life's Contingency's Package, various Actuarial Outpost forum threads, and the Comprehensive Symbol List for LaTeX, and combined the best into the following macros:
\DeclareRobustCommand{\lcroof}[1]{
\hbox{\vtop{\vbox{%
\hrule\kern 1pt\hbox{%
$\scriptstyle #1$%
\kern 1pt}}\kern1pt}%
\vrule\kern1pt}}
\DeclareRobustCommand{\angle}[1]{
_{\lcroof{#1}}}
You can then use this macro for the problem's example by typing
$a\angle{s}$
If you need a full set of actuarial symbols, you should use the Life's Contingency's Package lifecon. Using lifecon, you can set the above by typing
$a_{\lcroof{s}}$
For a very comprehensive list of LaTeX symbols, see The Comprehensive LaTeX Symbol List. Worth printing out and keeping under your pillow. Page 95 has some code that may do what you want.
I had the same problem with the actuarial symbol and the subscript/superscript, sooo I made a package to make my life easier and help other.
Plus, I’ve add some shortcut to save time.
The project page and the CTAN.
All you need is the actuarialsymbol package.
At the beginning of the code you have to write
\usepackage{actuarialsymbol}
For the sub/superscript
\actsymb['subscripLeft']['superscriptL']{<middle>}{'subscriptR'}{'superscriptR'}
Example of output:
Example of shortcut for actuarial symbol :
I've been doing some typesetting for a professor of mine and it turns out I needed some help producing the accumulated value of an annuity notation.
I asked this question on the tex stack exchange here
The result that Heiko Oberdiek produced was
\documentclass{article}
\usepackage{siunitx}
\makeatletter
\newcommand*{\NegationLike}[1]{%
\mathop{%
\mathpalette\#NegationLike{#1}%
}%
% A little space is added automatically,
% if a math ord atom follows.
}
\newdimen\BarLineWidth
\newcommand*{\#NegationLike}[2]{%
% #1: math style
% #2: argument
\vbox{%
% The rule thickness of \overline or \underline
% is available in the font dimen register 8
% of the math family 3 of the current size.
\BarLineWidth=%
\the\fontdimen8%
\ifx\displaystyle#1\textfont
\else\ifx\textstyle#1\textfont
\else\ifx\scriptstyle#1\scriptfont
\else\scriptscriptfont
\fi\fi\fi
3\relax
% The rule at the top
\hrule height\BarLineWidth
% Move the box with the vertical line
% as height as the top of the upper line
% to get a better corner.
Which produces:
accumulated value of annuity
\annu
A good list of latex symbols can be found here http://www.ctan.org/tex-archive/info/symbols/comprehensive/symbols-a4.pdf