cdriveraus / ctsem

Hierarchical continuous time state space modelling
41 stars 15 forks source link

[Documentation] Equations Go Past Page Margins #59

Closed emstruong closed 5 months ago

emstruong commented 7 months ago

Hello,

It seems like page 7 of your Hierarchical Manual https://cran.r-project.org/web/packages/ctsem/vignettes/hierarchicalmanual.pdf has its equations going past the margins.

Cheers, Michael

cdriveraus commented 7 months ago

Thanks. I'll reduce the text size again :)

emstruong commented 7 months ago

Is there any chance that the ctModelLatex() function could give something that I could copy-paste into a R-Markdown document as opposed to a separate pdf? Perhaps, the way equatiomatic does things? https://datalorax.github.io/equatiomatic/

I really appreciate the Latex functionality, makes interpreting the model a lot more approachable.

cdriveraus commented 7 months ago

it's a bit tricky yeah, you can output the tex directly by setting compile=F. But here is how I solved it for some blogdown posts: https://cdriver.netlify.app/post/dtbivariate/

```{r TEX,echo=FALSE,out.width='100%',out.height='100%', fig.align='left'}
ctModelLatex(model,textsize = 'small', folder=savedir,
  filename = 'dtbivariate',open=FALSE)

bitmap <- pdftools::pdf_render_page(paste0(savedir,'/dtbivariate.pdf'),dpi=72)
png::writePNG(bitmap, paste0(savedir,'/dtbivariate.png'))
knitr::include_graphics(paste0('dtbivariate.png'))
cdriveraus commented 7 months ago

I couldn't figure out in 2 minutes what equatiomatic was really doing or how it would help, I gladly accept summaries (or pull requests hah) ;)

emstruong commented 6 months ago

it's a bit tricky yeah, you can output the tex directly by setting compile=F. But here is how I solved it for some blogdown posts: https://cdriver.netlify.app/post/dtbivariate/

```{r TEX,echo=FALSE,out.width='100%',out.height='100%', fig.align='left'}
ctModelLatex(model,textsize = 'small', folder=savedir,
  filename = 'dtbivariate',open=FALSE)

bitmap <- pdftools::pdf_render_page(paste0(savedir,'/dtbivariate.pdf'),dpi=72)
png::writePNG(bitmap, paste0(savedir,'/dtbivariate.png'))
knitr::include_graphics(paste0('dtbivariate.png'))

That solution works. (BTW, I couldn't help but mention that it's somewhat blurry on my browser... perhaps svg would be crisper?)

emstruong commented 6 months ago

I couldn't figure out in 2 minutes what equatiomatic was really doing or how it would help, I gladly accept summaries (or pull requests hah) ;)

So my understanding is that equatiomatic automatically transforms regression models into the sort of equation forms that you might find in a statistics textbook. So it's quite similar to what happens with ctModelLatex().

Although, as far as I can tell, it's different in that the latex it outputs can be directly copy-pasted into a R-markdown file like so:

$$
\begin{aligned}
  \operatorname{hamd}_{i}  &\sim N \left(\alpha_{j[i]} + \beta_{1j[i]}(\operatorname{time}), \sigma^2 \right) \\    
\left(
  \begin{array}{c} 
    \begin{aligned}
      &\alpha_{j} \\
      &\beta_{1j}
    \end{aligned}
  \end{array}
\right)
  &\sim N \left(
\left(
  \begin{array}{c} 
    \begin{aligned}
      &\mu_{\alpha_{j}} \\
      &\mu_{\beta_{1j}}
    \end{aligned}
  \end{array}
\right)
, 
\left(
  \begin{array}{cc}
     \sigma^2_{\alpha_{j}} & \rho_{\alpha_{j}\beta_{1j}} \\ 
     \rho_{\beta_{1j}\alpha_{j}} & \sigma^2_{\beta_{1j}}
  \end{array}
\right)
 \right)
    \text{, for id j = 1,} \dots \text{,J}
\end{aligned}
$$

Whereas, my memory of ctModelLatex was that it's different because ctModelLatex gives you enough latex to generate an entire pdf based on the output itself... Which is a lot to parse through for people who aren't as fluent in latex.

cdriveraus commented 6 months ago

to output just the equation and not the entire document, use the equationonly=TRUE argument.

emstruong commented 6 months ago

to output just the equation and not the entire document, use the equationonly=TRUE argument.

D'oh!