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
1 vote
1 answer
52 views

How to find variance of multivariable expression

I have an expression of this form $W_i = a * X_i * (1 - Y_i * (1 - Z_i))$, where $a$ is a constant, $X_i \sim Bernoulli({p_x}_i)$, $Y_i \sim Bernoulli({p_y}_i)$, and $Z_i \sim N(\mu_i, \sigma)$ ...
1 vote
1 answer
56 views

Fitted Gamma model doesn't go through first datapoint

I have a dataset which looks like this ...
0 votes
0 answers
7 views

Interpretation and examples for unit vs time fixed effects (oneway)

I seek to understand the difference between unit / entity / individual fixed effects and time fixed effects. Both are oneway. Many questions surround them in contrast or addition to twoway fixed ...
  • 284
0 votes
0 answers
6 views

How do I know if the function lavCor from the lavaan package in R computes the polychoric or the polyserial correlation?

to compute the pairwise correlation matrix for my variables I used the lavCor function from the lavaan package in R. I have 9 variables, from which 8 are ordered variables and one is metric. So I ...
  • 31
0 votes
1 answer
45 views

Predicting with GAM (mgcv) and categorical/factor covariate in R

I have some data for multiple users and I want to generate some marginal effects for each user using GAM modelling. If I do this exercise for just a single user (John) as: ...
  • 3
2 votes
1 answer
87 views

Restricted cubic spline looks like a linear curve, but p for nonlinear < 0.001

I am analyzing a association between a frailty index and care needs using the cox model. I use R and use rms package to fit restricted cubic spline. This is my R code. ...
4 votes
2 answers
124 views

Disagreement between studentized Breusch-Pagan test and the plots "residuals vs fitted" and "scale location"

Given the model: > Durée <- c(6, 5, 3.5, 3, 5, 3, 2, 8, 2.5) > Note <- c(18, 16, 14, 10, 15, 13, 8, 19, 12) > model <- lm(Note ~ Durée) I was ...
1 vote
0 answers
39 views

Forest function error - "argument 1 matches multiple formal arguments'

