Hot answers tagged

22 votes
Accepted

Kolmogorov-Smirnov test fails to recognize a normally distributed sample

As highlighted in the comments (Alex J and COOLSerdash), there are two issues here. First, the model used under the KS test is different from the true model that generated the data. The correct way ...
utobi's user avatar
  • 11.6k
18 votes

Infinite upper confidence interval using Fisher exact test in R

There's a one-sided confidence interval because you asked for a one-sided test
Thomas Lumley's user avatar
17 votes

Compare 90th percentiles of two samples (confidence interval, test)

You can use a bootstrap to generate a confidence interval on this quantity, and a permutation test for the P-value. Let's go over an example for both. I'm not going to assume your response times are ...
PBulls's user avatar
  • 3,658
17 votes

Difference between charts of rcauchy(10000) and geom_function(fun = dcauchy)

There is nothing surprising here since you're comparing a kernel density estimate based on a sample from a truncated Cauchy distribution with the theoretical pdf of an untruncated Cauchy. If what you'...
Jarle Tufto's user avatar
  • 10.7k
17 votes

How to generate from this distribution without inverse in R/Python?

A quick and dirty solution is to apply the inverse transform sampling in which the quantile function is computed via numerical inversion. Below is an R ...
utobi's user avatar
  • 11.6k
16 votes

How can I automatically perform multiple linear regressions in R to identify the strongest predictors?

Welcome to the site. My advice is to NOT automate this. There are a variety of methods to do automated model selection (forward, backward, stepwise). Of these, the only ones that I would use are ...
Peter Flom's user avatar
  • 117k
16 votes
Accepted

Kolmogorov-Smirnov instability depending on whether values are small or big

The ways you’ve coded it, you’re asking the KS test about a null hypothesis that the distribution is $N(0,1)$. In the first set of numbers, that looks plausible. Consequently, the p-value is high. In ...
Dave's user avatar
  • 61k
14 votes

If a variable is coded as yes/no/unknown, is it categorical or ordinal?

This cannot be answered without knowing exactly what 'unknown' means in your dataset. If 'unknown' refers to missing data, then it's likely best to replace them with 'NA' and analyse the variables as ...
mkt's user avatar
  • 18.1k
14 votes

How does R lm() function calculate standard error of slopes with more than one predictor?

A slightly different angle on Dave's answer: The standard errors reported are the square roots of the diagonal elements of the estimated variance-covariance matrix of the OLS estimator $$Var(\hat{\...
Christoph Hanck's user avatar
14 votes

Why does dbeta not sum to 1?

The relevant property of a probability density is not that it sums (for evaluation on some particular $x$ values) to one, but that it integrates to one. If you evaluate a density $f$ at $x$ values ...
Stephan Kolassa's user avatar
14 votes

How to generate from this distribution without inverse in R/Python?

Your pdf is the same as a transformation of a variable that follows a truncated gamma distribution. The gamma distribution has shape $k=2$, rate $\alpha+1$ and is truncated at $-\log(\beta)$. ...
Sextus Empiricus's user avatar
13 votes
Accepted

Why am I getting different PCA loadings for the same data set using two different r packages?

The values you get from FactoMineR are not loadings: they are coordinates. Loadings are coordinates divided by the square root of eigenvalues. I don't know if you can directly get loadings from ...
J-J-J's user avatar
  • 3,862
13 votes
Accepted

Why doesn't R output for a paired t-test match the formula for a confidence interval in the t-distribution?

0.5547 is not the $t$ you are looking for. The $t$ you want to use in the equation is the critical value for the $t$-distribution with 8 degrees of freedom (n - 1). ...
kmm's user avatar
  • 557
12 votes
Accepted

Modelling a proportion

You don't actually have a continuous proportion. That is a discrete proportion. The proportions you have are counts of successes out of 100 trials. You are fortunate that you know the number of ...
gung - Reinstate Monica's user avatar
12 votes

How to compute the standard error of the variable $- \frac{\hat{\beta}_0}{\hat{\beta}_1}$ of a logistic regression?

