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
387 votes
12 answers
380k views

Difference between logit and probit models

What is the difference between Logit and Probit model? I'm more interested here in knowing when to use logistic regression, and when to use Probit. If there is any literature which defines it using ...
Beta's user avatar
  • 6,284
378 votes
26 answers
136k 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 ...
279 votes
2 answers
232k views

Interpretation of R's lm() output

The help pages in R assume I know what those numbers mean, but 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. ...
Alexander Engelhardt's user avatar
241 votes
4 answers
482k views

How to interpret a QQ plot?

I am working with a small dataset (21 observations) and have the following normal QQ plot in R: Seeing that the plot does not support normality, what could I infer about the underlying distribution? ...
JohnK's user avatar
  • 19.8k
225 votes
3 answers
177k 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 ...
207 votes
10 answers
227k 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: ...
user333's user avatar
  • 7,131
202 votes
3 answers
291k views

How to determine which distribution fits my data best?

I have a dataset and would like to figure out which distribution fits my data best. I used the fitdistr() function to estimate the necessary parameters to ...
tobibo's user avatar
  • 2,125
188 votes
9 answers
725k views

How to summarize data by group in R? [closed]

I have R data frame like this: ...
Yuriy Petrovskiy's user avatar
188 votes
2 answers
1.0m views

How do I get the number of rows of a data.frame in R? [closed]

After reading a dataset: dataset <- read.csv("forR.csv") How can I get R to give me the number of cases it contains? Also, will the returned value include of ...
Tom Wright's user avatar
  • 2,171
170 votes
3 answers
203k 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 ...
ako's user avatar
  • 1,803
169 votes
21 answers
69k views

Does Julia have any hope of sticking in the statistical community?

I recently read a post from R-Bloggers, that linked to this blog post from John Myles White about a new language called Julia. Julia takes advantage of a just-in-time compiler that gives it wicked ...
155 votes
25 answers
131k 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?
Benoit_Plante's user avatar
147 votes
3 answers
85k views

Removal of statistically significant intercept term increases $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$ ...
Ernest A's user avatar
  • 2,312
147 votes
6 answers
293k views

Correlations with unordered categorical variables

I have a dataframe with many observations and many variables. Some of them are categorical (unordered) and the others are numerical. I'm looking for associations between these variables. I've been ...
Clément F's user avatar
  • 1,777
114 votes
4 answers
222k views

What is rank deficiency, and how to deal with it?

Fitting a logistic regression using lme4 ends with Error in mer_finalize(ans) : Downdated X'X is not positive definite. A likely cause of this error is ...
Jack Tanner's user avatar
  • 4,772
109 votes
1 answer
69k views

Conditional inference trees vs traditional decision trees

Can anyone explain the primary differences between conditional inference trees (ctree from party package in R) compared to the ...
B_Miner's user avatar
  • 8,200
107 votes
9 answers
86k views

Generate a random variable with a defined correlation to an existing variable(s)

For a simulation study I have to generate random variables that show a predefined (population) correlation to an existing variable $Y$. I looked into the R ...
Felix S's user avatar
  • 4,650
105 votes
2 answers
66k views

How scared should we be about convergence warnings in lme4

If we a re fitting a glmer we may get a warning that tells us the model is finding a hard time to converge...e.g. ...
user1322296's user avatar
  • 1,605
102 votes
7 answers
178k views

Calculating the parameters of a Beta distribution using the mean and variance

How can I calculate the $\alpha$ and $\beta$ parameters for a Beta distribution if I know the mean and variance that I want the distribution to have? Examples of an R command to do this would be most ...
Dave Kincaid's user avatar
  • 1,658
102 votes
1 answer
89k 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 ...
Guest's user avatar
  • 1,021
99 votes
4 answers
62k 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 ...
Chris Beeley's user avatar
  • 5,681
96 votes
11 answers
254k views

How to obtain the p-value (check significance) of an effect in a lme4 mixed model?

I use lme4 in R to fit the mixed model lmer(value~status+(1|experiment))) where value is continuous, status and experiment are factors, and I get ...
ECII's user avatar
  • 2,141
93 votes
2 answers
50k views

Resampling / simulation methods: monte carlo, bootstrapping, jackknifing, cross-validation, randomization tests, and permutation tests

