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 program in `R`.

learn more… | top users | synonyms

97
votes
6answers
70k views

Difference between logit and probit models

What is the difference between the logit and the probit model? I'm more interested here in knowing when to use logistic regression, and when to use probit. If there's any literature which define it ...
83
votes
1answer
37k views

Interpretation of R's lm() output

the help pages in R assume I know what those numbers mean. I don't :) I'm trying to really intuitively understand every number here. I will just post the output and comment on what I found out. There ...
33
votes
4answers
11k views

How to deal with perfect separation in logistic regression?

If you have a variable which perfectly separates zeroes and ones in target variable, R will yield the following "perfect or quasi perfect separation" warning message: ...
16
votes
2answers
3k views

Simulation of logistic regression power analysis - designed experiments

This question is in response to an answer given by @Greg Snow in regards to a question I asked concerning power analysis with logistic regression and SAS ...
35
votes
7answers
14k views

When is it ok to remove the intercept in lm()?

I am running linear regression models and wondering what the conditions are for removing the intercept term of lm()? In comparing results from two different lm ...
8
votes
1answer
5k views

How to interpret type I (sequential) ANOVA and MANOVA?

My primary question is how to interpret the output (coefficients, F, P) when conducting a Type I (sequential) ANOVA? My specific research problem is a bit more complex, so I will break my example into ...
51
votes
1answer
8k views

R's lmer cheat-sheet

There's a lot of discussion going on on this forum about the proper way to specify various hierarchical models using lmer. I thought it would be great to have all ...
9
votes
4answers
2k views

Obtaining a formula for prediction limits in a linear model

Let's take the following example: set.seed(342) x1 <- runif(100) x2 <- runif(100) y <- x1+x2 + 2*x1*x2 + rnorm(100) fit <- lm(y~x1*x2) This creates a ...
68
votes
21answers
16k views

Resources for learning R [duplicate]

I'm interested in learning R on the cheap. What's the best free resource/book/tutorial for learning R?
12
votes
2answers
2k views

What distribution does my data follow?

Let us say that I have 1000 components and I have been collecting data on how many times these log a failure and each time they logged a failure, I am also keeping track of how long it took my team to ...
33
votes
1answer
9k views

Removal of statistically significant intercept term boosts $R^2$ in linear model

