Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Questions tagged [r]

Use this tag for any *on-topic* question that (a) involves `R` either as a critical part of the question or expected answer, & (b) is not *just* about how to use `R`.

Filter by
Sorted by
Tagged with
4
votes
2answers
6k views

Monte Carlo simulation for VaR estimation using R

As I am not very experienced in financial econometrics I need help in writing R code for MC simulation for VaR estimation. Namely, reading some books and reference manuals for R packages, I ended up ...
-1
votes
2answers
5k views

How to get the difference of two numbers (standard deviation)?

I have many pairs like: A B 10 20 15.3 19.5 23 13 45 32 etc etc, I create those pairs calculating the standard deviation of many vectors (R vectors) and then ...
5
votes
2answers
6k views

Is there a term for min + (max - min) / 2?

I'm looking for a function to do that in R. I know how to write that function. Just don't want to reinvent something.
5
votes
2answers
332 views

Data structures and libraries for high dimensional text analysis with R

I am going to be using R for text analysis (mostly clustering, classification and some visualization) and was wondering what mechanisms R provides for handling high dimensional, sparse data sets. If I ...
6
votes
1answer
1k views

Function to convert arithmetic to log-based covariance matrix?

Is there a function in R that will take the mu and Sigma of an arithmetic-covariance matrix and return the mu and Sigma of a log-based covariance matrix? I have the code for a function implementing ...
2
votes
1answer
8k views

Using R's aov() for two-way repeated-measurement ANOVA

We analyze blood vessel samples of patients in an organ bath which gives us force values. Each subject (patient) donates two types of blood vessels (pulmonary vein and pulmonary artery). The organ ...
17
votes
3answers
14k views

Time dependent coefficients in R - how to do it?

Update: Sorry for another update but I've found some possible solutions with fractional polynomials and the competing risk-package that I need some help with. The problem I can't find an easy way to ...
1
vote
1answer
438 views

Is it possible to compare multiple proportions in subdata sets?

There is one medical data set which contains 3 treatments: A, B, and C. The response variable is Yes/No. However, due to a specific medical reason, the dataset needs to be split into several sub-...
8
votes
3answers
4k views

Estimating random effects and applying user defined correlation/covariance structure with R lme4 or nlme package

I have following type of data. I have evaluated 10 individuals each repeated 10 times. I have 10x10 relation matrix (relationship between all combination of the individuals). ...
6
votes
1answer
19k views

Fisher's exact test in R

First, I am no expert but I am analyzing some marketing data. I have information on two versions of the same site, and I have data on the number of times people filled out a form on each version of ...
6
votes
1answer
4k views

How do I parameterize a Weibull distribution in JAGS / BUGS?

Based on the answer to a previous question, For which distributions are the parameterizations in BUGS and R different? I have been transforming R parameterizations to JAGS parameterizations, but I ...
9
votes
1answer
2k views

Computing inter-rater reliability in R with variable number of ratings?

Wikipedia suggests that one way to look at inter-rater reliability is to use a random effects model to compute intraclass correlation. The example of intraclass correlation talks about looking at $$\...
2
votes
1answer
901 views

Go from cluster to random forest

I'm working on improving a random forest model. I've done some clustering of the data using the pvclust package in R. I use ward and euclidean distances. My ...
3
votes
2answers
3k views

Incidence rate ratios (Stata vs R)

I asked this question on Stackoverflow: https://stackoverflow.com/questions/8142118/incidence-rate-ratios-in-r-poisson-regression and was advised to post here instead. I have data that looks like ...
2
votes
1answer
1k views

How to simulate binomial mixed effects data?

This R code simulates Gaussian mixed effects data with one random effect and one fixed effect. How would I modify that code to simulate Binomial mixed effects data with one random effect and one fixed ...
9
votes
4answers
9k views

Find probability density intervals

