Closed klmedeiros closed 5 years ago
lavaan has a function called lavaanify
that returns a data.frame from a model string. It seems like this removes the need to use regexes.
see these lavaan SCTs I tried on a branch to testwhat.ext: https://github.com/datacamp/testwhat.ext/blob/lav-scts/R/examples.R#L33
I think the same thing applies for RJAGS
@klmedeiros can you have a look at this and if it is helpful, update the issue accordingly?
@klmedeiros I merged the PR linked above and bumped the version of testwhat.ext
. I’m now building a new shared R image that contains this new testwhat.ext
When it’s live, I’ll respond here with a sample SCT for the specific example that you listed.
@klmedeiros the update to testwhat.ext
has been deployed and you can use the lavaan-specific function in any SCT for an R exercise now. Coming back to your example, a meaningful SCT could be:
ex() %>%
check_object('epi.model') %>% # zooms in on epi.model
check_lavaan_pattern("extraversion\\s*~~\\s*0\\s*\\*\\s*neuroticism", incorrect_msg ="You're wrong!") # arbitrary regexing
ex() %>%
check_object('epi.model') %>%
check_lavaan_df() %>% # turns the model into its data frame representation
check_lavaan_uses(lhs='extraversion', op = '~~', rhs = 'neuroticism', free = 0, incorrect_msg = "You're wrong!") # Check that there is a row in the df representation with the specified fields.
Some notes:
check_lavaan_pattern()
and check_lavaan_uses()
, the incorrect_msg
has to be specified. I didn't bother automatically generating feedback messages.append
argument: it allows you to control how your feedback messages will looklavaan::lavaanify(epi.model)
. From that, you can figure out which arguments you want to set in chekc_lavaan_uses()
.You can browse the docs here.
BTW: using .
in variable names is not according to DataCamp's R style guidelines. cc @sumedh10 do we have this styleguide available somewhere again? It's vital.
I consider this issue closed from a testwhat perspective now.
@filipsch Currently, we ask instructors to follow the tidyverse style guide.
@klmedeiros This is the style guide we used to have in our documentation.
The instructor filed an SCT-related issue that, at the very least, affects exercise 2.7, but she had said applies to other exercises in the course.
Exercise 2.7.1 requires creation of the following object:
and the standing SCT is:
Nick Solomon attempted to solve the instructor-reported issue using the
gsub()
function, which they'd thought would be a fix. Not so here, as described in the GH issue by the instructor, the spacing around, in particular :0*neuroticism'
vs.0 * neuroticism'
doesn't affect the model, but this SCT isn't passing with the spaces right now.He tried a similar fix on a few SCTs in the RJAGS course, using
check_expr(gsub())
and I guess they're also not working. As you know from the quizzes, text-based SCTs are my week point, plus with two courses having an issue like this, it seems to me like it might be a problem moving forward, so I'd love to see the lavaan example fixed, and then hopefully I can implement solutions across the rest of that course and the RJAGS one as well. Thanks!