normal-distribution

Plot a contour of multivariate normal PDF of a given MVN in MATLAB?

末鹿安然 提交于 2019-12-05 03:41:58
I have a bivariate gaussian I defined as follow: I=[1 0;0 1]; mu=[0,0]; sigma=0.5*I; beta = mvnrnd(mu,sigma,100); %100x2 matrix where each column vector is a variable. now I want to plot a contour of the pdf of the above matrix. What I did: Z = mvnpdf(beta,mu,sigma); %100x1 pdf matrix Now I want to plot a contour of the bivariate gaussian beta. I know I should use the command contour but this one require Z to be a square matrix. how do I solve this? I am very confused and not sure how to plot the contour of the bivariate gaussian!! ANY HELP IS GREATLY APPRECIATED.. Thank you You need to define

Toy R code on Bayesian inference for mean of a normal distribution [data of snowfall amount]

余生长醉 提交于 2019-12-05 02:56:02
问题 I have a number of snowfall observations: x <- c(98.044, 107.696, 146.050, 102.870, 131.318, 170.434, 84.836, 154.686, 162.814, 101.854, 103.378, 16.256) and I was told that it follows normal distribution with known standard deviation at 25.4 but unknown mean mu . I have to make inference on mu using Bayesian Formula. This is information on prior of mu mean of snow | 50.8 | 76.2 | 101.6 | 127.0 | 152.4 | 177.8 --------------------------------------------------------------- probability | 0.1 |

Defining a function that calculates the covariance-matrix of a correlation-matrix

流过昼夜 提交于 2019-12-05 02:44:44
问题 I have some problems with the transformation of a matrix and the names of the rows and columns. My problem is as follows: As input-matrix I have a (symmetric) correlation matrix like this one: The correlation-vector is given by the values of the lower triangular matrix: Now, I want to compute the variance-covariance-matrix of the these correlations, which are approximately normally distributed with the variance-covariance-matrix : The variances can be approximated by -> N is the sample size

evaluate multivariate Normal/Gaussian Density in c++

点点圈 提交于 2019-12-04 19:45:14
Right now I have the following function to evaluate the Gaussian density: double densities::evalMultivNorm(const Eigen::VectorXd &x, const Eigen::VectorXd &meanVec, const Eigen::MatrixXd &covMat) { double inv_sqrt_2pi = 0.3989422804014327; double quadform = (x - meanVec).transpose() * covMat.inverse() * (x-meanVec); double normConst = pow(inv_sqrt_2pi, covMat.rows()) * pow(covMat.determinant(), -.5); return normConst * exp(-.5* quadform); } This is just transcribing the formula . However I get a lot of 0, nans and infs. I suspect it's coming from the covMat.determinant() portion being very

How to plot normal distribution with percentage of data as label in each band/bin?

醉酒当歌 提交于 2019-12-04 12:58:41
While plotting normal distribution graph of data, how can we put labels like in image below for percentage of data in each bin where each band has a width of 1 standard deviation using matplotlib/seaborn or plotly ? Currently, im plotting like this: hmean = np.mean(data) hstd = np.std(data) pdf = stats.norm.pdf(data, hmean, hstd) plt.plot(data, pdf) Although I've labelled the percentages between the quartiles, this bit of code may be helpful to do the same for the standard deviations. import numpy as np import scipy import pandas as pd from scipy.stats import norm import matplotlib.pyplot as

Vectorizing the multivariate normal CDF (cumulative density function) in Python

≯℡__Kan透↙ 提交于 2019-12-04 08:29:19
How can I vectorize the multivariate normal CDF (cumulative density function) in Python? When looking at this post, I found out that there is a Fortran implementation of the multivariate CDF that was "ported" over to Python. This means I can easily evaluate the CDF for one specific case. However, I'm having a lot of trouble efficiently applying this function to multiple entries. Specifically speaking, the function I need to "vectorize" takes 4 arguments: the lower bounds of integration(vector) the upper bounds of integration (vector) the means of the normal random variables (vector) the

Draw Normal Distribution Graph of a Sample in Matlab

怎甘沉沦 提交于 2019-12-04 07:56:19
I have 100 sampled numbers, and I need to draw the normal distribution curve of them in matlab. The mean and standard deviation of these sampled data can be calculated easily, but is there any function that plots the normal distribution? If you have access to Statistics Toolbox, the function histfit does what I think you need: >> x = randn(10000,1); >> histfit(x) Just like with the hist command, you can also specify the number of bins, and you can also specify which distribution is used (by default, it's a normal distribution). If you don't have Statistics Toolbox, you can reproduce a similar

Random number within a range based on a normal distribution

你离开我真会死。 提交于 2019-12-04 07:46:22
问题 I want to generate random numbers with a range (n to m, eg 100 to 150), but instead of purely random I want the results to be based on the normal distribution. By this I mean that in general I want the numbers "clustered" around 125. I've found this random number package that seems to have a lot of what I need: http://codeproject.com/KB/recipes/Random.aspx It supports a variety of random generators (include mersiene twister) and can apply the generator to a distribution. But I'm confused, if

Alternative for scipy.stats.norm.pdf?

帅比萌擦擦* 提交于 2019-12-04 05:47:22
Does anyone know of an alternative for scipy.stats.norm.pdf()? I'm hosting my python site on Google App Engine and Google doesn't support SciPy. I've tried this function, but that didn't return the same results as scipy: def normpdf(x, mu, sigma): u = (x-mu)/abs(sigma) y = (1/(sqrt(2*pi)*abs(sigma)))*exp(-u*u/2) return y For example: print scipy.stats.norm.pdf(20, 20, 10) print normpdf(20, 20, 10) print scipy.stats.norm.pdf(15, 20, 10) print normpdf(15, 20, 10) print scipy.stats.norm.pdf(10, 20, 10) print normpdf(10, 20, 10) Returns these values: 0.0398942280401 0.0398942280401 0.0352065326764

Can't add a probability-curve on the histogram

倖福魔咒の 提交于 2019-12-03 17:14:47
I'm trying do display multiple histograms with one plot with the lattice-package. That's my code so far: histogram(~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10, data=mydata, type = "density",layout=c(5,2), panel=function(x, ...) { panel.histogram(x, ...) panel.mathdensity(dmath=dnorm, col="black", args=list(mean=mean(x), sd=sd(x)), ...) }) The problem is, that it won't plot the probability-curve. It doesn't give me an error back, so the code looks good, I think. I also tried it with only one variable and it didn't work either: histogram(~ X1, data=mydata, type = "density",layout=c(5,2),