I am trying to understand difference between different resampling methods (Monte Carlo simulation, parametric bootstrapping, non-parametric bootstrapping, jackknifing, cross-validation, randomization ...
Ram Sharma's user avatar
  • 2,436
93 votes
5 answers
101k views

What do the residuals in a logistic regression mean?

In answering this question John Christie suggested that the fit of logistic regression models should be assessed by evaluating the residuals. I'm familiar with how to interpret residuals in OLS, they ...
russellpierce's user avatar
89 votes
3 answers
191k views

An example: LASSO regression using glmnet for binary outcome

I am starting to dabble with the use of glmnet with LASSO Regression where my outcome of interest is dichotomous. I have created a small mock data frame below: <...
Matt Reichenbach's user avatar
83 votes
1 answer
103k 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: ...
user avatar
82 votes
4 answers
56k 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 – ...
hans0l0's user avatar
  • 2,125
81 votes
2 answers
78k views

Multivariate multiple regression in R

I have 2 dependent variables (DVs) each of whose score may be influenced by the set of 7 independent variables (IVs). DVs are continuous, while the set of IVs consists of a mix of continuous and ...
Andrej's user avatar
  • 2,213
81 votes
3 answers
66k views

Best way to present a random forest in a publication?

I am using the random forest algorithm as a robust classifier of two groups in a microarray study with 1000s of features. What is the best way to present the random forest so that there is enough ...
danielsbrewer's user avatar
80 votes
1 answer
77k views

Understanding ROC curve

I'm having trouble understanding the ROC curve. Is there any advantage / improvement in area under the ROC curve if I build different models from each unique subset of the training set and use it to ...
Tay Shin's user avatar
  • 1,005
80 votes
4 answers
26k 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 ...
gisol's user avatar
  • 983
78 votes
21 answers
49k views

Free resources for learning R

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

How should tiny $p$-values be reported? (and why does R put a minimum on 2.22e-16?)

For some tests in R, there is a lower limit on the p-value calculations of $2.22 \cdot 10^{-16}$. I'm not sure why it's this number, if there is a good reason for ...
paul's user avatar
  • 1,382
75 votes
6 answers
73k views

Do the predictions of a Random Forest model have a prediction interval?

If I run a randomForest model, I can then make predictions based on the model. Is there a way to get a prediction interval of each of the predictions such that I ...
Dean MacGregor's user avatar
74 votes
6 answers
198k 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: ...
robintw's user avatar
  • 2,107
73 votes
15 answers
129k views

Good GUI for R suitable for a beginner wanting to learn programming in R?

Is there any GUI for R that makes it easier for a beginner to start learning and programming in that language?
73 votes
3 answers
168k views

How to actually plot a sample tree from randomForest::getTree()? [closed]

Anyone got library or code suggestions on how to actually plot a couple of sample trees from: getTree(rfobj, k, labelVar=TRUE) (Yes I know you're not supposed ...
smci's user avatar
  • 1,472
73 votes
15 answers
5k views

Complete substantive examples of reproducible research using R

The Question: Are there any good examples of reproducible research using R that are freely available online? Ideal Example: Specifically, ideal examples would provide: The raw data (and ideally meta ...
72 votes
8 answers
59k views

Is PCA followed by a rotation (such as varimax) still PCA?

I have tried to reproduce some research (using PCA) from SPSS in R. In my experience, principal() function from package psych ...
Roman Luštrik's user avatar
72 votes
8 answers
120k 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 ...
Jeromy Anglim's user avatar
71 votes
2 answers
473k views

Removing duplicated rows data frame in R [closed]

How can I remove duplicate rows from this example data frame? A 1 A 1 A 2 B 4 B 1 B 1 C 2 C 2 I would like to remove the duplicates based on ...
Jana's user avatar
  • 969
70 votes
2 answers
58k views

How to interpret type I, type II, and type III 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 ...
djhocking's user avatar
  • 1,901
70 votes
6 answers
166k views

Warning in R - Chi-squared approximation may be incorrect

I have data showing fire fighter entrance exam results. I am testing the hypothesis that exam results and ethnicity are not mutually independent. To test this, I ran a Pearson chi-square test in R. ...
ferrelwill's user avatar
69 votes
6 answers
18k views

Standard errors for lasso prediction using R

I'm trying to use a LASSO model for prediction, and I need to estimate standard errors. Surely someone has already written a package to do this. But as far as I can see, none of the packages on CRAN ...
Rob Hyndman's user avatar
68 votes
3 answers
136k views

Questions about how random effects are specified in lmer

I recently measured how the meaning of a new word is acquired over repeated exposures (practice: day 1 to day 10) by measuring ERPs (EEGs) when the word was viewed in different contexts. I also ...
alwin hoff's user avatar
66 votes
8 answers
19k views

Is the R language reliable for the field of economics?

I am a graduate student in economics who recently converted to R from other very well-known statistical packages (I was using SPSS mainly). My little problem at the moment is that I am the only R user ...
SavedByJESUS's user avatar
  • 1,223
64 votes
5 answers
5k views

Why does collecting data until finding a significant result increase Type I error rate?

I was wondering exactly why collecting data until a significant result (e.g., $p \lt .05$) is obtained (i.e., p-hacking) increases the Type I error rate? I would also highly appreciate an ...
Reza's user avatar
  • 926
64 votes
7 answers
53k 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. (...
Henrik's user avatar
  • 14k
64 votes
5 answers
132k 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: ...
dfrankow's user avatar
  • 3,336
63 votes
1 answer
21k views

Logistic regression in R resulted in perfect separation (Hauck-Donner phenomenon). Now what? [duplicate]

I'm trying to predict a binary outcome using 50 continuous explanatory variables (the range of most of the variables is $-\infty$ to $\infty$). My data set has almost 24,000 rows. When I run ...
Dcook's user avatar
  • 763

1
2 3 4 5
590