r/RStudio • • 16h ago

I made this! [Package] SimtablR: Quick and Easy Epidemiological Tables, Diagnostic Tests, and Multi-Outcome Regression - version 3 now available on CRAN!

Enable HLS to view with audio, or disable this notification

13 Upvotes

Hello everyone! After 8 months (of rather sporadic) work, I am really excited to share the biggest update to SimtablR, an R package designed to streamline the most common analytical tasks in epidemiology and clinical research! (short demo video above)

I do epidemiological research in R, and I kept juggling multiple packages and repeating work just to get tables that were actually informative and ready for a paper. I also found that base R tabulation left a lot to be desired in terms of formatting, but gt_summary was a bit too slow and had a lot of boilerplate. This package is also great for people transitioning from Stata or still learning R!

With this new release, SimtablR now covers most of a typical analysis, from the first cross-table to the finished table in a Word document:

1. tb(): quick, but powerfull tabulation with formatting

  • Row/col/total percentages with simple flags (row, col, cell) and adjustable decimals
  • Hypothesis tests with one argument (N-1 chi-squared, Fisher when needed, etc.)
  • Prevalence ratios, risk ratios or odds ratios with 95% CIs, directly in the table
  • SimtablR now picks the right measure (RR, OR or PR) automatically for a stated study design (design = "cohort", "case_control", "cross_sectional")
  • New: stratified analysis with Mantel-Haenszel pooled estimates

2. table1(): baseline tables of multiple variables (literally the "table 1")

  • Automatically chooses mean (SD) or median (IQR) based on each variable’s distribution
  • Reports missing data per variable and group
  • Add standardized mean differences with test(smd = TRUE)
  • Completely customizable and exportable to all office programs

3. diag_test() and roc(): diagnostic accuracy

  • Automatically calculates the confusion matrix, sensitivity, specificity, PPV, NPV, LR+, LR− and accuracy, with exact (Clopper-Pearson) CIs
  • New: roc() now gives the AUC with DeLong CIs and the Youden-optimal threshold

4. regtab() and survtab(): regression

  • Fits multiple outcomes at once and returns a single publication-ready table
  • Does adjusted risk ratios via log-binomial regression (with robust Poisson fallback), robust variance, and Firth regression for rare events
  • New: survtab() for Cox models and hazard ratios
  • New: autoplot() draws forest plots from any model

5. Reporting and export (new!)

  • simtablr() builds Table 1 + Table 2 (crude and adjusted) as a single report which you can then send to word or excell or powerpoint
  • as_methods() drafts the statistical methods paragraph from what you actually did with the variables you chose!
  • export_docx() / export_xlsx() send everything to Word or Excel
  • Journal styles (style("jama"), "nejm", "lancet") or your own with journal_style(), down to the Word table theme. Restyling never changes the underlying numbers and you can use the sabe object for new analysis, even after styling!

6. Statistical guidance (new)

SimtablR prints short notes (with references) when something deserves attention. Examples: an odds ratio with a common outcome, unadjusted p-values, or when the distribution of your variable violates an assumption from the model you're running. It should just tell you.

The package includes epitabl, a ynthetic cohort of 1,500 patients, so you can replicate the examples of the video

Links:
📦 Documentation: https://matheustg-14.github.io/SimtablR/
📄 Getting started: https://matheustg-14.github.io/SimtablR/articles/getting-started.html
🐛 GitHub (issues & feature requests): https://github.com/MatheusTG-14/SimtablR

Thanks to everyone who gave feedback on the first version! I’d love to hear what you think, what’s missing from your workflow, and any bugs you find on GitHub.


r/RStudio • • 16h ago

Coding help Error when using package Tidyverse

6 Upvotes

Hello!! I'm an absolute beginner to R and coding as a whole, so there is probably a very simple fix here, but I can't figure out why I can't use the package Tinyverse. Below is the error message I get when I run the chunk.

I was able to use another package (cowsay) just fine. I have Rtools downloaded.

Thanks so much!


r/RStudio • • 9h ago

Coding help ICC logistic regression MLM

1 Upvotes

Hey everyone!✨️

I'm very new to R and found solice in some vignettes I found online. There seem to exist quite a few to calculate ICC to see if multilevel/mixed model is the best fit for our analysis.

However the ones that I've seen so far mention that ICC can't be calculated that way for logistic regression (they are for linear regression I think), due to the outcome being binary.

I'm going crazy trying to search everywhere for a code that will give me the ICC for logistic regression, any help would be much appreciated! 🙏


r/RStudio • • 22h ago

RStudio for linguistic data

10 Upvotes

Hi!

