cjvanlissa / tidySEM

55 stars 7 forks source link

Basic blavaan support #43

Closed nx10 closed 2 years ago

nx10 commented 2 years ago

Hi thanks for this package. I think tidySEM plots look better and are a easier to configure than the plots of other packages with similar goals.

I needed to plot a graph for some blavaan models so I added (very) basic support as you suggested in #37 .

There is a lot of things missing, and some concepts from frequentist SEM do not translate well (p values, confidence intervals, ...) so this is more of a starting point from which somebody more qualified may take over.

Some notes:

Prior to latex code ```R df <- as.data.frame(blavInspect(fit, "list")) groups <- stringr::str_match(df$Prior, r"{(\w+)\((\.?-?\d+e?-?\d*|iden),(\.?-?\d+e?-?\d*)\)}") groups[,3] <- ifelse(is.na(groups[,3]), "", groups[,3]) groups[,3] <- ifelse(groups[,3] == "iden", "\\mathbbm{1}", groups[,3]) groups[,4] <- ifelse(is.na(groups[,4]), "", groups[,4]) groups[,4] <- stringr::str_replace(groups[,4], "^\\.", "0.") groups[,4] <- stringr::str_replace(groups[,4], "^1e(.*)", "10^{\\1}") groups[,4] <- stringr::str_replace(groups[,4], "e(.*)", "\\\\cdot 10^{\\1}") groups[,2] <- dplyr::recode( groups[,2], dnorm = "\\mathcal{N}", dgamma = "\\Gamma", dwish = "\\mathcal{W}") df$Prior <- apply(groups, 1, function(x) ifelse(is.na(x[[2]]),"",sprintf("$%s(%s,%s)$",x[[2]],x[[3]],x[[4]]))) ```
cjvanlissa commented 2 years ago

This looks great, thank you very much! I have a deadline on 20-1, after which I'm going to incorporate these changes.