r/rstats • • 3h ago

qshap: Fast and exact Shapley decomposition of R² for tree ensembles

Post image
26 Upvotes

Hi r/rstats!

I'd like to share an R package I've been developing, qshap. Unlike conventional SHAP values that explain individual predictions, qshap decomposes GBDT model's R² into feature-specific contributions.

It supports XGBoost, LightGBM, and CatBoost, with both global and local explanations.

The CatBoost implementation is particularly fast: exact R² decomposition for 100,000 observations, 100 features, and 100 trees (depth 6) takes only 0.14 seconds on a single CPU core of an M1 MacBook Pro in our benchmarks.

Both R and Python packages are available on CRAN and PyPI, respectively.

Any feedback would be greatly appreciated!


r/rstats • • 15h ago

ggllm: Training a small Language Model on R's tidyverse documentation (ggplot2 + dplyr) which can then do exploratory data analysis and draw functional and good looking ggplot2 charts

Post image
47 Upvotes

Random weekend experiment: can a frontier model train a small Language Model on R's tidyverse documentation (ggplot2 + dplyr) which can then do exploratory data analysis and draw functional and good looking ggplot2 charts?

The answer is yes!

GGLLM is a small model (27.6 MB!) trained on high-quality R code, including the ggplot2 documentation.

You pick a dataset, give it a short data dictionary, and it plots charts from your natural language questions. It's not great at handling typos yet, but what I find interesting is that it does a semi-decent job without connecting to a server.

What this tells me is, you can use frontier models to train small Language Models for certain specific open ended tasks instead of using an large model.

Check it out in action here: https://rahulch.site/ggllm/ (the model is already preloaded)


r/rstats • • 1d ago

mcptools users: how could the package better serve you?

9 Upvotes

I'm the maintainer of the https://github.com/posit-dev/mcptools package and will be putting some attention towards it these next few days.

The big ticket item for the next release, from my perspective, is a sibling to `mcp_tools()` that is more general / less opinionated, fetching everything that the server has to offer (prompts, resources, etc). Is there anything else particularly that you'd like to see make it into the next release?


r/rstats • • 20h ago

Rao: Cursor for RStudio

0 Upvotes

r/rstats • • 1d ago

{shinyelectron} your Shiny app as a desktop app people double-click (v0.3 now on CRAN)

77 Upvotes

Your Shiny app works great on your own laptop! Getting it onto anyone else's usually means a server or a very long email about installing R or Python and, then, the associated package.

{shinyelectron} sidesteps this by turning a Shiny app, R or Python, into a desktop app for Windows, macOS and Linux that people open with a double-click. Bundle R or Python inside and they never have to install either.

install.packages("shinyelectron")
shinyelectron::export("path/to/app", destdir = "build")

Version 0.3.0 is mostly about fewer surprises and a few improvements to local package detection/inclusion. In order for the installer to work on other folks computers without a security warning, you will need a developer certificate on Windows and/or macOS to sign the application.

You can learn more at:

  • CRAN: https://cran.r-project.org/web/packages/shinyelectron/
  • YouTube Video (~2 min): https://youtu.be/YifE_USlYYE
  • Release notes (blog): https://blog.thecoatlessprofessor.com/software-releases/r/shinyelectron/shinyelectron-v0.3.0-released-package-source-checks-and-local-update-testing/
  • Docs: https://r-pkg.thecoatlessprofessor.com/shinyelectron/
  • Code (GitHub): https://github.com/coatless-rpkg/shinyelectron

Happy to answer any questions below about {shinyelectron}!

P.S. You'll likely see in a week or two another post regarding a similar project that side-steps the need for a developer certificate. :)


r/rstats • • 1d ago

Eu criei um projeto hobby usando R e Shiny.

0 Upvotes

Eu criei um pequeno projeto hobby no meu tempo livre usando R e Shiny.

Eu sei, R é ruim e supostamente só é bom para computação estatística. Mas decidi usá-lo mesmo assim.

Não me faça perguntas. Apenas use, faça um fork, quebre, critique — o que você quiser. Provavelmente não vou responder aos comentários.