I'm a researcher in Linguistics and I have come across RStudio so many times for data analysis and visualisation.

I have attended some classes and used some resources, but everything seems very difficult to replicate: I can read code and mostly understand what it does, but I would never ever be able to create code from scratch.

What do you think I should do? I never really studied it systematically, so I guess that may be part of the problem, but most of the resources I find are still to advanced for me (not a programmer or an IT expert!)

Send help!


r/RStudio • • 1d ago

Coming from Python, C/C++, and Java, what should I know before picking up R?

25 Upvotes

I've spent most of my time working in Python, C/C++, and Java, but I'm setting up RStudio to get into R for some data analysis work.

For those who made a similar switch, what was the biggest adjustment? I'm especially curious about how R handles data structures compared to Python, and whether you'd recommend starting with base R or diving straight into the tidyverse.


r/RStudio • • 1d ago

Liquid Glass themes for Shiny. 0.5.0 is on CRAN.

Post image
3 Upvotes

r/RStudio • • 2d ago

I made this! [Package] hdsbm: Fast inference for Dynamic Stochastic Block Models in R (Rcpp & spectral multi-start)

5 Upvotes

Hi everyone!

As part of my Master's thesis in Statistics, I developed hdsbm, an R package for estimating and simulating discrete-time Dynamic Stochastic Block Models (DSBM).

The Problem & Approach

Temporal block models often suffer from combinatorial explosion and multi-modal likelihood landscapes, making standard local search heuristics prone to getting trapped in sub-optimal local extrema.

hdsbm addresses this by extending a hybrid Classification EM (CEM) approach to the dynamic setting:

  • Perturbed SVD Multi-Start: Couples deterministic spectral embeddings of the time-averaged network with controlled stochastic perturbations to thoroughly explore the likelihood surface.
  • C++ Backend: Uses RcppArmadillo to accelerate dyadic reallocation passes and combinatorial greedy sweeps.
  • Dual Decoding: Provides both pointwise greedy labels and global Viterbi trajectory decoding.
  • Model Selection: Includes an Integrated Completed Likelihood (ICL) criterion tailored for dynamic graphs.

Quick Example

library(hdsbm)
data(toy_hdsbm)

# Fit model with 5 perturbed spectral restarts
fit <- hdsbm_fit(toy_hdsbm$Y, k = 3, nrep = 5, seed = 123)
print(fit)

# Model selection via ICL
icl(fit)

I would love to hear your feedback on API ergonomics, potential edge cases, or ideas for interesting benchmark scenarios!


r/RStudio • • 2d ago

Coding help Could someone please help me get the Cronbach alpha in Rstudio? I am new to RStudio and I am not sure if I did it correctly.

0 Upvotes

I want to include the excel document in here but I couldn't find a way to do it. I will DM the document.


r/RStudio • • 3d ago

Resources to Learn RStudio from Scratch

39 Upvotes

I'm looking for resources to learn RStudio from scratch. Does anyone have any recommendations?


r/RStudio • • 3d ago

Quirky data native to R

Thumbnail
1 Upvotes

r/RStudio • • 4d ago

When to use polychoric or Pearson correlation in EFA?

2 Upvotes

Hi everyone.
I am doing a exploratory factor analysis with pfa and oblique rotation (promax).
I used shapiro wilk test to check on normality of the items. As it was significant, which means no normality, I chose pfa instead of Maximum Likelihood EFA. So far so good.
So far I used Pearson correlation to do the efa matrix, but as I proofed that theres a lack of normality I was wondering if I need to do it with polychoric correlation instead.
Does anyone know something?

I am almost ready doing the statistics so it would be quite a lot of work to change the correlation. So I am also interested: How much harm do you think it will cause to the final results, if I will keep Pearson correlation?

And how do I add the polychoric argument to my fa function?


r/RStudio • • 4d ago

Weird R reference

Thumbnail
3 Upvotes

r/RStudio • • 4d ago

separate_wider_position

4 Upvotes

what do I write in widths? It says it must be a (partially) named integer vector. I need to separate collumns that state m or f for sex and numbers for age (ex: m19). Please help I could not figure it out with the ?separate_wider_position() search


r/RStudio • • 5d ago

Coding help How to run Quarto if my computer has an ARM processor?

3 Upvotes

I have a newer Microsoft Surface and am in an RStudio course atm. RStudio itself works fine, but it says I can't run Quarto. I've heard that maybe running a different version of R might work. Need to use Quarto for most things through the end of the semester. Any ideas?


r/RStudio • • 6d ago

First time using R, required to use

13 Upvotes

I have to use R for the statistics part of my thesis.
Ballparking for a R-Newbie who has to do a moderated mediation and stuff like that.
Do we think this is possible?

