Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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

16
votes
0answers
955 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 ...
14
votes
0answers
424 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: ...
13
votes
0answers
956 views

Writing out the mathematical equation for a multilevel mixed effects model

The CV Question I'm trying to give (a) detailed and concise mathematical representation(s) of a mixed effects model. I am using the lme4 package in R. What is the ...
11
votes
0answers
761 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
4k views

How to compute confidence interval in ANOVA with repeated measures?

I made a model using repeated measures univariate ANOVA in R. ...
10
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 ...
10
votes
0answers
921 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 ...
9
votes
0answers
352 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 ...
9
votes
0answers
484 views

What are multivariate orthogonal polynomials as computed in R?

Orthogonal polynomials in an univariate set of points are polynomials that produce values on that points in a way that its dot product and pairwise correlation are zero. R can produce orthogonal ...
8
votes
0answers
3k 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 <...
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
743 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
0answers
390 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}=...
7
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-...
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

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 ...
7
votes
0answers
3k views

lmer() parametric bootstrap testing for fixed effects

I am performing a parametric bootstrap to test whether I need a specific fixed effect in my model or not. I have mainly done this for exercise and I am interested if my procedure so far is correct. ...
7
votes
0answers
470 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 ...
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/...
6
votes
0answers
141 views

Random Forest in a Big Data setting

I have a dataset with 5,818,446 lines and 51 columns, where 50 of them are predictors. My response is quantitative, so I am interested in a regression model. I am trying to fit a random forest to my ...
6
votes
0answers
394 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
230 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
2k 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 ...
6
votes
0answers
907 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
329 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
749 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
705 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
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
7k 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
725 views

Optimization in R vs Python, constrained, unconstrained and automatic differentiation?

I am an economics/stat guy who uses quite a bit of optimization (maximum likelihood, simulated maximum likelihood), constrained optimization (mathematical programming w/ equilibrium conditions), ...
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

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
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
2k 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
90 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 ...
6
votes
0answers
420 views

Post hoc tests for robust mixed design ANOVA using R

Is it possible to compute the function mcp2atm with unequal sample size? I ran the robust Mixed Design ANOVA by using tsplit and ...
6
votes
0answers
98 views

How to form a confidence band around the trend fitted from time series data

I have a time series data set. I can decompose it and get the trend but I would like to put confidence ranges around the trend (past) not the forecast-ed component. The decompose function also doesn'...
6
votes
0answers
496 views

Average Structural Function Calculation

EDIT: I have solved this problem myself. The problem with the simulation below is that the omitted variable should not be included in the 'true model'. I have written a blog post with a more detailed ...
6
votes
0answers
424 views

Programming a new random effects structure in lme

I am seeking advice on programming a new random effects variance-covariance matrix/structure (pdmat) in R for use in lme()? I've checked out the lme source code (as suggested if you want to program ...
6
votes
0answers
4k views

When to use longitudinal (panel) weights vs cross-section weights in complex surveys

I'm currently working with a longitudinal dataset, the Kauffman Firm Survey. The survey tracks about 5000 firms starting from 2004 - 2009. Firms die out over the years. It has both cross-sectional ...
6
votes
0answers
781 views

Canonical correlation analysis on a MICE data set

I am looking to do a canonical correlations analysis (CCA) in R, using the CCA package, on a multiply imputed dataset (obtained from the mice package). I know that ...
5
votes
0answers
44 views

Why does “mixtools” return the model with highest AIC as the “winner” if lower AIC is better?

Mixtools package is used to fit mixtures of normal/regressions. The package documentation is given here The regmixmodel.sel fits the mixture model for varying ...
5
votes
0answers
134 views

Whether to use EFA or CFA to predict latent variables scores?

I have a dataframe of individual observations, that I partitioned to create a training (0.7 prop) and a test set (0.3 prop). I started by running an exploratory factor analysis (EFA) on the training ...
5
votes
0answers
83 views

Does it makes sense to calculate a correlation between two binary variables?

I have a data set with 14 binary variables. I conducted a survey and there was a question with 14 elements of a specific method to which the respondents had to check if they used the element. Now I ...
5
votes
0answers
449 views

generalized linear mixed-effects models R^2 and the tweedie distribution

I am modelling data exhibiting a tweedie distribution in R using glmer (package lme4). To compare the models I would like to use the AIC and R^2. I have a couple of question on this (example code at ...
5
votes
0answers
254 views

Longitudinal mixed model: What random effects are possible?

I'm faced with analyzing the following design: In a longitudinal study, the muscle tissue of about 25 subjects are analyzed at 8 timepoints. Specifically, 7 measurements are taken during a race ...
5
votes
0answers
425 views

When and How to Scale Numeric Interaction Variables in Machine Learning Model

I found one similar question on cross validated, but it was unanswered; my apologies if this has been answered. I'm experimenting with feature interaction in a regression model I'm working on in R. ...
5
votes
0answers
207 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 ...