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
52
votes
3answers
25k views

Is it possible to do time-series clustering based on curve shape?

I have sales data for a series of outlets, and want to categorise them based on the shape of their curves over time. The data looks roughly like this (but obviously isn't random, and has some missing ...
55
votes
6answers
66k views

How to determine best cutoff point and its confidence interval using ROC curve in R?

I have the data of a test that could be used to distinguish normal and tumor cells. According to ROC curve it looks good for this purpose (area under curve is 0.9): My questions are: How to ...
75
votes
4answers
46k views

What is the difference between R functions prcomp and princomp?

I compared ?prcomp and ?princomp and found something about Q-mode and R-mode principal component analysis (PCA). But honestly – ...
55
votes
5answers
96k views

How to calculate pseudo-$R^2$ from R's logistic regression?

Christopher Manning's writeup on logistic regression in R shows a logistic regression in R as follows: ...
31
votes
3answers
90k views

How to know if a time series is stationary or non-stationary?

I am using R, I searched on Google and learnt that kpss.test(), PP.test(), and adf.test() ...
32
votes
2answers
83k views

Interpretation of biplots in principal components analysis

I came across this nice tutorial: A Handbook of Statistical Analyses Using R. Chapter 13. Principal Component Analysis: The Olympic Heptathlon on how to do PCA in R language. I don't understand the ...
50
votes
3answers
64k views

Is there any difference between lm and glm for the gaussian family of glm?

Specifically, I want to know if there is a difference between lm(y ~ x1 + x2) and glm(y ~ x1 + x2, family=gaussian). I think ...
25
votes
3answers
55k views

Choice between Type-I, Type-II, or Type-III ANOVA [duplicate]

We have a dataset with three variables (dV: self-reported measure on scale 1-5, assumed to be metric; iV1: factor with 4 levels; iV2: factor with 8 levels). We are interested whether the dV differs in ...
42
votes
2answers
47k views

What is quasi-binomial distribution (in the context of GLM)?

I'm hoping someone can provide an intuitive overview of what quasibinomial distribution is and what it does. I'm particularly interested in these points: How quasibinomial differs to the binomial ...
19
votes
4answers
26k views

Visualizing Likert responses using R or SPSS

I have 82 respondents in 2 groups (43 in Group A and 39 in Group B) that completed a survey of 65 Likert questions each ranging from 1 – 5 (strongly agree - strongly disagree). I therefore have a ...
42
votes
5answers
32k views

Confidence interval for median

I have to find a 95% C.I. on the median and other percentiles. I don't know how to approach this. I mainly use R as a programming tool.
22
votes
2answers
40k views

How to interpret parameters in GLM with family=Gamma

I have a question regarding parameter interpretation for a GLM with a gamma distributed dependent variable. This is what R returns for my GLM with a log-link: ...
12
votes
2answers
16k views

Interpreting a logistic regression model with multiple predictors

I performed multivariate logistic regression with the dependent variable Y being death at a nursing home within a certain period of entry and got the following ...
24
votes
3answers
28k views

Regression vs. ANOVA discrepancy (aov vs lm in R)

I was always under the impression that regression is just a more general form of ANOVA and that the results would be identical. Recently, however, I have run both a regression and an ANOVA on the same ...
31
votes
1answer
50k views

predict() Function for lmer Mixed Effects Models

The problem: I have read in other posts that predict is not available for mixed effects lmer {lme4} models in [R]. I tried ...
26
votes
3answers
28k views

Sample size calculation for mixed models

I am wondering if there are any methods for calculating sample size in mixed models? I'm using lmer in R to fit the models (I have random slopes and intercepts).
19
votes
1answer
13k views

Understanding the variance of random effects in lmer() models

I'm having trouble understanding the output of my lmer() model. It is a simple model of an outcome variable (Support) with varying State intercepts / State random ...
42
votes
2answers
29k views

Understanding the parameters inside the Negative Binomial Distribution

I was trying to fit my data into various models and figured out that the fitdistr function from library MASS of ...
25
votes
1answer
70k views

Comparing levels of factors after a GLM in R

Here is a little background about my situation: my data refer to the number of prey successfully eaten by a predator. As the number of prey is limited (25 available) in each trial, I had a column "...
23
votes
1answer
26k views

Why do the R functions 'princomp' and 'prcomp' give different eigenvalues?

You can use the decathlon dataset {FactoMineR} to reproduce this. The question is why the computed eigenvalues differ from those of the covariance matrix. Here are the eigenvalues using ...
24
votes
1answer
34k views

In R, given an output from optim with a hessian matrix, how to calculate parameter confidence intervals using the hessian matrix?

Given an output from optim with a hessian matrix, how to calculate parameter confidence intervals using the hessian matrix? ...
22
votes
9answers
9k views

Time series for count data, with counts < 20

I recently started working for a tuberculosis clinic. We meet periodically to discuss the number of TB cases we're currently treating, the number of tests administered, etc. I'd like to start ...
22
votes
2answers
14k views

Paired t-test as a special case of linear mixed-effect modeling

We know that a paired t-test is just a special case of one-way repeated-measures (or within-subject) ANOVA as well as linear mixed-effect model, which can be demonstrated with lme() function the nlme ...
29
votes
1answer
41k views

What is an acceptable value of the Calinski & Harabasz (CH) criterion?

I have done a data analysis trying to cluster longitudinal data using R and the kml package. My data contains of around 400 individual trajectories (as it is called in the paper). You can see my ...
18
votes
2answers
29k views

How to plot an ellipse from eigenvalues and eigenvectors in R?

Could someone come up with R code to plot an ellipse from the eigenvalues and the eigenvectors of the following matrix $$ \mathbf{A} = \left( \begin{array} {cc} 2.2 & 0.4\\ 0.4 & 2.8 \end{...
30
votes
3answers
79k views

How to calculate goodness of fit in glm (R)

I have the following result from running glm function. How can I interpret the following values: Null deviance Residual deviance AIC Do they have something to do with the goodness of fit? Can I ...
28
votes
4answers
102k views

How to test the autocorrelation of the residuals?

I have a matrix with two columns that have many prices (750). In the image below I plotted the residuals of the follow linear regression: ...
24
votes
2answers
12k views

What is “baseline” in precision recall curve

I'm trying to understand precision recall curve, I understand what precision and recall are but the thing I don't understand is the "baseline" value. I was reading this link https://classeval....
19
votes
3answers
16k 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 ...
27
votes
7answers
41k views

How does one do a Type-III SS ANOVA in R with contrast codes?

Please provide R code which allows one to conduct a between-subjects ANOVA with -3, -1, 1, 3 contrasts. I understand there is a debate regarding the appropriate Sum of Squares (SS) type for such an ...
24
votes
1answer
10k views

Why is the quasi-Poisson in GLM not treated as a special case of negative binomial?

I'm trying to fit generalized linear models to some sets of count data that might or might not be overdispersed. The two canonical distributions that apply here are the Poisson and Negative Binomial (...
13
votes
4answers
5k views

What to make of explanatories in time series?

Having worked mostly with cross sectional data so far and very very recently browsing, scanning stumbling through a bunch of introductory time series literature I wonder what which role explanatory ...
7
votes
1answer
5k views

Goodness of fit test for a mixture in R

I just estimated the parameters for a mixture of two gaussians with different means and different sigmas, I would like to test if the data adjusts well to the explicit form of the mixture, do I ...
17
votes
2answers
5k views

Alternative to sieve / mosaic plots for contingency tables

I once stumbled across a type of plot for categorical data (i.e., contingency tables) on the internet, which I really liked, but I've never found it again, and I don't even know what it's called. It ...
7
votes
1answer
1k views

Can I replace NAs based on response variable?

My data consists of 1 response variable 'Age' and 1 feature (beta). The feature contains some missing values (NA) so I want to replace them. I've been replacing them with the median of the feature. ...
22
votes
3answers
20k views

How to present box plot with an extreme outlier?

I could use some guidance about presenting some data. This first plot is a case-control comparison for the cytokine IL-10. I've manually set the y axis to include 99% of the data. The reason I set ...
11
votes
1answer
5k views

How to perform a 4 by 4 mixed ANOVA with between- and within-subjects contrasts using R?

Beginner user of R here struggling with a repeated measures ANOVA. I have a dataset that consists of one between subjects factor with 4 levels (coded in a single variable called 'groups'), and one ...
8
votes
2answers
2k views

Equivalent to Welch's t-test in GLS framework

How can Welch's t-test be expressed as a generalized least squares model? A standard independent samples t-test (where it is assumed that the samples being compared are drawn from populations with ...
8
votes
2answers
2k views

Repeated measures ANOVA vs. factorial ANOVA with subject factor: understanding “error strata” and Error() term in aov

Consider repeated measures ANOVA (RM-ANOVA) with one within-subject factor A and several measurements per subject for each level of ...
1
vote
2answers
3k views

Which model should I use to fit my data ? ordinal and non-ordinal, not normal and not homoscedastic

Here is the kind of data I have: I have two predictor variables: 1) discrete non-ordinal --> c('a','b','c') 2) discrete ordinal --> c(10,100,200,500) Response variable: Proportion of TRUE over a ...
12
votes
1answer
11k views

Comparing mixed-effects and fixed-effects models (testing significance of random effects)

Given three variables, y and x, which are positive continuous, and z, which is categorical, ...
18
votes
4answers
25k views

Fitting t-distribution in R: scaling parameter

How do I fit the parameters of a t-distribution, i.e. the parameters corresponding to the 'mean' and 'standard deviation' of a normal distribution. I assume they are called 'mean' and 'scaling/degrees ...
12
votes
1answer
28k views

Graphing a Probability Curve for a Logit Model With Multiple Predictors

I have the following probability function: $$\text{Prob} = \frac{1}{1 + e^{-z}}$$ where $$z = B_0 + B_1X_1 + \dots + B_nX_n.$$ My model looks like $$\Pr(Y=1) = \frac{1}{1 + \exp\left(-[-3.92 + 0....
5
votes
1answer
3k views

Remove effect of a factor on continuous proportion data using regression in R

I have a data set of continuous proportions which depend on a fixed-effect factor, e.g.: ...
7
votes
1answer
15k views

VIF for generalized linear model

Is the variance inflation factor useful for GLM models. Below example shows OLS is showing VIF>5, but GLM lower. GLM shows instability in the coefficients between train and test set. ...
2
votes
2answers
1k views

Get quantile function of dynamic mixture model

I have a dynamic mixture distribution fitted to my risk data (i.e., I have all parameters) of Weibull and Generalized Pareto, with a Cauchy CDF mixing function, that can be written as: \begin{align} ...
6
votes
3answers
6k views

Linear Regression with individual constraints in R

I am using the nnls() function from the nnls package in R to do a linear regression for regressors $x_i$ and observations $y$. ...
8
votes
1answer
772 views

Using proper scoring rule to determine class membership from logistic regression

I am using logistic regression to predict likelihood of an event occurring. Ultimately, these probabilities are put into a production environment, where we focus as much as possible on hitting our "...
3
votes
3answers
1k views

Interesting Logistic Regression Idea - Problem: Data not currently in 0/1 form. Any solutions?

I am attempting to conduct a logistic regression for a tennis analytics project, endeavoring to predict the probability of a player winning a point in which he is the server. My response variable (...
2
votes
2answers
2k views

Does this Q-Q plot indicates leptokurtic or platykurtic distribution?

The points have shown a "hump" pattern but I can't really identify that is it a narrow hump or wide hump?

1
3 4
5
6 7
74