Aproveite!

Glorium: https://glorium.shinyapps.io/glorium/

Código fonte: https://gitea.com/Oddler/Glorium.git

E fica quieto se o markdown ficou terrível; não quero ouvir sua opinião.

\---

Estou no processo de traduzir os comentários do código para o inglês — desculpe por isso.


r/rstats • • 2d ago

Speed Demon II: an online optimisation race where R is one of 26 languages (29 Jan to 1 Feb 2027)

0 Upvotes

Speed Demon II is an online optimisation hackathon for interpreted languages, and R is one of the 26. Each language runs on one pinned interpreter. No FFI, native modules or subprocesses, so no Rcpp: the speed has to come from the R code itself.

Four tracks: per endpoint and hour, report p50, p95 and p99 latency from 310,000 log lines; index 25,000 documents; join 332,000 records from a hostile CSV; and run shortest paths on a 500,000-edge graph. Each entry is timed against a naive R reference on one machine. Every push sets your team's car speed on a live 3D race round San Francisco.

R is one of the 10 slowest languages in the Underdog prize: $100 for the fastest car that runs all four tracks in those languages.

Teams of 1 to 4. A practice day, then a 48-hour race. $2,000 in prizes.

Details: https://speeddemon.dev/2027/

Register: https://speeddemon.dev/2027/register/


r/rstats • • 5d ago

cuplyr 0.2.0: all (except a few weird) dplyr verbs now can be run on the GPU

45 Upvotes

A while back I posted cuplyr here, a dplyr backend that runs on NVIDIA GPUs. Version 0.2.0 is now out.

All (except a few weird) dplyr verbs now run on the GPU, with the same results as dplyr. One query on 10 million rows has a speedup of 150 times:

> system.time(
+ sales |>
+ mutate(revenue = amount * price) |>
+ arrange(desc(revenue)) |>
+ head(100)
+ )

user system elapsed
0.583 0.052 0.637

> sales_gpu <- tbl_gpu(sales)
> system.time(
+ sales_gpu |>
+ mutate(revenue = amount * price) |>
+ arrange(desc(revenue)) |>
+ head(100) |>
+ collect()
+ )

user system elapsed
0.004 0.000 0.004

The weird verbs are group_map(), group_modify(), group_nest(), nest_by(), nest_join() and do(). They need list columns or arbitrary R functions. Those will then fallback to the CPU.

A new function read_parquet_gpu() reads parquet files straight onto the GPU. The GPU decodes the file, so it uses less RAM than reading it into R first. The reader is lazy too. Put a filter() after it and the filter is pushed down to the Parquet reader, which skips the data it doesn't need.

There's also a conda package now, so no compiler or CUDA toolkit.

No GPU? No worries! This Colab notebook runs it on a free Nvidia T4 GPU.

Found a verb that falls back or a result that differs from dplyr? Open an issue and I'll take a look.

TLDR: cuplyr is at its best on millions of rows, read from Parquet or uploaded once and queried many times. Sorting, string work and group-bys with many groups gain the most.

Docs
GitHub


r/rstats • • 6d ago

Textmate lives

1 Upvotes

A great editor is key for R, and the OG TextMate had and retains has a surprisingly strong following among R users who love bundles and hate heavy IDEs.

Textmate lives is a reboot.

It has cleared the technical debt, and adding modern features such as built in disjoint selection (cntrl-W), cursor history (cntrl -/+ to smartly move back and forth between jumps/edits) both coming in the next release. Speaking of which it's been getting frequent updates and auto-download is reconnected: You can sub to the beta channel again.

The R bundle has support for modern headings (navigable by symbols menu) and open to more improvements. Check it out. Feedback welcome.

https://github.com/textmatelives/textmate (at releases)

It


r/rstats • • 7d ago

Trouble running R on positron

6 Upvotes

Been trying to run R on positron. I'm on Windows and have downloaded both but for some reason I'm getting the error message "Cannot execute code because there is no registered runtime for the 'r' language". Not sure what I'm missing. Just spent a couple hours trying to figure it out and can't find any clear answers anywhere so if anyone has any ideas I would be super grateful


