New answers tagged

0

If what you have is $100$ individuals each having $400$ mutations in one of $20,000$ genes, with all genes having the same probability of mutation, then for a quick analysis you don't need a simulation. Overall, there are $400 \times100=40,000$ mutations. With $20,000$ genes, that comes out to 2 mutations per gene on the average over all $400$ individuals. ...


1

An example of using the inverse CDF (quantile function) as suggested by @Glen_b You can use runif to generate random quantiles and then pass these quantiles to e.g. qnorm (or any other distribution) to find the values these quantiles correspond to for the given distribution. If you only generate quantiles within a specific interval, you truncate the ...


0

A friend helpfully suggested that this is similar to a Brownian Bridge, and I was able to use that to derive an analytical solution. Conditions: $w$ = min boundary, $x$ = starting value, $y$ = final value, $z$ = max boundary 1. Incorporating the x and y conditions using a Brownian Bridge The generalized Brownian Bridge is a specific Wiener Process, defined ...


1

After a couple of days hammering away at this, I think I have a workable solution, reparameterizing a beta distribution. The key insight (from this answer) was to solve for the beta distribution parameters $\alpha$ and $\beta$ as functions of the mean $\mu$ and variance $\sigma^2$. Then, I just had to decide how $\mu$ and $\sigma^2$ should vary with $t$ on ...


0

According to the documentation for numpy.random.geometric, The geometric distribution models the number of trials that must be run in order to achieve success. It is therefore supported on the positive integers, k = 1, 2, .... this means that z-1 should used as the number of repetitions of the current state, before moving to the other state. I thus wonder ...


0

Neither. Those distributions are used only to approximate the distribution of your data. First of all, normality checking is pretty useless procedure. Use the distribution that is useful as an approximation of the distribution of your data, that shares the characteristics you find important. E.g. if the data is continuous and the distribution is roughly ...


2

The differences in variance are most definitely the reason for the observed differences in importance. Broadly, you would only expect the result to show ~.167 for a lm's set of coefficients. Because of the way simulated_set[["dep"]] is defined, the mean value is determined by mulitplying all X variables by one-sixth. > sapply(coef(lm(dep ~ X1 + ...


3

Given a standardized $n\times p$ design matrix $X$ and a specified coefficient $p$-vector $b$ you want to generate normalized random responses $y$ for which the ordinary least squares fit of the model $y = X\beta + \varepsilon$ is $b;$ that is, $$b = (X^\prime X)^{-}X^\prime y.$$ How you normalize doesn't matter (to unit variance or unit Euclidean length), ...


7

An historical note about sample is that it got recently modified for being biased in some extreme situations (as commented by Chris Haug). In earlier versions of R such as 3.4.4, still running on my ownlaptop, the outcome of the above would be the same as a cdf inversion (and as the complement of the standard Uniform draw): > set.seed(1) > rbinom(10,1,...


8

Somewhat related example: One way to generate 10 tosses of a coin with probability $0.4$ of heads is to use rbinom: set.seed(123); rbinom(10, 1, .4) [1] 0 1 0 1 1 0 0 1 0 0 Another way is to use the binomial inverse CDF (quantile) function) qbinom to transform uniform random numbers from runif get the desired Bernoulli distribution. set.seed(123); qbinom(...


2

I tried getting to the source code for both, but couldn't find it. I did, however, find the references for the building of the two algorithms. They do not use the same references, so it is reasonable that they do not generate them in a similar manner. Indeed, sample() function briefly says it uses an easier way to handle random numbers, presumably through ...


1

The second idea is the right one. I've already used it.


0

You need to generate your data in accordance with what you want the data-generating process to be. If you want your dependent variable to be related to your independent variables, then you need to generate it as such. If you don't want your dependent variable to be related to your independent variables, then you need to generate it as such. There is no right ...


Top 50 recent answers are included