Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
331
votes
Accepted
How to understand degrees of freedom?
Let's generate 20 independent and identically distributed (iid) standard Normal variates and estimate their mean and standard deviation with the usual formulas (mean = sum/count, etc.). … To test goodness of fit, create four bins with cutpoints at the quartiles of a standard normal: -0.675, 0, +0.657, and use the bin counts to generate a Chi-squared statistic. …
50
votes
How to create an arbitrary covariance matrix
That's fine: you can easily generate a random orthogonal matrix. Just wrap $n^2$ iid standard Normal values into a square matrix and then orthogonalize it. … The QR decomposition will do that, as in this code
n <- 5
p <- qr.Q(qr(matrix(rnorm(n^2), n)))
This works because the $n$-variate multinormal distribution so generated is "elliptical": it is invariant …
47
votes
Generating random numbers manually
:$$X=\sqrt{-2\log U_1}\,\cos(2\pi U_2)$$(and even two since $Y=\sqrt{-2\log U_1}\,\sin(2\pi U_2)$ is another normal variate independent from $X$). … By comparison, if I exploit the very same 3000 die outcomes $D_i$ to create enough digits of a pseudo-uniform as$$U=\sum_{i=1}^k \dfrac{D_i-1}{6^i}$$with $k=15$ (note that 6¹⁵>10¹¹, hence I generate more …
45
votes
Accepted
Is Cauchy distribution somehow an "unpredictable" distribution?
Heavy tails
While the Cauchy is symmetric and roughly bell shaped, somewhat like the normal distribution, it has much heavier tails (and less of a "shoulder"). … For example, there's a small but distinct probability that a Cauchy random variable will lay more than 1000 interquartile ranges from the median -- roughly of the same order as a normal random variable …
45
votes
Accepted
Simulating draws from a Uniform Distribution using draws from a Normal Distribution
This approach seems circular, though: how do we generate a uniform variate with a process that needs a uniform variate to begin with? … For fixed $k$, the asymptotic computational cost is therefore $O(n\log(k))$ = $O(n)$, needing $2n(1+1/k)$ Normal variates to generate $n$ uniform values.) …
42
votes
Accepted
Test whether variables follow the same distribution
iterations for each permutation test (n.iter), a reference to the function test to compute the test statistic (you will see momentarily why we might not want to hard-code this), and two functions to generate … <- replicate(n.reps, f(n.x, n.y, n.per.rep, dist.y=rnorm))
hist(normal, breaks=20)
plot(normal)
exponential <- replicate(n.reps, f(n.x, n.y, n.per.rep, dist.y=function(n) rgamma(n, 1)))
hist(exponential …
41
votes
How to generate correlated random numbers (given means, variances and degree of correlation)?
Finally, for each pseudorandom variate, $x_i$, that you have generated, generate a pseudorandom error variate, $e_i$, with the appropriate error variance $v_e$, and compute the correlated pseudorandom … variate, $y_i$, by multiplying and adding. …
28
votes
How to simulate data that satisfy specific constraints such as having specific mean and stan...
For example, to generate a set of $N$ data from a normal distribution that will have a given sample mean, $\bar x$, and variance, $s^2$, you will need to fix the values of two points: $y$ and $z$. … Alternatively, you could generate a small number of samples and use the one with the smallest (say) Kolmogorov-Smirnov statistic. …
27
votes
How to simulate from a Gaussian copula?
Gauss copula
The Gauss copula is defined implicitely from the multivariate normal distribution, that is, the Gauss copula is the copula associated with a multivariate normal distribution. … Generate a vector $Z = (Z_1, \ldots, Z_d)'$ of independent standard normal variates.
Set $X = AZ$
Return $U = (\Phi(X_1), \ldots, \Phi(X_d))'$. …
24
votes
Accepted
How to define a distribution such that draws from it correlate with a draw from another pre-...
Therefore,
$$ {\rm cor}(X,Y) = \frac{ {\rm cov}(X,Y) }{ \sqrt{ {\rm var}(X)^{2} } } = \rho $$
So if you can generate data from $F_{X}$, you can generate a variate, $Y$, that has a specified correlation … This is due to the fact that sums of normally distributed variables are normal; that is not a general property of distributions. …
22
votes
Accepted
What are the mean and variance of the ratio of two lognormal variables?
The relationship between the mean and variance of a lognormal variate and the mean and variance of the corresponding normal variate is:
$\mathbb E(X/Y) = \mathbb E e^Z = \exp \{\mu_Z + \frac{1}{2}\sigma … }$
$\mathrm{Var}(X/Y) = \mathrm{Var}(e^Z) = \exp \{2\mu_Z + 2\sigma^2_Z\} - \exp \{2\mu_Z + \sigma^2_Z\} \>.$
This can be rather easily derived by considering the moment-generating function of the normal …
22
votes
Accepted
Moment generating function of the inner product of two gaussian random vectors
When $X$ and $Y$ are standard normal,
$$XY = ((X+Y)/2)^2 - ((X-Y)/2)^2$$
is a difference of two independent scaled Chi-squared variates. … Because the mgf of a chi-squared variate is $1/\sqrt{1 - 2\omega}$, the mgf of $((X+Y)/2)^2$ is $1/\sqrt{1-\omega}$ and the mgf of $-((X-Y)/2)^2$ is $1/\sqrt{1+\omega}$. …
21
votes
If a sample is normally distributed, is its population always normally distributed?
So it may make perfect sense to model apple weights by a normal distribution, but that's not the real thing; the normal distribution is a convenient abstraction, a tool. … If you test normality, you may well fail to reject normality, but you would also fail to reject an infinite number of non-normal distributions at the same time, and at least some of those would have a …
19
votes
transformation to normality of the dependent variable in multiple regression
Note that the collection of dependent variables ($Y$'s) is not assumed to be normal. … of independent variable values, that might be very non-normal. …
18
votes
Accepted
How to generate sorted uniformly distributed values in an interval efficiently?
If you want to avoid sorting, instead generate $n+1$ independent exponentially-distributed variates. Normalize their cumulative sum to the range $(0,1)$ by dividing by the sum. … For many more (amusing) ways to simulate independent uniform variates, see Simulating draws from a Uniform Distribution using draws from a Normal Distribution. …