R/exams exams2blackboard the order of the questions is randomly assigned in the exam - r-exams

I have used exams2blackboard to generate an exam and import it into Blackboard. The format of the exam is correct but the order of the questions are shown randomly each time the exam is taken (without selecting that option in Blackboard). How can I avoid that? (I want the questions to appear as they were introduced in the exams2blackboard function)
This is my code:
exam <- cbind("question1.rmd", "question2.rmd", ...)
exams2blackboard(exam,
name = "exam",
schoice = list(shuffle = FALSE, enumerate = FALSE),
eval = list(partial = -33, rule = "false", negative = -100))

Related

Error in data.frame( ... : arguments imply differing number of rows: 0, 60

Basically, I'm trying to create a portfolio data frame, where the coefficient estimates of the linear regressions are lagged. I've seen many similar issues like mine on stack overflow, but I can't understand what is meant when they say that the two vectors are of different length (I'm still a bit new to R and programming). Hopefully someone can better explain it for my situation.
I think the potential root to my problem is that before this code, Returns had 120 time-series observations and Dates had 121.
Portfolio_dataframe <- data.frame(Dates = Returns$Date[-c(1:Lookback)][1:(Periods*Holding)],
Market = Returns$Market.Close[-c(1:Lookback)][1:(Periods*Holding)],
Low_beta = unlist(Map(Holding_Period_Calculations, Holding_list, Portfolio_names,Portfolio_number = 1)),
Low_beta2 = unlist(Map(Holding_Period_Calculations, Holding_list, Portfolio_names,Portfolio_number = 2)),
Medium_beta = unlist(Map(Holding_Period_Calculations, Holding_list, Portfolio_names,Portfolio_number = 3)),
High_beta4 = unlist(Map(Holding_Period_Calculations, Holding_list, Portfolio_names,Portfolio_number = 4)),
High_beta = unlist(Map(Holding_Period_Calculations, Holding_list, Portfolio_names,Portfolio_number = 5)))
Lastly, the code runs well on my script, but the markdown fails to print this^^ section.
enter image description here
Check the length of your variables using
length(Returns$Date[-c(1:Lookback)][1:(Periods*Holding)]), length(Returns$Market.Close[-c(1:Lookback)][1:(Periods*Holding)]),
and so on.
If they have different lengths, that is why the function is returning an error. You need to keep all on the same length to be able to create your Porfolio_dataframe dataframe.
You may also want to take a look at the function lag() to obtain lagged data.

R bootnet case-dropping bootstrap stops running with no specific error message

