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
82
votes
7answers
137k 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 ...
54
votes
4answers
118k 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: ...
26
votes
3answers
25k views

Interpreting plot of residuals vs. fitted values from Poisson regression

I am trying to fit data with a GLM (poisson regression) in R. When I plotted the residuals vs the fitted values, the plot created multiple (almost linear with a slight concave curve) "lines". What ...
28
votes
2answers
83k 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 (...
19
votes
3answers
55k 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 ...
26
votes
3answers
57k 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) ...
18
votes
1answer
27k views

R package for Weighted Random Forest? classwt option?

I'm trying to use Random Forest to predict the outcome of an extremely imbalanced data set (the minority class rate is about only 1% or even less). Because the traditional Random Forest algorithm ...
37
votes
4answers
14k views

Why does logistic regression become unstable when classes are well-separated?

Why is it that logistic regression becomes unstable when classes are well-separated? What does well-separated classes mean? I would really appreciate if someone can explain with an example.
78
votes
21answers
45k 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?
75
votes
2answers
70k 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 ...
33
votes
3answers
47k views

Which variance inflation factor should I be using: $\text{GVIF}$ or $\text{GVIF}^{1/(2\cdot\text{df})}$?

I'm trying to interpret variance inflation factors using the vif function in the R package car. The function prints both a ...
33
votes
2answers
30k views

How to use both binary and continuous variables together in clustering?

I need to use binary variables (values 0 & 1) in k-means. But k-means only works with continuous variables. I know some people still use these binary variables in k-means ignoring the fact that k-...
48
votes
2answers
48k 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' ...
28
votes
4answers
50k views

Generating random variables from a mixture of Normal distributions

How can I sample from a mixture distribution, and in particular a mixture of Normal distributions in R? For example, if I wanted to sample from: $$ 0.3\!\times\...
27
votes
1answer
5k views

“Kernel density estimation” is a convolution of what?

I am trying to get a better understanding of kernel density estimation. Using the definition from Wikipedia: https://en.wikipedia.org/wiki/Kernel_density_estimation#Definition $ \hat{f_h}(x) = \...
26
votes
7answers
23k views

Estimating a distribution based on three percentiles

What methods can I use to infer a distribution if I know only three percentiles? For example, I know that in a certain data set, the fifth percentile is 8,135, the 50th percentile is 11,259, and the ...
7
votes
2answers
5k views

How to use boxplots to find the point where values are more likely to come from different conditions?

I have plotted some data using box plots. I am comparing Condition 1 (left) and Condition 2 (Right) values. My aim is to find a point at which we make a decision where the value changes from point ...
4
votes
1answer
4k views

Canonical Correlation analysis without raw data (algebra of CCA)

I want to run a Canonical Correlation (in R) but I don't have the original (raw) data. I have only the correlation matrix of all the variables. I have seen some ...
373
votes
26answers
133k 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 ...
45
votes
2answers
104k views

Interpretation of R's output for binomial regression