I created the following random-effects model, and am hoping to -for now anyway- generate a very basic forest plot, using the forest function from metafor. This is the code I used: `res <- rma(yi=...
  • 11
1 vote
0 answers
21 views

Power of Bernoulli likelihood in Jags (R2jags) [closed]

In a fixed power prior model, the model is set up as: $$ \pi(p_i \mid \alpha,\mathcal{D}_0) \propto L(p_i\mid \mathcal{D}_0)^{w} \pi(p_i) $$ Suppose that the event follows a Bernoulli distribution ...
0 votes
0 answers
14 views

Control for the effect of an outcome in proportion tests: a Bayesian case

I’m having some difficulties in data analysis plan for my research. I want to check if people do not have a preference between two objects. Therefore, I’m conducting a Bayesian binomial test. I choose ...
1 vote
1 answer
25 views

Cox PH model HR - is it possible to measure against the general average?

Reproducible example: ...
0 votes
1 answer
59 views

Comparing standardised values of microbial colony perimeters

I’m having a statistical problem (a rather major one) and I was wondering if you could help. I’m researching microbial chemotaxis and analysing colony perimeters by scanning their fluorescence. ...
0 votes
1 answer
64 views

Failing to find optimal linear fit in R with lm

I have three linear regression models in R: 1. lm(Y~X1) 2. lm(Y~X2) 3. lm(Y~X2+X3) Of note, in this data mathematically ...
  • 463
1 vote
2 answers
40 views

Multifractional polynomial with mixed-effects logistic model

Dataset I am working on a dataset collected from more than 20 hospitals. I used the glmer command to estimate a mixed-effects logistic regression model with the ...
2 votes
0 answers
35 views

Is survival analysis appropriate for forecasting time series data?

I have 32 months of historical data and I am testing forecasting methodologies. I assume that only 12 months of data are available, I forecast months 13-32, and then compare actuals for months 13-32 ...
1 vote
1 answer
33 views

ARIMA D coefficient for seasonality lesser than frequency

Lets suppose we have a time series with monthly data (frequency=12) my_tS <- ts(my_monthly_data, start=c(2002,1), frequency=12) When I plot it, I can see a ...
  • 115
2 votes
2 answers
40 views

Can I predict values from a multiple regression model with fewer predictors than there are in the model?

I have built a linear regression model with three predictor variables: the model predicts forest growth (y = stand volume) with stand age, stand basal area and site type (x1, x2 and x3 respectively). ...
  • 31
0 votes
0 answers
14 views

Can I use Dominance analysis (using r package domir for instance) with a negative binomial (nb.glm)?

I want to examine the relative importance of the predictors in my model. I know the domir package in R allows for the ...
  • 1
0 votes
0 answers
8 views

Not sure how to define effects in MEM in R

I have looked through all the online material about fixed vs random effects, and I have not been able to make head or tail of most of that which I have read. I am not a statistician, and unfortunately,...
2 votes
0 answers
16 views

If I use anova() in R to compare two nested models, do I get a one-sided or two-sided p-vlaue?

I'm running a likelihood ratio test to check whether or not a condition has a significant outcome for subjects performing an experiment, and I'm using lmer in R to do this. So I run something like <...
0 votes
0 answers
10 views

Panel data regression with time periods that are unaligned

I want to run a regression with panel data involving data from variables that are collected at different periods. Is there a way to do this, and if so, is it legitimate to do this or should panel data ...
0 votes
0 answers
10 views

R gamsel for generalized additive model - interpretation

I have set up a gamsel like this ( X has ~ 60 different independent variables). I am struggling to interpret the summary and plots: ...
user avatar
1 vote
1 answer
44 views

Using GAM Gaussian family to Examine Significance in Data Pattern Across Two Categorical Variables

I came across this post in using GAM with the default Gaussian family to examine the significant difference of the patterns across two categorical variables Statistical differences between two hourly ...
  • 159
0 votes
0 answers
18 views

What Bayesian priors are diffuse on the log scale?

I am trying to come up with priors for the intercept and coefficients of a Bayesian regression model on the log scale, but I can't get the resulting distribution of the prior to be diffuse once I log ...
1 vote
0 answers
15 views

Elbow plot and plot of average silhouette width disagree with each other

I am fairly new to using clustering. On the data science course I am on, we recently covered agglomerative clustering and k means clustering. I have created a toy example to see if I can use R to ...
0 votes
0 answers
40 views

Interpreting interaction coefficients from categorical predictors in lmer

I have 4 mixed effect models that I want to compare - each one has exactly the same structure but a different outcome variable (see summary plot below). I need a statitical test of whether the effects ...
  • 1
2 votes
1 answer
24 views

One-way ANOVA F-test is significant but none of the Tukey pairwise test is significant

I made up this example myself: Three geoscientists from China, USA and Europe were interested in exploring the mineralogical and textural characteristics and organic carbon composition of carbonate ...
  • 21
0 votes
0 answers
14 views

Does including random effects in CLMM alter the calculation of OR?

I'm having trouble using the output of a model to find OR and 95% CI. I've created two models. Model 1 has no random effects (clm) and model 2 includes random 1 random effect of participant ID ...
  • 1
0 votes
0 answers
68 views

Fitting multiple piecewise linear regression model (with hinges)

I am trying to fit a multiple piecewise linear regression model, where I coerce the model to have the exact terms I want. For example, let's say I want to fit the exact model below, with predictors $...
0 votes
0 answers
23 views

Find correlation between continuos predictive features and a continuos target feature

In my data, I have about 10K predictive features (genes), and one target feature (age). I want to predict the ages according to the genes. The rows in the data are the patients. To do so I plan to use ...
  • 413
1 vote
0 answers
56 views

Algorithm for Irwin Hall Distribution [closed]

I've been trying to create a function for the Irwin Hall distribution that doesn't face the same issue as the unifed package implementation. Because the function suffers from numerical issues, I ...
1 vote
0 answers
5 views

Modifying ordered factor estimates in linear model

My question starts on previous answered questions: https://stackoverflow.com/questions/25735636/interpretation-of-ordered-and-non-ordered-factors-vs-numerical-predictors-in-m/25736023#25736023 Results ...
  • 198
2 votes
1 answer
26 views

Why does the survival probability of the survival package return 0% at the end of the time horizon when there are survivors in the dataset?

I've just started using the survival and survminer packages in R and am trying to understand its output. In the code below I create a dataframe with the first 12 rows of my actual dataset, as ...
0 votes
0 answers
28 views

Interpreting multilevel random effects in R

I am conducting analyses on simple multilevel modeling. I have two data points that participants responded (within-person), and have conducted a simple multilevel model as the data points are nested ...
  • 1
0 votes
1 answer
41 views

Simulated data (with the outcome and predictors) from a GLM model

The goal of simulation is to produce a number of synthetic datasets, where the outcomes are a function of the known regression coefficients. I would like to know if my reasoning behind creating ...
0 votes
0 answers
9 views

How to provide data for the "PROX" argument in BayesSAE R-package (To Model the Spatial Fay Herriot SAE)

I am trying to apply Fay Herriot (FH) with Spatial structure (CAR=Conditional Auto Regression) using BayesSAE Package in R (here is the link to the package: https://cran.r-project.org/web/packages/...
0 votes
0 answers
4 views

σ (StD) value for the discretizeRaster parameter in R

I'm following this article to downscale a satellite image. I have several predictors to assist the downscalign. The first step is to resample the predictors to make them match the pixel size of the ...
  • 111
0 votes
1 answer
21 views

robust linear mixed model(rlmer): how to unpack the three-way interaction

I found a three-way interaction effect (each of the three factors has two levels) during a robust linear mixed model(RLMM). I'm wondering how to unpack this interaction. What I had done is: first ...
1 vote
1 answer
26 views

Non parametric 2 way anova

In my dataset, there are two distinct species, each with three unique treatments. My objective is to investigate whether there are any significant differences among the various species and treatments. ...
2 votes
2 answers
19 views

How do I force lavaan to use positive factor loadings for a latent construct?

I am looking for a way to force lavaan to use positive factor loadings in a latent construct. I am working on a sem defined as follows: ...
2 votes
1 answer
35 views

Calculating efficiency of rejection sampling

I have a joint distribution from which I want to simulate $f(x,y) = 2(1-x)(1-y)(1-xy)^{-3}, 0<x,y<1$. I have worked out that the marginal distributions are both $U(0,1)$, so I want to simulate ...
1 vote
0 answers
13 views

Split block design with crossed main effects and a random effect in R

I am having trouble specifying a model in lme4. Your help with be greatly appreciated!! And please let me know if I can improve how I ask this question. I am looking at the impact of light, ...
  • 11
0 votes
1 answer
49 views

Why is the order of factors (order of samples in dataset) affect PERMANOVA results with adonis2?

I am trying to run PERMANOVA tests on multiomics datasets collected from coral samples using adonis2 (v 2.6-5). I found when the order of samples in my dataset change, the pvalues change, sometimes ...
0 votes
0 answers
36 views

Weigthening social media sentiment scores

I struggle to understand how to implement a logical weighting of sentiment data. I predicted the sentiment for multiple Reddit comments. How can I weight them according to their scores? The problem is ...
  • 1
0 votes
1 answer
13 views

Efficient way to compare 2 similar datasets

I am a grad student who is fairly new to all of this. I have a matrix likert table that I was wanting to compare across 3 different relationships to the land. I got the means and standard error for ...
1 vote
1 answer
35 views

How to compare linear mixed models that do not satisfy the assumption of Gaussian errors?

I have fitted two linear mixed models, A and B, to a data set using lme4::lme: model ...
1 vote
0 answers
26 views

Gaussian Process posterior distribution

I'm trying to find a way to get the posterior covariance function for a mgcv::gam fit. Assuming I have a simple model y ~ s(x), ...
  • 41
0 votes
1 answer
43 views

Calculare Risk Ratio with CI in R from Odds ratios

I have performed a multiple logistic regression because I wanted to see the association between Death and Cardiovascular disease. I adjusted using age, sex, risk factors. The result came in ODDS RATIO ...
user avatar
0 votes
0 answers
21 views

Calculate percentual slope

I have the following dataframe (dput below): ...
  • 291
22 votes
3 answers
4k views

How to fix the problem in this XKCD comic?

Slope Hypothesis Testing (Randall Munroe, xkcd) The problem with this comic is obviously that the "measurements" are not independent, violating a key assumption for computing valid p-values....
  • 1,109

1
3 4
5
6 7
573