I'm running a network analysis in R using qgraph and bootnet. When running the case-dropping bootstrap to estimate correlation-stability coefficients of centrality indices, the algorithm simply "gets stuck" with no specific error message.
I know there are issues with my data (e.g., the sample is quite small, N = 112, a subset of variables are highly correlated with each other, while a few others share little to no correlation with the rest). However, it's never happened to me that the analysis would simply stop mid-way and I'm trying to figure out what exactly is causing this.
This is the current code:
netdt23 <- select(dati,
ToM,
"MT" = Mentalization,
"PpR" = Popular_Response,
"CM" = Complete_Meaning,
"PE" = Problem_Elaboration,
"PS" = Problem_Solving,
"NE" = Negative_Emotions
)
npn23 <- huge.npn(netdt23)
net23 <- estimateNetwork(
npn23,
default = "EBICglasso",
corMethod = "cor_auto",
lambda.min.ratio = 1e-15,
threshold = TRUE
)
btfun <- function(x){
nt <- estimateNetwork(x,
default = "EBICglasso",
corMethod = "cor_auto",
lambda.min.ratio = 1e-15,
threshold = TRUE
)
return(nt$graph)
}
btntCen23 <- bootnet(
npn23, fun = btfun, type = "case",
statistics = c("edge", "strength", "betweenness"), #"closeness",
nBoots = 2000,
caseMin = .05, caseMax = .95, caseN = 19)
While running, bootnet occasionally gives warnings and/or errors, but these are never the last output before crashing (meaning that, apparently, the analysis keeps running past these issues and stops later). Such as:
Error in lav_samplestats_icov(COV = cov[[g]], ridge = ridge.eps, x.idx = x.idx[[g]], : lavaan ERROR: sample covariance matrix is not positive-definite
An empty network was selected to be the best fitting network. Possibly set 'lambda.min.ratio' higher to search more sparse networks. You can also change the 'gamma' parameter to improve sensitivity (at the cost of specificity).
Any help would be greatly appreciated. If I left out necessary information, please let me know and I'll edit the question.

MLR3 using data transforms in bootstrapping hit an error

I'm trying to use bootstrapping resampling as my cross-validation in mlr3, and have been tracking down the cause of an error:
Error in as_data_backend.data.frame(backend, primary_key = row_ids) :
Assertion on 'primary_key' failed: Contains duplicated values, position 2.
The position changes (likely the first repeated row). Based on the error message I first thought it was an issue having rownames included, so I set those as the col_type$name, and also tried removing rownames from the data before creating the task (no luck!).
In trying to create a reprex, I narrowed it down to transform pipe operators like 'scale' and 'pca' as the cause:
library("mlr3verse")
task <- tsk('sonar')
pipe = po('scale') %>>%
po(lrn('classif.rpart'))
ps <- ParamSet$new(list(
ParamDbl$new("classif.rpart.cp", lower = 0, upper = 0.05)
))
glrn <- GraphLearner$new(pipe)
glrn$predict_type <- "prob"
bootstrap <- rsmp("bootstrap", ratio = 1, repeats = 5)
instance <- TuningInstanceSingleCrit$new(
task = task,
learner = glrn,
resampling = bootstrap,
measure = msr("classif.auc"),
search_space = ps,
terminator = trm("evals", n_evals = 100)
)
tuner <- tnr("random_search")
tuner$optimize(instance)
I've also tried grid search instead of random, different learners, including the flag "duplicated_ids = TRUE" in rsmp, with no luck. Changing to CV cross validation, however, does fix the problem.
For reference, in the full pipe/graph I am trying different feature filters and learners to identify candidate pipelines.

Seeding words into an LDA topic model in R

I have a dataset of news articles that have been collected based on the criteria that they use the term "euroscepticism" or "eurosceptic". I have been running topic models using the lda package (with dfm matrices built in quanteda) in order to identify the main topics of these articles; however, the words I am interested in do not appear in any of the topics. I want to therefore seed these words into the model, and I am not sure exactly how to do that.
I see that the package topicmodels allows for an argument called seedwords, which "can be specified as a matrix or an object class of simple_triplet_matrix", but there are no other instructions. It seems that a simple_triplet_matrix only takes integers, and not strings - does anyone know I would then seed the words 'euroscepticism' and 'eurosceptic' into the model?
Here is a shortened version of the code:
library("quanteda")
library("lda")
##Load UK texts/create corpus
UKcorp <- corpus(textfile(file="~Michael/DM6/*"))
##Create document feature matrix
UKdfm2 <- dfm(UKcorp, ngrams =1, verbose = TRUE, toLower = TRUE,
removeNumbers = TRUE, removePunct = TRUE, removeSeparators = TRUE,
removeTwitter = FALSE, stem = TRUE, ignoredFeatures =
stopwords(kind="english"), keptFeatures = NULL, language = "english",
thesaurus = NULL, dictionary = NULL, valuetype = "fixed"))
##Convert to lda model
UKlda2 <- convert(UKdfm2, to = "lda")
##run model
UKmod2 <- lda.collapsed.gibbs.sampler(UKlda2$documents, K = 15, UKlda2$vocab,
num.iterations = 1500, alpha = .1,eta = .01, initial = NULL, burnin
= NULL, compute.log.likelihood = TRUE, trace = 0L, freeze.topics = FALSE)
"Seeding" words in the topicmodels package is a different procedure, as it allows you when estimating through the collapsed Gibbs sampler to attach prior weights for words. (See for instance Jagarlamudi, J., Daumé, H., III, & Udupa, R. (2012). Incorporating lexical priors into topic models (pp. 204–213). Association for Computational Linguistics.) But this is part of an estimation strategy for topics, not a way of ensuring that key words of interest remain in your fitted topics. Unless you have set a threshold for removing them based on sparsity, before calling lad::lda.collapsed.gibbs.sampler(), then *every* term in yourUKlda2$vocab` vector will be assigned probabilities across topics.
Probably what is happening here is that your words are either of such low frequency that they are hard to locate near the top of any of your topics. It's also possible that stemming has changed them, e.g.:
quanteda::char_wordstem("euroscepticism")
## [1] "eurosceptic"
I suggest you make sure that your words exist in dfm first, through:
colSums(UKdfm2)["eurosceptic"]
And then you can look at the fitted distribution of topic proportions for this word and others in the fitted topic model object.

Bisecting K-Means on a Data Set in R

I am doing my first assignment in Data Science (Masters level) and do not come from a programming background. I have completed a K-Means model on my data (which is a a simple test data set). But now I want to implement bisecting k-means in order to show how this can improve the clustering result. I am coding in R, does anyone have any knowledge on how to code bisecting k-means in R, for someone who is fairly new to the field?
The code I am trying to use is:
bkmeansset <- ml_bisecting_kmeans(x, formula = NULL, k = 3, max_iter = 20,
seed = NULL, min_divisible_cluster_size = 1, features_col = "features",
prediction_col = "prediction", uid =
random_string("bisecting_bisecting_kmeans_"))
I am inputting a test set called "testset" and I am not sure where to but this in the argument of the function. The error message that I am getting is:
Error in UseMethod("ml_bisecting_kmeans") :
no applicable method for 'ml_bisecting_kmeans' applied to an object of class
"character"

Resources