Questions tagged [r]
R is a free, open source programming language and software environment for statistical computing and graphics.
376 questions
0
votes
0
answers
49
views
Mediation analysis using AFT
I have this R code for mediation analysis based on AFT.
Can someone take a look?
https://github.com/cristianricciwork-commits/aft-mediation..git
I suggest to take a look at the .pptx (there are ...
1
vote
0
answers
74
views
Combine and Propagate "Vectors" in Power Query M
Background
In an earlier post, I prototyped an M equivalent of tidyselect in R: in particular, its general syntax and selection helpers. In this post, I prototype ...
1
vote
0
answers
119
views
Vectorized approach for generating random numbers with specified count and sum
I'm looking to optimize my code by avoiding the use of a for loop, in order to improve performance when working with large data frames controlled by ...
5
votes
1
answer
243
views
Compute rolling median absolute deviation (MAD) in R
I am computing the rolling Median Absolute Deviation (MAD) in R for outlier detection in a time series dataset. The goal is to:
Detect outliers based on a rolling MAD.
Exclude previously detected ...
0
votes
0
answers
69
views
Tracking how much money you made in stock market
I am trying to write R code to see how much money someone could have made in the stock market had they invested in a certain amount of money in a certain stock between two dates (while taking into ...
7
votes
2
answers
391
views
Custom expectations: Reuse existing `testthat` functions
I came up with these lines to test if an R list contains a certain element at a given index (supplied by purrr::pluck syntax):
<...
3
votes
1
answer
108
views
Finding repeats in DNA in R
I recently wrote some R code, which I would normally not do, to find repeats in DNA fasta files.
Here is an example fasta file:
...
2
votes
1
answer
250
views
Pattern search algorithm for infinite integer string in R
Let X = "1234567891011..." the infinite string contains all positive integers. str is a sequence of digits. We are asked to find the first location in X that str appears.
I have tried the ...
4
votes
1
answer
242
views
Simulating people talking to each other in a network
I have this network graph in R:
...
2
votes
0
answers
111
views
R function to expand range of numbers/alphabets in a regex
I tried writing a short function that expands brackets [] within a regular expression. Given a regular expression, the function will expand the brackets and return ...
1
vote
0
answers
48
views
Using ARIMAX correctly in R
I am working with the R programming language. I have data on crop yield and fertilizer costs. I want to make a time series model (ARIMAX) that predicts crop yield based on (crop yield -1, crop yield -...
4
votes
1
answer
109
views
R function to do rolling cross validation
Consider a generic (univariate) time series model:
$$ \hat{y}(x_n, \ldots, x_{n+h-1} \mid x_0, \ldots, x_{n-1}; \boldsymbol{\theta}) $$
Where:
$$ \hat{y}_{t+h} \text{ is the forecast for the next } h \...
6
votes
2
answers
126
views
Mean by groups Rcpp
Here is an attempt to translate a R function to Rcpp. The goal is to group every n observations together (of a numeric vector) and calculate the mean.
On big'ish vectors the R function is almost two ...
2
votes
1
answer
167
views
R Script to forecast volatility of monthly crude oil prices using GARCH
This is my first time writing a script for volatility forecasting and I am fairly new to econometrics. I chose to analyze monthly WTI crude oil prices of past 20 years and determine volatility as well ...
4
votes
2
answers
96
views
Correctness of newborn feeding data visualization
Just wanted some code review for correctness here. This is a little app for plotting newborn feeding data (important to keep track of in the first 48 hours of so) that I hope to provide to a clinic, ...