r/rstats • u/doritos_burrito • 1h ago
r/rstats • u/Bikes_are_amazing • 21h ago
Why is coxph choosing 2 as reference from survsplit data
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 • u/Confident_Bee8187 • 1d ago
Unpacking during assignment in R
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 • u/Junior_Bee7274 • 3d ago
Plotted 60 days of my quantile forecasts against what happened. The 80% band only held 66%
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, and is there a package youd recommend?
r/rstats • u/joshua_rpg • 3d ago
The major S7 version 1.0 has been released!
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 • u/Xenon_Chameleon • 5d ago
Preferred libraries for Bayesian Optimization
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.
r/rstats • u/international-guy • 6d ago
Looking for online courses or books to learn statistical analysis in R for social sciences
Hi everyone!
I have a bachelor's and a master's degree in Political Science, and I'm looking for a beginner-friendly online course or book that teaches quantitative methods using R, specifically for social research (i.e. social statistics with R for sociology, political science, and the social sciences more broadly).
I'm not looking for an online course or book that covers the entirety of R for every possible statistical method, as that would be far too broad. I'd like something focused on quantitative methods for social sciences, starting from the basics. I had a statistics class, but unfortunately it was just theoretical, with no software involved. I assume the online course or book would include, for example:**
• descriptive statistics
• hypothesis testing
• most importantly, regression analysis using R.
Any advice?
r/rstats • u/spinesoakedwithmagic • 6d ago
Swirl: Lessons do not load. Help
Hi. Im trying to learn R with Swirl, but from lesson 10 onwards I get the error shown in the screenshot.
I am super confused. I tried searching the directory but found no folder named "AppData" inside "Usuario". The apps "R-4.6.2-win" "R_Programming_E" and company are all in my Downloads folder,
I dont get why its trying to search a folder that never existed and never told me to create.
I dont know if the solution is obvious and im just too tired, or if this s a bug im unaware of.
Can someone help me?
Thank you for reading this far
I just published rairai on CRAN! It’s an MCP server built to speed up R package development.
Hi folks! If you use AI coding agents to develop R packages, you might find rairai useful. It’s an MCP server that uses Tree-sitter to give agents a structured view of an R package. For example, an agent can find where a function is defined and used, check what the package imports, or look up a help page. Think of it as a language server designed for AI agents.
I built rairai out of frustration with a few things I kept seeing in my own work. I’d watch an agent burn tokens searching for a function and fill its context with unrelated code along the way. Sometimes it would miss that a function was already imported and add namespace prefixes where they weren’t needed. Other times it would guess what an argument did or what a function returned instead of checking the docs, and miss an important side effect.
The idea behind rairai is simple: give agents easy access to the same information I’d look up myself. Language servers are built around what an editor needs. I built `rairai` around the questions I want an agent to ask, like “What should I check before changing this function?” The goal is to get the relevant information in one call without filling the context with unrelated code.
You can find it on CRAN, and the source is on GitHub. If you try it on one of your own packages, I’d love to hear what worked and what you’d change!
Shipping R-Powered Drug Discovery Models as Apps on an Enterprise AI/Data Platform
Most R machine learning models for drug discovery never leave the researcher’s laptop. Getting them into a governed, production AI app is a different challenge.
Now on the R Consortium YouTube channel: Chanin Nantasenamat, PhD (Lead Developer Advocate, Snowflake) walks through a case study from R+AI 2026, taking R-based models from exploratory lab code to production on an enterprise data platform. Reproducible preprocessing, molecular feature engineering, training and scoring, version control, containers, and a Streamlit frontend so scientists can query predictions without touching code, plus secure deployment, keeping proprietary chemistry in-house, monitoring, and cost control at scale.
"From Lab to Production: Shipping R-Powered Drug Discovery Models as Apps on an Enterprise AI/Data Platform"
r/rstats • u/Exciting-Platypus-63 • 7d ago
Is AI there yet?
I have only used the free tiers of the most popular AI chats for some code generation. And it takes at least 50 whips, before an acceptable output.
Can the newest, paid versions really work from start to finish on their own? Or are the people on Twitter having an AI psychosis?
r/rstats • u/SaikonBr • 8d ago
Long time ago i made a simple script to animate a maze generation process, it was well receiveid, but i set to private the repo and lost all my stars. Decided to give a lift up. Today in the era of agents this is trivial, but it was a great archieviement for me at the time. So here its a nice gif.
Also some mazes being solved
Full gallery: https://matfmc.github.io/mazegenerator/articles/gallery.html
r/rstats
•
u/New-Jellyfish-9498
•
8d ago
cuplyr: dplyr on an NVIDIA GPU
I've been building cuplyr, a dplyr backend for NVIDIA GPUs built on RAPIDS cuDF. It works pretty much like dbplyr. You can upload a data frame with tbl_gpu(), write normal dplyr code and collect() or compute() the results. On a 10-million-row pipeline it runs about 40x faster than dplyr on my machine. But depends a lot on different tasks.
It's still experimental, and I'm sure there are plenty of cases I haven't hit yet. If you try it on dplyr code you already have and something would either break or run extremely slowly. I would appreciate a bugreport! Just remember to set options(cuplyr.fallback = "warn") as the default behaviour is currently to fall back to the CPU quietly.
You don't need your own GPU to try it. This Colab notebook installs it on a free GPU, and then you can paste in your own code: https://colab.research.google.com/github/bbtheo/cuplyr-material/blob/main/notebooks/try-cuplyr-colab.ipynb
If you would want to install it on your own machine you need Linux, an NVIDIA RTX 20-series card or newer, and CUDA 12.2+.
Most of the code was written with a multi-agent Claude setup, using dplyr's own test suite to check the results extensively.
Repo: https://github.com/bbtheo/cuplyr
TLDR: dplyr on a GPU
r/rstats • u/davisvaughan • 8d ago
rray: An array focused R package, inspired by NumPy
After SEVEN LONG YEARS I am thrilled to be able to say that rray is back on CRAN!
rray is an array focused R package (not data frames, for once!), extremely inspired by NumPy.
- Broadcasting
- Combining and splitting
- Flexible slicing
- Long vectors
- And so much more!
Broadcasting is the idea of applying the tidyverse recycling rules (length 1 recycles to any other length) to all axes of an array. It allows you to, say, add a 2x1 array to a 1x3 array in a meaningful way, with a 2x3 result. Read about it in our broadcasting vignette:
https://rray.r-lib.org/articles/broadcasting.html
rray has a very powerful (and fast!!) family of functions for combining and splitting arrays. Like everything else in the package, they support broadcasting, allowing you to combine in ways that rbind() and cbind() don't allow:
https://rray.r-lib.org/articles/toolkit.html#combining
rray has "long vector" support throughout the entire package, meaning that it works with arrays longer than ~2 billion elements with no issues.
Array terminology can be highly confusing, so rray documents precise definitions exactly once, and uses them throughout the package. rray is intentionally very consistent! Once you learn one concept it tends to translate well to the other functions in the package:
https://rray.r-lib.org/articles/terminology.html
rray is an interesting experiment for me. It was created almost entirely from my phone using Claude's and Codex's remote-control features. But it is not slop! I personally vouch for every line of code, and ruthlessly interrogated each one. As an example, here's the development of `rray_if_else()`. After planning and creating with Claude, I followed up with ~30 corrections to forge it into something I felt met my high quality bar (I am a maintainer of both dplyr and vctrs, so my standard is extremely high). The result is that rray's R and C code don't "feel" AI written to me.
https://github.com/r-lib/rray/pull/137
I've created a neat visualization that tracks rray's development over time. You can see every conversation, in full, paired with the PR and function it generated. It also shows approximate cost at API prices (though I used a subscription).
r/rstats • u/Pei-Pa-Koa • 8d ago
Expired GP key for CRAN-R Debian packages
Hi,
The GPG key used to sign Debian packages for CRAN-R has expired:
LANG=en gpg --list-keys 95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7
pub rsa4096 2021-11-16 [C] [expired: 2026-11-15]
95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7
uid [ expired] Johannes Ranke <johannes.ranke@jrwb.de>Can anyone ask around on the r-sig-debian mailing-list?
r/rstats • u/Mema9080 • 9d ago
Need advice: Using RStudio for my master’s thesis data analysis and making sure I’m doing things correctly
Hi everyone!
I’m currently working on the statistical analysis for my master’s thesis in nutrition science, and I’d really appreciate some advice from people experienced with R and research data analysis.
My study involves survey data from over 1,300 participants, including demographic variables, dietary frequency data, knowledge questions, and Likert-scale responses related to attitudes and behaviors.
I’ve studied statistics during my degree, but applying statistical methods to a real dataset feels quite different from learning them in class.
I’ve been using RStudio and AI to help with coding, data cleaning, statistical tests, and visualizations. While AI has been incredibly helpful, I sometimes worry about whether the suggested methods are statistically appropriate, even when the code runs without errors.
I genuinely want to understand what I’m doing rather than simply copying and running code, especially since the results will be part of my thesis.
For those who use R in academic research:
How do you verify that your statistical analyses and R code are correct?
What resources helped you bridge the gap between statistical theory and practical analysis?
Do you have any advice for using AI responsibly when writing or reviewing R code?
I’d really appreciate any guidance, resources, or personal experiences.
Thank you!
r/rstats • u/OutdoorSportBoy • 9d ago
Will R development move to GitHub?
It feels a bit surprising that core R is still developed on SVN when almost its entire package ecosystem relies on Git and GitHub. Are there any plans to eventually migrate R to GitHub? Moving over could really attract more contributors.
r/rstats • u/LuscasMathias • 8d ago
erro fatal no Rstudio quando tento puxar um dataframe
reddit.comr/rstats • u/Delicious_Abies_9708 • 8d ago
Initial VuPy release: CuPy-like GPU array library backed by vulkan. any and all feedback is preferred.
r/rstats • u/majorcatlover • 9d ago
[Q] What would be the best approach to inter-rater reliability for temporally annotated events?
reddit.comr/rstats • u/Ok_Mortgage1263 • 13d ago
mascot 0.1.0 on CRAN: animated characters for Shiny apps and Quarto pages
mascot 0.1.0 is now on CRAN. It puts a small character, drawn in code, into your Shiny app. You set its mood and status from the server, and it gives a short wiggle when the state changes.
For Shiny specifically:
# UI
mascot("helper", mood = "idle", status = "Ready when you are", placement = "inline")
# server, when the state changes
update_mascot("helper", mood = "worried", status = "Two dates need a look")- Works inside modules, golem and rhino-style apps (`mascot_examples()` has one of each, plus a form check and a long task)
- `update_mascot()` also shows a speech bubble or plays a nod or wave
- `mascot_popup_menu()` makes the mascot a button with a menu; the choice comes back as `input$<id>_menu`, and it works with the keyboard and screen readers
- Floating in a corner (minimisable) or inline in the page
- Follows your `bslib` theme or your own brand colours, light and dark mode
- Everything ships with the package, no CDN, so it works offline; reduced motion is honoured
- `mascot::mascot_studio()` lets you try every argument and copy the code
Install: `install.packages("mascot")`
Docs: https://insightsurge.github.io/mascot/
Source: https://github.com/insightsurge/mascot
Some parts are experimental in 0.1.0 (Knurl, Neer, the studio, custom character files). I'd like to hear how it fits into your apps and what's missing.
r/rstats • u/The_God_was_Here • 12d ago
How do you plot calibration for daily range forecasts over time in ggplot?
Have about 120 days of daily forecasts for a price series. each day has a forecast median, an 80% interval and the actual close. i want to show two things clearly:
- how taken the actual landed inside the 80% band, and whether that changes over time
- whether the misses cluster on certain kinds of days(high vol)
right now i have a geom_ribbon for the band with geom_point for the actuals, plus a separate bar chart of hit rate by month. it works but feels clunky and nobody gets it on first look
any better ways to show coverage time? a rolling coverage line? some package i don't know about? happy to share code if useful