I'm quite new on this with binomial data tests, but needed to do one and now I´m not sure how to interpret the outcome. The y-variable, the response variable, is binomial and the explanatory factors ...
60
votes
6answers
46k 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. (...
29
votes
3answers
23k views

How to do logistic regression in R when outcome is fractional (a ratio of two counts)?

I'm reviewing a paper which has the following biological experiment. A device is used to expose cells to varying amounts of fluid shear stress. As greater shear stress is applied to the cells, more of ...
18
votes
2answers
20k views

Qualitative variable coding in regression leads to “singularities”

I have an independent variable called "quality"; this variable has 3 modalities of response (bad quality; medium quality; high quality). I want to introduce this independent variable into my multiple ...
13
votes
3answers
8k views

What to do with random effects correlation that equals 1 or -1?

Not so uncommon occurrence when dealing with complex maximal mixed models (estimating all possible random effects for given data and model) is perfect (+1 or -1) or nearly perfect correlation among ...
25
votes
1answer
44k views

What is the non-parametric equivalent of a two-way ANOVA that can include interactions?

Hi I am trying to find the non-parametric equivalent of a two-way ANOVA (3x4 design) which is capable of including interactions. From my reading in Zar 1984 "Biostatistical analysis" this is possible ...
16
votes
1answer
2k views

I have a line of best fit. I need data points that will not change my line of best fit

I'm giving a presentation about fitting lines. I have a simple linear function, $y=1x+b$. I'm trying to get scattered data points that I can put in a scatter plot that will keep my line of best fit ...
9
votes
2answers
2k views

Risk of extinction of Schrödinger's cats

I am interested in how uncertainty can be accounted for when considering the risk of extinction of a species. Forgive me for extending a rather tired thought experiment, but at least it's familiar ...
7
votes
3answers
19k 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? <...
6
votes
7answers
23k views

Looking for function to fit sigmoid-like curve

I'm looking for a function to fit sigmoid-like curves, from experimental data points. The model (the function) doesn't matter, it doesn't have to be physically relevant, I just want to be able to ...
52
votes
1answer
57k views

Obtaining predicted values (Y=1 or 0) from a logistic regression model fit

Let's say that I have an object of class glm (corresponding to a logistic regression model) and I'd like to turn the predicted probabilities given by ...
58
votes
4answers
35k views

Choosing between LM and GLM for a log-transformed response variable

I'm trying to understand the philosophy behind using a Generalized Linear Model (GLM) vs a Linear Model (LM). I've created an example data set below where: $$\log(y) = x + \varepsilon $$ The ...
48
votes
2answers
130k views

Logistic regression model does not converge

I've got some data about airline flights (in a data frame called flights) and I would like to see if the flight time has any effect on the probability of a ...
24
votes
2answers
13k views

Polynomial contrasts for regression

I cannot understand the usage of polynomial contrasts in regression fitting. In particular, I am referring to an encoding used by R in order to express an interval ...
32
votes
3answers
12k views

Visualizing a million, PCA edition

Is it possible to visualize the output of Principal Component Analysis in ways that give more insight than just summary tables? Is it possible to do it when the number of observations is large, say ~...
28
votes
6answers
46k views

Fit a sinusoidal term to data

Although I read this post, I still have no idea how to apply this to my own data and hope that someone can help me out. I have the following data: ...
29
votes
2answers
59k views

Dealing with singular fit in mixed models

Let's say we have a model ...
40
votes
2answers
50k views

Test for bimodal distribution

I wonder if there is any statistical test to "test" the significance of a bimodal distribution. I mean, How much my data meets the bimodal distribution or not? If so, is there any test in the R ...
16
votes
2answers
30k views

Estimate ARMA coefficients through ACF and PACF inspection

How do you estimate the appropriate forecast model for a time series by visual inspection of the ACF and PACF plots? Which one (i.e., ACF or PACF) tells the AR or the MA (or do they both)? Which part ...
15
votes
2answers
56k views

Understanding dummy (manual or automated) variable creation in GLM

If a factor variable (e.g. gender with levels M and F) is used in the glm formula, dummy variable(s) are created, and can be found in the glm model summary along with their associated coefficients (e....
11
votes
5answers
6k views

Fitting SIR model with 2019-nCoV data doesn't conververge

I am trying to calculate the basic reproduction number $R_0$ of the new 2019-nCoV virus by fitting a SIR model to the current data. My code is based on https://arxiv.org/pdf/1605.01931.pdf, p. 11ff: <...
3
votes
3answers
6k views

Dealing with new Factor Levels in a Regression in R

I originally posted this in stackoverflow (as given here) but was told to try here since it might be more relevant here. I am very new to statistics and R in general so my question might be a bit dumb,...
40
votes
2answers
62k views

Mixed Effects Model with Nesting

I have data collected from an experiment organized as follows: Two sites, each with 30 trees. 15 are treated, 15 are control at each site. From each tree, we sample three pieces of the stem, and ...
27
votes
3answers
51k views

Interpreting interaction terms in logit regression with categorical variables

I have data from a survey experiment in which respondents were randomly assigned to one of four groups: ...
26
votes
2answers
24k views

Why do I get zero variance of a random effect in my mixed model, despite some variation in the data?

We’ve run a mixed effects logistic regression using the following syntax; ...
4
votes
2answers
14k views

Backward selection for Cox model using R

I want to perform an exploratory Cox regression analysis of medical data using R. I am practicing using the pbc data from the survival function. Would you recommend performing a backward selection ...
25
votes
3answers
7k views

Generating correlated binomial random variables

I was wondering if it might be possible to generate correlated random binomial variables following a linear transformation approach? Below, I tried something simple in ...
17
votes
5answers
3k views

Generate normally distributed random numbers with non positive-definite covariance matrix

I estimated the sample covariance matrix $C$ of a sample and get a symmetric matrix. With $C$, I would like to create $n$-variate normal distributed r.n. but therefore I need the Cholesky ...
14
votes
2answers
15k 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.
4
votes
1answer
3k views

ARMA/GARCH estimation in sequence

I have a time series that shows a nonstationary seasonal autoregressive component as well as known heteroshedasticity. In order to model the series, I have fit a seasonal ARIMA model for the mean with ...
4
votes
1answer
2k views

How can logistic regression have a factorial predictor and no intercept?

I tried a regression in the form ${\rm logit}(Y) = {\rm coefficient}\times X + 0 + e$, where $Y$ is a binomial variable and $X$ is a factor variable with $n$ levels. I noticed that removing the ...

1
2
3 4 5
74