In a simple linear model with a single explanatory variable, $\alpha_i = \beta_0 + \beta_1 \delta_i + \epsilon_i$ I find that removing the intercept term improves the fit greatly (value of $R^2$ ...
11
votes
2answers
4k views

How to find a good fit for semi-sinusoidal model in R?

I want to assume that the sea surface temperature of the Baltic Sea is the same year after year, and then describe that with a function / linear model. The idea I had was to just input year as a ...
9
votes
1answer
1k views

Alternatives to one-way ANOVA for heteroskedastic data

I have data from 3 groups of algae biomass ($A$, $B$, $C$) which contain unequal sample sizes ($n_A=15$, $n_B=13$, $n_C=12$) and I would like compare if these groups are from the same population. ...
29
votes
1answer
13k views

How to interpret coefficients in a Poisson regression?

How can I interpret the main effects (coefficients for dummy-coded factor) in a Poisson regression? Assume the following example: ...
31
votes
5answers
11k views

Which permutation test implementation in R to use instead of t-tests (paired and non-paired)?

I have data from an experiment that I analyzed using t-tests. The dependent variable is interval scaled and the data are either unpaired (i.e., 2 groups) or paired (i.e., within-subjects). E.g. ...
27
votes
3answers
5k views

Box-Cox like transformation for independent variables?

Is there a Box-Cox like transformation for independent variables? That is, a transformation that optimizes the $x$ variable so that the y~f(x) will make a more ...
3
votes
3answers
2k views

Continuous dependent variable with ordinal independent variable

Given a continuous dependent variable y and independent variables including an ordinal variable X1, how do I fit a linear model in R? Are there papers about this ...
202
votes
21answers
66k views

Python as a statistics workbench

Lots of people use a main tool like Excel or another spreadsheet, SPSS, Stata, or R for their statistics needs. They might turn to some specific package for very special needs, but a lot of things can ...
7
votes
2answers
6k views

Using principal component analysis (PCA) for feature selection

I'm new to feature selection and I was wondering how you would use PCA to perform feature selection. Does PCA compute a relative score for each input variable that you can use to filter out ...
27
votes
2answers
18k views

How are the standard errors of coefficients calculated in a regression?

For my own understanding, I am interested in manually replicating the calculation of the standard errors of estimated coefficients as, for example, come with the output of the ...
11
votes
2answers
5k views

Why do lme and aov return different results for repeated measures ANOVA in R?

I am trying to move from using the ez package to lme for repeated measures ANOVA (as I hope I will be able to use custom ...
25
votes
7answers
4k views

How can I efficiently model the sum of Bernoulli random variables?

I am modeling a random variable ($Y$) which is the sum of some ~15-40k independent Bernoulli random variables ($X_i$), each with a different success probability ($p_i$). Formally, $Y=\sum X_i$ where ...
20
votes
4answers
2k views

Good methods for density plots of non-negative variables in R?

plot(density(rexp(100)) Obviously all density to the left of zero represents bias. I'm looking to summarize some data for non-statisticians, and I want to avoid ...
12
votes
2answers
1k views

I'm getting “jumpy” loadings in rollapply PCA in R. Can I fix it?

I have 10 years of daily returns data for 28 different currencies. I wish to extract the first principal component, but rather than operate PCA on the whole 10 years, I want to rollapply a 2 year ...
19
votes
1answer
7k views

Interpreting plot.lm()

I had a question about interpreting the graphs generated by plot(lm) in R. I was wondering if you guys could tell me how to interpret the scale-location and leverage-residual plots? Any comments would ...
22
votes
5answers
9k views

Generate a random variable with a defined correlation to an existing variable

For a simulation study I have to generate random variables that show a prefined (population) correlation to an existing variable $Y$. I looked into the R packages ...
9
votes
1answer
4k views

Cross-correlation significance in R

How do you tell if the correlations at different lags obtained from the cross-correlation (ccf function) of two time series are significant.
43
votes
4answers
17k views

How to choose nlme or lme4 R library for mixed effects models?

I have fit a few mixed effects models (particularly longitudinal models) using lme4 in R but would like to really master the ...
14
votes
5answers
7k views

Post-hocs for within subjects tests?

What is the preferred method for for conducting post-hocs for within subjects tests? I've seen published work where Tukey's HSD is employed but a review of Keppel and Maxwell & Delaney suggests ...
24
votes
1answer
2k views

Logistic regression in R resulted in Hauck Donner phenomenon. Now what?

I'm trying to predict a binary outcome using 50 continuous explanatory variables (the range of most of the variables is -∞ to ∞). My data set has almost 24,000 rows. When I run glm in R, I get: ...
13
votes
1answer
10k views

Post hoc test after ANOVA with repeated measures using R

I have performed a repeated measures ANOVA in R, as follows: aov_velocity = aov(Velocity ~ Material + Error(Subject/(Material)), data=scrd) summary(aov_velocity) ...
12
votes
2answers
8k views

Transforming variables for multiple regression in R

I am trying to perform a multiple regression in R. However, my dependent variable has the following plot: Here is a scatterplot matrix with all my variables ...
14
votes
4answers
5k views

is psych::principal function still PCA when using rotation?

I have tried to reproduce some research (using PCA) from SPSS in R. In my experience, principal() function from package psych ...
13
votes
5answers
2k views

Time taken to hit a pattern of heads and tails in a series of coin-tosses

Inspired by Peter Donnelly's talk at TED, in which he discusses how long it would take for a certain pattern to appear in a series of coin tosses, I created the following script in R. Given two ...
7
votes
1answer
17k 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: ...
10
votes
1answer
5k views

How to simulate artificial data for logistic regression?

I know I'm missing something in my understanding of logistic regression, and would really appreciate any help. As far as I understand it, the logistic regression assumes that the probability of a '1' ...
5
votes
3answers
825 views

Log or square-root transformation for ARIMA

With the below dataset, I have a series which needs transforming. Easy enough. However, how do you decide which of the SQRT or LOG transformations is better? And how do you draw that conclusion? ...
7
votes
1answer
4k views

Wald test in regression (OLS and GLMs): t- vs. z-distribution

I understand that the Wald test for regression coefficients is based on the following property that holds asymptotically (e.g. Wasserman (2006): All of Statistics, pages 153, 214-215): $$ ...
16
votes
4answers
8k 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 ...
7
votes
2answers
1k views

dispersion in summary.glm()

I conducted a glm.nb by glm1<-glm.nb(x~factor(group)) with group being a categorial and x being a metrical variable. When I try to get the summary of the ...
5
votes
1answer
2k views

Can the scaling values in a linear discriminant analysis (LDA) be used to plot explanatory variables on the linear discriminants?

Using a biplot of values obtained through principal component analysis, it is possible to explore the explanatory variables that make up each principle component. Is this also possible with Linear ...
3
votes
4answers
267 views

r sequence recognition for univariate data sequence mining

I am looking for a method to detect sequences within univariate discrete data without specifying the length of the sequence or the exact nature of the sequence beforehand (see e.g. Wikipedia - ...
4
votes
2answers
5k views

Test a significant difference between two slope values

The data I have are a regression slope value of y~time, a standard error, an n value and a p value, for a particular species in two different areas. I want to check whether the the regression slope ...
74
votes
21answers
38k views

R vs SAS, why is SAS preferred by private companies?

I learned R but it seems that companies are much more interested in SAS experience. What are the advantages of SAS over R?
28
votes
3answers
5k 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 ...
27
votes
3answers
3k views

Why does including latitude and longitude in a GAM account for spatial autocorrelation?

I have produced generalized additive models for deforestation. To account for spatial-autocorrelation, I have included latitude and longitude as a smoothed, interaction term (i.e. s(x,y)). I've based ...
6
votes
2answers
17k views

How to statistically compare two time series?

I have two time series, shown in the plot below: The plot is showing the full detail of both time series, but I can easily reduce it to just the coincident observations if needed. My question is: ...
10
votes
4answers
8k views

A non-parametric repeated-measures multi-way Anova in R?

The following question is one of those holy grails for me for some time now, I hope someone might be able to offer a good advice. I wish to perform a non-parametric repeated measures multiway anova ...
15
votes
4answers
10k views

How to simulate data that satisfy specific constraints such as having specific mean and standard deviation?

This question is motivated by my question on meta-analysis. But I imagine that it would also be useful in teaching contexts where you want to create a dataset that exactly mirrors an existing ...
5
votes
5answers
891 views

Where can I find useful R tutorials with various implementations?

I'm using R and the manuals on the R site are really informative. However, I'd like to see some more examples and implementations with R which can help me develop my knowledge faster. Any suggestions? ...