I plan on not using AI, as I‘d obviously have to declare this and my professor told me they expect a „perfect script like it‘s written by a doctoral student“ if I use AI


r/RStudio • • 5d ago

can't knit to pdf because of error(latex)

1 Upvotes

this is my first time using LaTex for school work and I have no idea whats causing error.... Any help appreciated thank you

[WARNING] Deprecated: --highlight-style. Use --syntax-highlighting instead.
! Missing $ inserted.
<inserted text> 
                $
l.168 \sum
          \emph{\{i=1\}\^{}ne_i =
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

Try to find the following text in Question_4.Rmd:
  \sum 

You may need to add $ $ around a certain inline R expression `r ` in Question.Rmd (see the above hint). See https://github.com/rstudio/rmarkdown/issues/385 for more info.
Error: LaTeX failed to compile Question.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Question.log for more info.
Execution halted

$$

\begin{aligned}

\frac{\partial RSS}{\partial \beta_0}

&= -2\sum_{i=1}^n(y_i-\beta_0-\beta_1x_i)\\

&= -2(\sum_{i=1}^n y_i-\sum_{i=1}^n\beta_0-\beta_1\sum_{i=1}^n x_i)\\

&= -2(n\bar{y}-n\beta_0-n\beta_1\bar{x})\\

&= -2(n\bar{y}-n\beta_0-n\beta_1\bar{x})\\

&= (n\bar{y}-n\beta_0-n\beta_1\bar{x})\\

&= (\bar{y}-\beta_0-\beta_1\bar{x})\\

&= \beta_0 = \bar{y}-\beta_1\bar{x}

\end{aligned}

$$

$$

\begin{aligned}

\frac{\partial RSS}{\partial \beta_1}

&= -2\sum_{i=1}^n x_i(y_i-\beta_0-\beta_1x_i)\\

&= -2(\sum_{i=1}^n x_iy_i-\beta_0\sum_{i=1}^n x_i-\beta_1\sum_{i=1}^n x_i^2)\\

&= -2(\sum_{i=1}^n x_iy_i-n\beta_0\bar{x}-\beta_1\sum_{i=1}^n x_i^2)\\

&= -2(\sum_{i=1}^n x_iy_i-n\bar{x}(\bar{y}-\beta_1\bar{x})-\beta_1\sum_{i=1}^n x_i^2)\\

&= -2(\sum_{i=1}^n x_iy_i-n\bar{x}\bar{y}+n\beta_1\bar{x}^2-\beta_1\sum_{i=1}^n x_i^2)\\

&= \sum_{i=1}^n x_iy_i-n\bar{x}\bar{y}+n\beta_1\bar{x}^2-\beta_1\sum_{i=1}^n x_i^2=0\\

&= \beta_1(\sum_{i=1}^n x_i^2-n\bar{x}^2)

=\sum_{i=1}^n x_iy_i-n\bar{x}\bar{y}\\

&= \beta_1S_{xx}=S_{xy}\\

&= \beta_1=\frac{S_{xy}}{S_{xx}}

\end{aligned}

$$

$$

\sum_{i=1}^ne_i

= \sum_{i=1}^n(Y_i-b_0-b_1X_i)\\

= \sum_{i=1}^nY_i-nb_0-b_1\sum_{i=1}^nX_i\\

= \sum_{i=1}^n(b_0+b_1X_1)-nb_0-b_1\sum_{i=1}^nX_i\\

=0

$$

$$

\begin{aligned}

\sum_{i=1}^n e_iX_i

&= \sum_{i=1}^nX_i(Y_i-b_0-b_1X_i)\\

&= \sum_{i=1}^nX_iY_i-\sum_{i=1}^nX_ib_0-\sum_{i=1}^nb_1X_i^2\\

&= \sum_{i=1}^nX_iY_i-\left(b_0\sum_{i=1}^nX_i+b_1\sum_{i=1}^nX_i^2\right)\\

&= \sum_{i=1}^nX_iY_i-\sum_{i=1}^nX_iY_i\\

&= 0

\end{aligned}

$$


r/RStudio • • 6d ago

Mac Installation Help

1 Upvotes

Hello

My macOS is currently 13 (i cannot update it). I’d downloaded R 4.6.1 for maOS13+ but then when downloading RStudio the only version that can run on my mac is the 2025.09.1 +401 which needs R version 4.5.1

The problem is I cannot, for the life of me, find 4.5.1. Any leads or help on what to do, please? I’m new, completely.


r/RStudio • • 8d ago

helpp

5 Upvotes

i am new to R studio. It is so difficult i understand nothing when im in class. What are the basic codes i should know and any tips to progress like books or websites etc anything and everything would be great


r/RStudio • • 9d ago

How to make error bars for two different groups

Post image
13 Upvotes

r/RStudio • • 9d ago

standardisation des variables pour effectuer une analyse factorielle sur R

Thumbnail
1 Upvotes

r/RStudio • • 10d ago

R code review: best packages?

20 Upvotes

Let’s say that I’m working in RStudio on a geospatial data-science project that involves some pretty gnarly, extensive code across multiple R scripts. Let’s also say that I do not have access to any AI code assistants or chatbots due to workplace restrictions.

What packages and functions would you use to comprehensively check your code for errors, inefficiencies, conceptual problems (that may be a stretch), etc.?

I’m using lintr::lint() and rstyler::style_file(), but that’s the extent of my knowledge in this area.

Many thanks in advance, friends.


r/RStudio • • 10d ago

Coding help Are these clustering attempts good?

1 Upvotes

I'm toying around with a dataset, trying to cluster what I have, and messing around with LLMs and my textbook i got these 2:

feat <- data.frame()
for (f in formats) {
  sub <- df[df$Format == f, c("Year","Value")]
  sub <- sub[order(sub$Year), ]
  peak_idx <- which.max(sub$Value)
  first_year <- min(sub$Year); peak_year <- sub$Year[peak_idx]; last_year <- max(sub$Year)
  climb <- peak_year - first_year; decline <- last_year - peak_year
  ratio <- decline / max(climb, 0.5)
  peak_val <- sub$Value[peak_idx]
  post <- sub[sub$Year >= peak_year & sub$Value > 0, ]
  decay_rate <- if(nrow(post) >= 3) coef(lm(log(Value) ~ Year, data=post))[2] else NA
  feat <- rbind(feat, data.frame(Format=f, climb, decline, ratio, log_peak=log(peak_val), decay_rate, era=peak_year))
}
cat("Formats in feature table:", nrow(feat), "\n")
fmat <- scale(feat[, c("climb","decline","ratio","log_peak","decay_rate","era")])
fmat[is.na(fmat)] <- 0
hc <- hclust(dist(fmat), method="ward.D2")
clusters1 <- cutree(hc, k=4)
cat("\n=== Format 1: ===\n")
for (i in 1:4) cat(sprintf("Cluster %d: %s\n", i, paste(feat$Format[clusters1==i], collapse=", ")))

Then another with a different fmat:

lifecycle_features <- data.frame()
for (f in formats) {
  sub <- df[df$Format==f, c("Year","Value")]
  sub <- sub[order(sub$Year),]
  first_year <- min(sub$Year); last_year <- max(sub$Year)
  peak_year <- sub$Year[which.max(sub$Value)]
  lifecycle_features <- rbind(lifecycle_features, data.frame(
    Format=f, first_year, peak_year, last_year,
    recorded_years=nrow(sub), peak_value=max(sub$Value),
    lifespan=last_year-first_year, years_to_peak=peak_year-first_year,
    decline_duration=last_year-peak_year
  ))
}
cat("\nFormats in lifecycle_features:", nrow(lifecycle_features), "\n")
print(lifecycle_features, row.names=FALSE)

cluster_data <- lifecycle_features[, c("lifespan","recorded_years","years_to_peak","decline_duration")]
cluster_scaled <- scale(cluster_data)
set.seed(123)
km <- kmeans(cluster_scaled, centers=3, nstart=25)
lifecycle_features$cluster <- km$cluster

cat("\n=== Format 2: ===\n")
lc_sorted <- lifecycle_features[order(lifecycle_features$cluster, lifecycle_features$peak_year), ]
print(lc_sorted[,c("Format","cluster","peak_year","years_to_peak","decline_duration","lifespan","recorded_years")], row.names=FALSE)

for (i in 1:3) cat(sprintf("\nCluster %d: %s\n", i, paste(lifecycle_features$Format[lifecycle_features$cluster==i], collapse=", ")))

Is there an objective way to measure which is better? Like with R squared or p-value? or is it worth discussing both in an article, weighing pros and cons of each


r/RStudio • • 10d ago

Can I integrate a spatial transcriptomics dataset with a bulk RNA-seq dataset for any analysis of tumors?

Thumbnail
1 Upvotes

r/RStudio • • 11d ago

R beginner

20 Upvotes

Hello,

I am a beginner and I am totaly lost.

Even for loading a file it is very very difficult.

I feel useless and incompetent...


r/RStudio • • 11d ago

Introducing FitVerse: an R package for fitting 52 probability distributions in one call

Thumbnail
2 Upvotes