The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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`.

6,600 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
20
votes
0answers
1k views

How to create a multivariate Brownian Bridge

It is known, that a standard multivariate Brownian bridge $ y(\mathbf u) $ is a centered Gaussian process with covariance function $$ \mathbb E(y(\mathbf u) y(\mathbf v)) = \prod_{j=1}^d (u_j \wedge ...
16
votes
0answers
575 views

Fitting custom distributions by MLE

My question relates to fitting custom distributions in R but I feel it has enough of a probability element to remain on CV. I have an interesting set of data which has the following characteristics: ...
12
votes
0answers
4k views

Specify correlation structure for different groups in mixed-effects model (lme4/nlme)

I am trying to account for spatial autocorrelation in a linear mixed-effects model in R with measurements repeated in time. BodyMass has been collected once per <...
12
votes
0answers
918 views

Implementation of CoVaR (a systemic risk measure) in R

I'm trying to estimate CoVaR using bivariate DCC GARCH in R. The concept of CoVaR is the dependence adjusted of VaR, which was first introduced by Adrian and Brunnermeier (2011). However, this ...
11
votes
0answers
2k views

Gamma hurdle model for continuous response

I am modelling invertebrate.biomass ~ habitat.type * calendar.day + habitat.type * calendar.day ^ 2, with a random intercept of transect.id (50 transects were repeated 5 times) My response is zero-...
11
votes
0answers
1k views

The role of scale parameter in GEE

I am learning the generalized estimating equations (GEE) and the geepack R package. There are some questions that I am a little confused. In a GEE-constructed ...
11
votes
0answers
4k views

How to compute confidence interval in ANOVA with repeated measures?

I made a model using repeated measures univariate ANOVA in R. ...
11
votes
0answers
971 views

Testing for a significant difference between ML estimates: Likelihood ratio or Wald test?

I am trying to test whether or not there is a significant difference between maximum likelihood estimates of two genetic parameters (selection and dominance) across two environments with genotype data ...
8
votes
0answers
158 views

Why is the type I error (power?!) for shapiro.test on studentized residuals on lm is 10% and for regular residuals is just 5%?

I understand that the residuals from a regression model are not i.i.d. Hence, checking if they are normal (even when we know it is the case), should be a problem since they are dependent. The ...
8
votes
0answers
1k views

Compute partial $\eta^2$ for all fixed effects anovas from a lme4 model

Disclamer: I wasn't sure where to post this question: CV or SO, but eventually decided to try here first I've been asked by one of the reviewers to add effects sizes (preferably $\eta^2_p$ which is ...
8
votes
0answers
492 views

The Regularization Path for Smoothing Splines

I've got a potentially interesting question. Does anyone know if R already has a package for calculating the entire regularization path of the smoothing spline? That is, for: $$\hat{f}_{\lambda}=...
8
votes
2answers
3k views

How to predict state probabilities or states for new data with DepmixS4 package, for Hidden Markov Models

It seems like I can learn the parameters just fine and find the posterior probabilities for the training data but I have no clue on how to make new predictions on new data. The problem in particular ...
8
votes
0answers
2k views

glmer in R: Significance estimates are not robust to order of data frame

I'm using a mixed effects model with logistic link function (using lme4 version 1.1-7 in R). However, I noticed that the estimates of significance for fixed effects change depending on the order of ...
7
votes
0answers
1k views

How to generate 2 correlated Beta random variables

I was wondering if it might be possible to generate 2 correlated $Beta$ random variables? In other words, I want to generate two Beta random variables which can be said to have come from two Beta ...
7
votes
1answer
1k views

Comparing two multinomial distributions

Background: Imagine a pizza cut into 8 slices. On each straight edge of the slice, I insert a magnet with opposite polarities facing outwards. If I separate these components, prevent flipping and ...
7
votes
1answer
4k views

How to determine weights for WLS regression in R?

I am trying to predict age as a function of a set of DNA methylation markers. These predictors are continuous between 0 and 100. When performing OLS regression, I can see that variance increases with ...
7
votes
1answer
1k views

How to test for the difference in skewness of two samples?

I have two samples. From looking at their densities, one appears symmetrical and the other from some right-tailed distribution. I would like to test that the two do not have the same skewness (...
7
votes
0answers
2k views

Comparing two ECDFs using Kolmogorov-Smirnov test (alternative hypothesis)

I am taking measurements of a computer system performance over time and I'd like to understand if the performance is degrading or improving as time passes.. After doing some research, I picked the KS ...
7
votes
0answers
2k views

How to use formative indicators in covariance-based SEM with lavaan?

I'm trying to build a covariance-based structural equation model (SEM) using both reflective and formative specifications of latent variables. I use the sem ...
7
votes
0answers
2k views

Interpretation of crossed random effect interactions in lme4

I'm considering a model in lme4 in which I am estimating random effects for two crossed factors, very similar to the Machines example in Bates' 2010 draft book (http://lme4.r-forge.r-project.org/lMMwR/...
7
votes
1answer
744 views

Using Google Causal Impact package to assess the significance of a planned intervention

I am using the Causal Impact package in R to infer the causal effect of an intervention in some data which are highly correlated and seasonal. Specifically, i got 17 days of hourly data, intervetion ...
7
votes
1answer
710 views

Random Forest: Class specific feature importance

I'm using the bigrf R-package to analyse a dataset with ca. 50.000 observations x 120 variables, classified into two groups. After growing a forest of 1000 trees, ...
7
votes
1answer
513 views

Hypergeometric: how do I construct a credibility interval around K (population successes) in R?

I have a problem for which I believe I should use the hypergeometric distribution, but I can't figure out how to do it in R. Say I have a bag of marbles with known number ($N$) of marbles, but the ...
6
votes
1answer
749 views

forecast::auto.arima() is not returning a model with a differencing parameter when it should

I'm experiencing an issue in which it seems forecast::auto.arima() isn't returning a model with a differencing parameter when it should. Read through my reproducible example to arrive at the question. ...
6
votes
1answer
702 views

Why are (almost) all of my corrected (Benjamini-Hochberg) p-values equal?

I have the following p-values: ...
6
votes
0answers
473 views

How to estimate random-effects for new subjects for predictions (example in GNU R's lme4)

I'm wondering how to make predictions for new subjects from a fitted mixed-effects model (in a frequentist framework). Specifically, we have multiple observations on a set of subjects to which we can ...
6
votes
0answers
3k views

How to choose bootstrap confidence interval type from boot.ci in R?

The boot.ci documentation in R says there are five different types of confidence interval that boot.ci will return: norm (normal approximation) basic stud (...
6
votes
1answer
145 views

How to analyse growth rate in R?

Within the framework of an experiment I followed to growth rate of bird nestlings. I measured them every day for weight and tarsus. I have a number of continuous and categorical explanatory variables, ...
6
votes
0answers
533 views

How good is an optimal design (DOE)?

I am looking at an experiment with 5 factors (4 numeric and one nominal) with three levels for each numeric and 2 levels for the nominal. Instead of the 162 runs, I am interested in a small design (30 ...
6
votes
0answers
282 views

Mixed models formulation (GAMM, GLS, nlme): from R to mathematical notation

I have just finalised the analysis of a dataset fitting Generalised additive mixed models (GAMMs) with mgcv package in R v3.3.0. But I am having trouble in writing my models into their correct ...
6
votes
0answers
1k views

Interpolation with radial basis functions (RBF) is failing for some reason

This is not a pure programming question. I am trying to understand what's going on when I try to use RBF with 5 centers. I am using R to exemplify, see below. My data set: ...
6
votes
0answers
504 views

How should I include age in this mixed-effects model?

I've got repeated measures of hearing thresholds for a set of patients who each have a different inner ear measurement. This data is unbalanced, there are a varied number of measurements at varied ...
6
votes
0answers
862 views

How to fit a function to a CDF in R?

Background: I've been given a dataframe that contains data for a CDF. The column X contains the 250 $X$ values, and the column P ...
6
votes
0answers
813 views

Confidence interval of the mean response from nonlinear model

My problem (question at the end) is to calculate confidence interval (CI) (NOT prediction interval) of the response of a nonlinear model. I am working with R but this question is not R-specific. I ...
6
votes
1answer
481 views

Forecasting daily visits using ARIMA with external regressors

I have daily visitors data for the last 10 years. I want to do some basic tests like which is the busiest day, which is the busiest month, busiest week etc. I used ...
6
votes
0answers
1k views

Relationship between Gumbel and Weibull distribution, accelerated failure time models, and Survreg using R

I have three questions concerning accelerated failure time models (AFT), one statistical, one regarding how to implement these models in R, and one related to finding out information about what R is ...
6
votes
0answers
1k views

“weight” input in glm.nb function in R. How exactly does the weight affect the likelihood?

I would like to understand how the weight argument of glm.nb is affecting the likelihood function. I understand that glm.nb find the MLE in an alternating iteration process where for a given theta the ...
6
votes
0answers
2k views

Interpreting and reporting gamm4 result

I am new to gam, and most of my knowledge comes from this document http://www3.nd.edu/~mclark19/learn/GAMS.pdf. Now I am using generalized addictive model with random effects to model some data, where ...
6
votes
0answers
8k views

covariate selection for a cox model by Lasso using glmnet

I would like to use model selection through shrinkage (Lasso) using glmnet. So far I did the following: ...
6
votes
0answers
1k views

How to deal with underdispersion with binomial data

I'm working with a pretty large dataset (n = 4,500) where 10% of my points (pixels in a GIS landscape) are 1s and the rest are 0s. The full model for my data looks something like this: ...
6
votes
0answers
1k views

R model.matrix and makeContrast. Understanding model and possible contrast

I have measurements from 12 mice, grouped in two conditions. I each mouse I have measurements from 4 tissues. The design is not balanced, 5 mice in condition1 and 7 in condition2. After reading the ...
6
votes
0answers
2k views

Appropriate negative eigenvalue correction for PCoA of genetic distances

I am trying to find the best way to represent genetic distances in a plane so that they may use them as response variables in canonical redundancy analysis (using ...
6
votes
0answers
2k views

Hyper-prior for negative binomial in hierarchical model using JAGS/BUGS

Below I'm using a negative binomial because it is more flexible than a simple poisson model. The data are counts $y$ of events for 16 individuals $x$. There are 14 counts (i.e. counting periods) for ...
6
votes
1answer
789 views

Johansen test conditions and Breusch-Godfrey LM test

I am a student from Belgium and I am writing a thesis about the relationship between credit aggregates and property prices. I examine the Granger causality between the two variables and I also do some ...
6
votes
0answers
3k views

Confidence interval for the restricted mean in survival analysis

What is the recommended way of calculating confidence intervals for the restricted mean in survival analysis? Here are some example data, taken from the paper Chris Barker (2009), The Mean, Median, ...
6
votes
0answers
2k views

How to simplify coxme survival models?

I have some questions about specifying a coxme (mixed-effects Cox proportional hazards) model in R and then simplifying it after reading the ...
6
votes
0answers
3k views

Time series clustering: Fourier transform and PCA

I have biological time series (9 years long) of the biomass of species which logically exhibit a seasonal pattern. I would like to cluster them into a few groups based on their typical seasonal ...
6
votes
0answers
510 views

Calculate goodness-of-fit (with deviance) to compare averaged models?

I need to compare the goodness of fit of several averaged logistic regression models by calculating the deviance explained. I'm using the MuMIn package in R to ...
6
votes
0answers
285 views

Numerical properties of the logistic growth model for non-linear regression

I am using the nls procedure in R to fit a logistic growth model. In their SSlogis function, José Pinheiro and Douglas Bates chose the formulation ...
6
votes
0answers
93 views

Territories from observations

I have a number of animal observations, and want to deduce the number of territories (i.e. the number of individual animals) from this. More formally, the problem can be stated as follows: Each ...