r/rstats • • 6d ago

How to use R (R studio) for data wrangling??

Thumbnail reddit.com
0 Upvotes

r/rstats • • 7d ago

Rayshader 1.0: Exit the Matrix

Thumbnail tylermw.com
81 Upvotes

r/rstats • • 7d ago

Plotting curves after coxph frailty model and strata()

3 Upvotes

Hello I am asking if anyone is aware of how to draw adjusted cum hazard and survival curves after running a frailty model using coxph. I am using the Surv(start, stop ,event status) framework with gap times. Importantly, I have had to stratify a binary variable as it violated the proportional hazards assumption - using strata(var). The goal is to do curves for the overall sample (showing the two strata), and then separately for each individual variables. I have an interaction and it would be good to plot the hazards of 1 variable versus the actual values of the other variables. Any guidance, particularly code implementation, of this would be very helpful.

I am a clinician and not a statistician, but also not trying to use AI at all as Im against it and dont want to have to use it and then declare it.

I am aware of other setups for example cluster() option for robust standard errors as well as frailtypack, coxme, etc. The curves could be drawn in easily with the cluster() option. However, the research question very much needs a frailty model. Also Ive written out the whole thing based on the frailty findings and Kaplan Meier curves...the findings dont necessarily remain with other modelling options which is a problem.


r/rstats • • 7d ago

How do you decide whether a residual correlation structure (e.g. AR(1)) is necessary in a longitudinal linear mixed-effects model when AIC/BIC and residual diagnostics disagree?

Thumbnail
reddit.com
2 Upvotes

r/rstats • • 8d ago

Cox PH assumption Schoenfeld residuals

2 Upvotes

I was reading this site: https://www.datanovia.com/learn/biostatistics/survival-analysis/testing-ph-assumptions about the cox PH assuption, and i ran the code below

library(survival)
library(survminer)

res.cox <- coxph(Surv(time, status) ~ age + sex + ph.ecog, data = lung)
test.ph <- cox.zph(res.cox)

ggcoxzph(test.ph)

On the website they say "survminer’s ggcoxzph() draws, for each covariate, the scaled Schoenfeld residuals against transformed time, with a smoothing spline and a ±2-standard-error band.

Below they also say: "

  • In all three panels the spline is essentially flat and stays inside the band, so there is no pattern with time: the assumption is supported for age, sex (the two-level factor accounts for the two residual bands), and ph.ecog. This matches the non-significant cox.zph() p-values exactly." So everythings seems fine.

I now do this classic comand myself below.

library(survival)
res.cox <- coxph(Surv(time, status) ~ age + sex + ph.ecog, data = lung)
test.ph <- cox.zph(res.cox)

plot(test.ph[1])

abline(h = res.cox$coefficients[1])

And I get the image below where the line seems not to inside the band, is this because I've not plotted the scaled Schoenfeld residuals against transformed time? And what does even transformed time mean in this setting? If I used this plot I would be debating myself quite a bit if the PH assumption hold.


r/rstats • • 8d ago

Hello from the Washington DC R Conferencehttps://i.imgur.com/sZWfmgK.jpeg

0 Upvotes

r/rstats • • 9d ago

White Noise in SARIMA residuals

Thumbnail reddit.com
6 Upvotes

r/rstats • • 8d ago

Cove: an open-source IDE where R, Shiny and Python (via reticulate) run on a prebuilt software stack

0 Upvotes

I've been building Cove, a development environment for scientific applications.

  • R, Python, Julia and Rust from the same software stack, with Python inside R through reticulate
  • Thousands of packages already built and shared by every project
  • Code, consoles, plots and an AI agent in one workspace
  • Every project runs at its own address; work is saved every 30 minutes and any version can become a container image
  • MIT-licensed: install it on your own servers and point the agent at your own Anthropic or OpenAI key

Install on Linux: `curl -fsSL https://ndexr.io/install.sh | sh`

Site: https://ndexr.io Source: https://github.com/fdrennan/cove

I'd value blunt feedback on what's missing for your workflow.


r/rstats • • 10d ago