I have the vector x <- c(1,2,3,4,5,5,5,6,6,6,6, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,8,8,8,8,9,9,9,10) (my actual vector has ...
0
votes
1answer
105 views

Interpreting error when trying to import dta file in R

I'm trying to solve a couple of exercises in Gelman and Hill 2007. The datasets they use are all on a website, however, every time I try to import the files I get an error: pollution=read.table("...
10
votes
1answer
3k views

Predicting response from new curves using fda package in R

Basically all I want to do is predict a scalar response using some curves. I've got as far as doing a regression (using fRegress from the fda package) but have no idea how to apply the results to a ...
1
vote
1answer
259 views

Pre-PCA pooling in R

I was just wondering if it is possible to pool the data into groups before doing prcomp() in R? I have i.e. 100 individuals (rows) and 50 measurements(cols) with individuals being grouped in separate ...
21
votes
0answers
13k views

Formula symbols for mixed model using lme4 [duplicate]

I often confuse symbols :, |, / and * in the ...
1
vote
1answer
3k views

Why don't I get the p-value doing an ANOVA test?

I want to regress two series (one big series divided in half) with the mean of the big series. I do that because I would like to "investigate" the relationship between those two subseries and the ...
9
votes
3answers
25k views

How to calculate the difference of two slopes?

Is there a method to understand if two lines are (more or less) parallel? I have two lines generated from linear regressions and I would like to understand if they are parallel. In other words, I ...
3
votes
2answers
540 views

Mixed model specification in R

I have nested structure design with the following model: ...
4
votes
1answer
1k views

What's the difference between dlmSmooth and dlmFilter in R's dlm package?

Could someone please explain what the difference is between the two, and perhaps avoid the worst statistical jargon? I am currently using the dlm package to model ...
1
vote
1answer
676 views

Kalman smoothing of returns vs. prices with dlmSmooth in R's dlm package?

So I am using the R code behind Fig. 3.14 in Dynamic Linear Models With R (p. 124-5) to make a dynamic version of a simple pair trading model: $$ Y = \alpha + \beta X. $$ If I use log returns (<...
2
votes
2answers
421 views

R sparse smoothing splines

I would like to fit a model of the form weight ~ bs(height) + id, where id is a factor (so I have several observations per every id). There are perhaps 100k values ...
5
votes
1answer
3k views

Odd error with caret function rfe

library(caret) set.seed(1) x <- data.frame(runif(10),runif(10)) y <- rnorm(10) rfeModel <- rfe(x,y,rfeControl = rfeControl(functions = lmFuncs)) returns:...
4
votes
0answers
224 views

R: looking for “time” clusters in a data set [closed]

I am new to R and seeking some advice. I have a set (~20M) of data describing on which step a process did fail or succeeded: ...
2
votes
1answer
1k views

How to analyze the volatility with GARCH?

How could I use GARCH model to detect if the volatility is constant during all the series(time series)? I can't do a visual check, I need to detect if the volatility is constant using R and GARCH ...
2
votes
2answers
761 views

Displaying multiple conditional distributions using lattice

I have a data frame which contains several true/false columns, some numeric and a class (target) variable which has true/false values. Now, how can I produce with R multiple barplots for all ...
1
vote
3answers
9k views

Fitting a multivariate ARIMA model with R

I have 4 correlated time series, and I want to predict one of them, from the other 3. There is a clear seasonal effect in the 4 time series, so my first thought was to fit a multivariate ARIMA model, ...
3
votes
0answers
278 views

Controlled experiment with binary outcome variable

I have data from an experiment where students were tested on multiple words for the correct pronunciation of a specific linguistic phenomena. The experiment was done with a control and experimental ...
2
votes
1answer
1k views

Algorithms to find most frequent data

I want to find most frequent words in some cases that some words stand out. I have two data for each case, the word and the number of times it appears. I want to know which algorithms, techniques can ...
13
votes
2answers
7k views

Assessing logistic regression models

This question arises from my actual confusion about how to decide if a logistic model is good enough. I have models that use the state of pairs individual-project two years after they are formed as a ...
5
votes
2answers
10k views

Predicted by residual plot in R

I'm wondering what the difference is between: 'predicted by residual plot' where I plot the residuals of the regression with the predicted values of the regression ; the case where I plot the ...
11
votes
1answer
42k views

What are the predicted values returned by the predict() function in R when using original data as input?

After running a regression of the form reg <- lm(y ~ x1 + x2, data=example) on a dataset, I can get predicted values using ...
0
votes
1answer
4k views

Plotting regression predictors

In the case of multiple regression where I have dependent variable Y and two predictors X1 and X2 I would like to make a plot of their relationship before fitting a regression, however the plot ...
26
votes
1answer
51k views

How to interpret coefficient standard errors in linear regression?

I'm wondering how to interpret the coefficient standard errors of a regression when using the display function in R. For example in the following output: ...
1
vote
1answer
1k views

How to calculate all the combinations in R?

I have four letters: A B C D, I need to calculate all the combinations on the follow type: ...
3
votes
3answers
226 views

How to compute simulated differences of means repetitively?

I would like to run a 1000 simulations of $X-Y$ where $X$ is the average of 100 random observations with mean of 69.5 and SD 2.9 and $Y$ is the average of 100 random observations with mean of 63.9 ...
2
votes
1answer
7k views

Computing probability from the Poisson distribution

I have a question regarding the ppois function in R: ppois(x,lambda,lower.tail=TRUE) gives $P[X>x]$ ...
2
votes
1answer
303 views

Binomial regression with penalized ML

These coefficients look way too large to me, they seem to imply probabilities of around 0.5, instead of around .01, as I would expect. Here is sample code: ...
3
votes
2answers
1k views

Generating random numbers based on 'rule-of-thumb' proportions

I will try to be as clear as I possibly can: I want to populate a matrix of about 10 million rows by 43 columns as a test to an application The first task is to generate a random number around 10 ...
22
votes
1answer
7k views

Intraclass correlation (ICC) for an interaction?

Suppose I have some measurement for each subject at each site. Two variables, subject and site, are of interest in terms of computing intraclass correlation (ICC) values. Typically I would use ...
11
votes
2answers
16k views

Collinearity between categorical variables

There's a lot about collinearity with respect to continuous predictors but not so much that I can find on categorical predictors. I have data of this type illustrated below. The first factor is a ...
3
votes
0answers
1k views

Getting spline coefficients in R

I'm fitting a natural basis spline on a data set of the form: splineModel=lm(dist~bs(speed, df=3), data=cars) using bs ...
2
votes
1answer
311 views

Linear statistic for measuring association in the party R package

I had asked a general question about conditional inference trees via party a while back and gotten a great reply. I am revisiting this procedure and trying to make sense of the linear statistic that ...
7
votes
2answers
3k views

Transformation to fit gamma distribution for glm

The data simulated below has a maximum value of 4 and is interestingly skewed. The maximum of 4 is a limitation imposed by the instrument used and the data is semi-discrete, i.e., there are a ...
3
votes
1answer
11k views

Generating all possible unique combinations of dataset with two variables

I am fairly new to R and I have been reading all related topics but still I don't manage to solve my rather simple problem. I have a dataset with 5 cases for two variables (X,Y), for instance: ...
1
vote
0answers
650 views

Contrast to ANOVA with interaction term

I need to fit orthogonal contrasts to the following model. The following example data. ...