normal-distribution

How to use the function curve in [R] to graph a normal curve?

微笑、不失礼 提交于 2019-11-29 13:46:58
I'm trying to make a histogram in [R], and the normal curve that describes the histogram as follows: w<-rnorm(1000) hist(w,col="red",freq=F,xlim=c(-5,5)) curve(dnorm(w),-5,5,add=T,col="blue") But when I try to plot the normal curve by curve function shows me the following error: Error en curve(dnorm(w), -5, 5, add = T, col = "blue") : 'expr' must be a function, or a call or an expression containing 'x' What am I doing wrong? You just need to drop the "w" argument to dnorm in curve : w<-rnorm(1000) hist(w,col="red",freq=F,xlim=c(-5,5)) curve(dnorm,-5,5,add=T,col="blue") To use something other

Drawing pseudorandoms from a truncated normal distribution

試著忘記壹切 提交于 2019-11-29 08:48:57
Matlab has the function randn to draw from a normal distribution e.g. x = 0.5 + 0.1*randn() draws a pseudorandom number from a normal distribution of mean 0.5 and standard deviation 0.1. Given this, is the following Matlab code equivalent to sampling from a normal distribution truncated at 0 at 1? while x <=0 || x > 1 x = 0.5 + 0.1*randn(); end Using MATLAB's Probability Distribution Objects makes sampling from truncated distributions very easy. You can use the makedist and truncate functions to define the object and then modify (truncate it) to prepare the object for the random function which

Generate matrix with iid normal random variables using R

泪湿孤枕 提交于 2019-11-29 06:07:56
问题 Is there a way to generate a data set with normally distributed random values in R without using a loop? Each entry would represent an independent random variable with a normal distribution. 回答1: To create an N by M matrix of iid normal random variables type this: matrix( rnorm(N*M,mean=0,sd=1), N, M) tweak the mean and standard deviation as desired. 回答2: let mu be a vector of means and sigma a vector of standard devs mu<-1:10 sigma<-10:1 sample.size<-100 norm.mat<-mapply(function(x,y){rnorm

Random Numbers with Gaussian and Uniform Distributions in matlab

試著忘記壹切 提交于 2019-11-28 22:05:25
I want generate a number in Gaussian and Uniform distributions in matlab. I know this function randi and rand() but all of them are in normal (Gaussian) distribution. How can a generate a random number in uniform distribution? Use rand(dimensions) for a Uniform Distribution between 0 and 1. Use randn(dimensions) * sqrt(sigma) + mu for a Gaussian Distribution with a mean of mu and variance of sigma . randn is the function to generate Gaussian distributed variables ( randi and rand produce uniformly distributed ones). raj You can generate any distribution from rand(). For example , lets say you

Java normal distribution

依然范特西╮ 提交于 2019-11-28 18:35:22
I'm trying to simulate the arrival of fans to a stadium. The system itself, I believe it won't be a problem, but, the arrival of the fans follows a normal distribution. My problem is: I have a certain time for the arrival like 100 minutes and 1000 fans, and I need to generate arrivals of Fans at a time following that distribution like -> fan x arrived at 25 minutes, fan y arrived at 54 minutes, and so on. How can I generate these random numbers following a normal distribution? I'm doing this in Java and found the nextGaussian() method in the Random class , but I'm not sure how to use this in

Sample from multivariate normal/Gaussian distribution in C++

北城余情 提交于 2019-11-28 16:31:45
问题 I've been hunting for a convenient way to sample from a multivariate normal distribution. Does anyone know of a readily available code snippet to do that? For matrices/vectors, I'd prefer to use Boost or Eigen or another phenomenal library I'm not familiar with, but I could use GSL in a pinch. I'd also like it if the method accepted nonnegative -definite covariance matrices rather than requiring positive-definite (e.g., as with the Cholesky decomposition). This exists in MATLAB, NumPy, and

How to use boost normal distribution classes?

落花浮王杯 提交于 2019-11-28 16:07:00
I'm trying to use boost::normal_distribution in order to generate a normal distribution with mean 0 and sigma 1. The following code doesn't work as some values are over or beyond -1 and 1 (and shouldn't be). Could someont point out what I am doing wrong? #include <boost/random.hpp> #include <boost/random/normal_distribution.hpp> int main() { boost::mt19937 rng; // I don't seed it on purpouse (it's not relevant) boost::normal_distribution<> nd(0.0, 1.0); boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > var_nor(rng, nd); int i = 0; for (; i < 10; ++i) { double d = var_nor

Perform a Shapiro-Wilk Normality Test

吃可爱长大的小学妹 提交于 2019-11-28 14:41:43
问题 I want to perform a Shapiro-Wilk Normality Test test. My data is csv format. It looks like this: heisenberg HWWIchg 1 -15.60 2 -21.60 3 -19.50 4 -19.10 5 -20.90 6 -20.70 7 -19.30 8 -18.30 9 -15.10 However, when I perform the test, I get: shapiro.test(heisenberg) Error in [.data.frame (x, complete.cases(x)) : undefined columns selected Why isnt`t R selecting the right column and how do I do that? 回答1: What does shapiro.test do? shapiro.test tests the Null hypothesis that "the samples come from

C++ TR1: how to use the normal_distribution?

这一生的挚爱 提交于 2019-11-28 12:08:51
I'm trying to use the C++ STD TechnicalReport1 extensions to generate numbers following a normal distribution, but this code (adapted from this article ): mt19937 eng; eng.seed(SEED); normal_distribution<double> dist; // XXX if I use the one below it exits the for loop // uniform_int<int> dist(1, 52); for (unsigned int i = 0; i < 1000; ++i) { cout << "Generating " << i << "-th value" << endl; cout << dist(eng) << endl; } only prints 1 "Generating..." log message, then never exits the for loop ! If I use the distribution I commented out instead, it terminates, so I'm wondering what I'm doing

Generate multivariate normal r.v.'s with rank-deficient covariance via Pivoted Cholesky Factorization

北城余情 提交于 2019-11-28 11:31:52
问题 I'm just beating my head against the wall trying to get a Cholesky decomposition to work in order to simulate correlated price movements. I use the following code: cormat <- as.matrix(read.csv("http://pastebin.com/raw/qGbkfiyA")) cormat <- cormat[,2:ncol(cormat)] rownames(cormat) <- colnames(cormat) cormat <- apply(cormat,c(1,2),FUN = function(x) as.numeric(x)) chol(cormat) #Error in chol.default(cormat) : # the leading minor of order 8 is not positive definite cholmat <- chol(cormat, pivot