datacamp / testwhat

Write Submission Correctness Tests for R exercises
https://datacamp.github.io/testwhat
GNU Affero General Public License v3.0
33 stars 24 forks source link

SCT issue on a course - Structural Equation Modeling in R with lavaan #193

Closed klmedeiros closed 5 years ago

klmedeiros commented 5 years ago

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:

epi.model <- 'extraversion =~ V1 + V3 + V5 + V8
neuroticism =~ V2 + V4 + V7 + V9
lying =~ V6 + V12 + V18 + V24
extraversion ~~ 0*neuroticism'

and the standing SCT is:

ex() %>%
    check_expr("gsub(\"\\\\s{1,}\", \" \",  epi.model)") %>% 
    check_result() %>% 
    check_equal(incorrect_msg = "The contents of `epi.model` appear to be incorrect.",
                append = FALSE)

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!

machow commented 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

filipsch commented 5 years ago

@klmedeiros can you have a look at this and if it is helpful, update the issue accordingly?

filipsch commented 5 years ago

@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.

filipsch commented 5 years ago

@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:

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.

sumedh10 commented 5 years ago

@filipsch Currently, we ask instructors to follow the tidyverse style guide.

@klmedeiros This is the style guide we used to have in our documentation.