Why is coxph choosing 2 as reference from survsplit data

6 Upvotes

Hi

I'm a currently a beginner with survSplit and I was curious why it seems like coxph chooses 2 as reference here from my survsplit data in my MRE below:

library(survival)
library(tidyverse)

lung <- lung

lung <- lung %>% 
  mutate(status = if_else(status == 2, 1,0)) %>% 
  mutate(ph.ecog = case_when(ph.ecog == 0 ~ 0,
                             ph.ecog == 1 ~ 1,
                             TRUE ~ 2)) %>% 
  mutate(ph.ecog = factor(ph.ecog))


lung200 <- survSplit(Surv(time,status) ~ sex + age + ph.karno + ph.ecog, 
                     data = lung, cut = c(200), episode = "time_group")


coxph(Surv(time,status) ~ ph.ecog:strata(time_group) + sex + age + ph.karno, 
      data = lung200 )

r/rstats • • 10d ago

Unpacking during assignment in R

3 Upvotes

R indeed already has this with %<-℅ from zeallot package but I don't think you can apply it into assigning variables inside for loops like Python did with its for i, j in iter_item. Same goes with unpack from 'wrapr' package. It would be so incredible if R has good unpacking functionality so that I would avoid writing similar to

for (i in seq_along(iter_item)) {
  x <- iter_item[[i]]
  cat(i, ". ", x, "\n", sep = "")
}

every time and instead, we'll do something like:

for (unpack(x, i) in enum(iter_item)) {
  cat(i, ". ", x, "\n", sep = "")
}

It's a bad syntax but as long as unpacking is involved, I'm fine with it. Maybe I missed other packages that does the job.


r/rstats • • 12d ago

Plotted 60 days of my quantile forecasts against what happened. The 80% band only held 66%

10 Upvotes

Forecasting a daily price with quantreg::rq() at tau 0.1 n 0.9, then plotting the band vs actuals in ggplot every week.

  • In sample the 80% band covers about 79%
  • Last 60 days: 66%
  • Adding a 20 day rolling sd as a predictor got it to 70
  • Refitting weekly instead of monthly changed nothing

I've seen conformal quantile regression mentioned a few times. Is that what ppl use in R for this, or do you just compare against an outside range like the glimpse markets one, and is there a package you'd recommend?


r/rstats • • 13d ago

The major S7 version 1.0 has been released!

Thumbnail
opensource.posit.co
65 Upvotes

Finally, S7 has reach its mature v1.0.0 release, and I have been waiting for this as an S7 user. It has the capabilities of S3 and S4, but more robust with types and classes and arguably less stupid (see more in this blog), albeit the complexity. R's Lisp-y mechanics never fails to amaze me (also sometimes a pain), something that is missing in Python, which is the reason why R has multiple classes (for better or for worse, your call), and also because of this, I like the new changes in S7, including the walrus := operator (I find this redundant at first but changed my mind later), its S4 inheritance semantic — now, I can work with legacy S4 codes with less pain (or so I hope), and its method dispatch mechanics for unary/binary operators. There are many more in this release, yes, but those are the things I like the most, but those are the things that caught my attention.

Though by this release, it somehow broke our package and we have to fix it until Dec. 11 😑, but it's no biggie I suppose.


r/rstats • • 14d ago

Preferred libraries for Bayesian Optimization

11 Upvotes

I've been trying to move a Bayesian optimization setup I made in Python via Scikit Learn & Optuna over to R and I found a couple different ways to do it.

The first results I found were tutorials using caret and rBayesianOptimization packages. Upon digging further I found out about Tidymodels and the whole system with Parsnip + Dials seems to be similar to what I was using and more recently updated.

Wanted to ask if there was a significant difference in performance between these different Bayesian optimization methods, and if there is a package I haven't found yet that I really should be using for this. My guess is that I'm overthinking it and that if I like Tidyverse then I should use Tidymodels.

The specific models I'm optimizing are survival or time-to-event models. I initially made these via scikit-survival + lifelines but I've been moving to the survival + ranger R packages so I can run them with the MICE multiple imputation package.