One possibility is the delta method (see also this post). Another is simulation-based inference as described in the paper by King et al. (2000) with a recent exploration of simulation-based inference ...
COOLSerdash's user avatar
  • 30.1k
12 votes
Accepted

Is there a clean way to derive the start parameters for running the `fitdist()` function for the Gumbel distribution?

The NIST page on Gumbel distributions shows the method of moments estimators for the parameters of both the maximum and minimum extreme-value distributions. Those are easily calculated and should ...
EdM's user avatar
  • 90.8k
12 votes

Mixed effects in Random forest (in R)

The current main popular implementation of Random Forests (RF) (i.e. the randomForest package) is available only for univariate (continuous or discrete) responses. ...
utobi's user avatar
  • 11.6k
11 votes

Why does re-scaling my density plot using counts change the y-axis so much?

The bottom line (here at the top) is that the vertical scale in the second series of plots is probability density, which not only is not the count or frequency in any bin, it is not probability either....
Nick Cox's user avatar
  • 55.4k
11 votes

What type of pairwise test does emmeans run?

Here is an illustration of how the model determines the right test. First, create a toy data set and run both a pooled and a paired t test: ...
Russ Lenth's user avatar
11 votes

Why am I getting different PCA loadings for the same data set using two different r packages?

Principal components are the eigenvectors of the covariance matrix. Eigenvectors are only defined up to a multiplicative constant. In this case, both results are identical up to a multiplicative ...
cdalitz's user avatar
  • 5,022
11 votes

How to generate from this distribution without inverse in R/Python?

It is possible to generate this random variable using a rejection-sampling algorithm using uniform random variables. To do this, let $U_1,U_2 \sim \text{IID U}(0,1)$ and define the random variable: $$...
Ben's user avatar
  • 123k
10 votes

Why does re-scaling my density plot using counts change the y-axis so much?

The difference between the two figures is that one displays the probability density and the other the count density. The total probability is always one (by definition). But the total counts can be ...
Sextus Empiricus's user avatar
10 votes

Best plot in R for count data with a broad range and lots of low frequency data

Two simple variations on the suggestion of logarithmic scale by @Stephan Kolassa are square root scale (some history as a first aid transformation for counts) log(count + 1) scale implemented ...
Nick Cox's user avatar
  • 55.4k
10 votes

Mixed effects modelling - Is there a limit for number of observations?

I will add my two cents as the two questions have very different answers, and the accepted answer only explains those very briefly. One assumption I would have to make is that all of those variables ...
StasK's user avatar
  • 31.4k
10 votes

Doubts about mixed model (R vs SAS) with nested random effects

Can I ignore this warning ? You certainly can, but I doubt that would be a good idea. The problem you have encountered seems to be due to the way the variables are coded. If we look at a cross ...
Robert Long's user avatar
10 votes

Help with the normality of the residuals of my regression model

Normality of the error distribution is possibly the least important assumption of linear regression. All desirable properties of OLS and of the estimated coefficients still hold regardless of the ...
Matenmakkers's user avatar
10 votes
Accepted

How does R lm() function calculate standard error of slopes with more than one predictor?

You’re missing two facets about the standard error for multiple regression. In your formula, the $n-2$ comes from subtracting the number of regression parameters $(2)$ from the sample size $(n)$, and ...
Dave's user avatar
  • 61k
10 votes
Accepted

How do I present averages from different sample sizes across years?

The usual thing to do here would be to include "error bars" around your sample average giving a confidence interval for the true average from the sampled data each year. For binary data you ...
Ben's user avatar
  • 123k
10 votes

How do I deal with many zero values in terms of correlation?

Because you are comparing simulated vs. true values, a correlation between the two is not the best way to evaluate the quality of your simulations. This is easy to illustrate: imagine your model is ...
mkt's user avatar
  • 18.1k
10 votes
Accepted

Alternative to Friedman Test in R

The tests you cited are not appropriate due to the presence of repeated measures. The common way to deal with repeated measures is via mixed-effects linear models. I'm considering here the most ...
utobi's user avatar
  • 11.6k

Only top scored, non community-wiki answers of a minimum length are eligible