normal-distribution

Creating Mills Ratio in R for large values

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 11:09:33
问题 I'm using R to create a function, that amongst others uses Mills Ratio (See here). This is not a complicated formula, and at first I just programmed it like this: mill <- function(x) { return((1 - pnorm(x)) / dnorm(x)) } I soon found out however, that for very large values (x >= 9) of x , this function returns zero. Even more dramatic, at around x >= 37, it starts returning NaN , which really messes up my stuff. Following the article, for now I've changed the function into this: mill <-

Scipy lognorm fitting to histogram

天涯浪子 提交于 2019-12-11 04:24:57
问题 I'm fitting a lognormal pdf to some binned data, but my curve doesn't quite match the data, see image below. My code is: import numpy as np import matplotlib.pyplot as plt from scipy.stats import lognorm data = genfromtxt('data.txt') data = np.sort(data) # plot histogram in log space ax.hist(data, bins=np.logspace(0,5,200),normed=1) ax.set_xscale("log") shape,loc,scale = lognorm.fit(data) print shape, loc, scale pdf = sp.stats.lognorm.pdf(data, shape, loc, scale) ax.plot(data,pdf) plt.show()

Curve fiting of normal distribution in Python

雨燕双飞 提交于 2019-12-11 02:37:09
问题 I want to calculate the percentiles of normal distribution data, so I first fit the data to the normal distribution, here is the example: from scipy.stats import norm import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as plt x = np.array([ 0.47712125, 0.5445641 , 0.61193563, 0.67924615, 0.74671202, 0.81404772, 0.88144172, 0.94885291, 1.01623919, 1.08361011, 1.15100191, 1.21837793, 1.28578227, 1.3531658 , 1.42054981, 1.48794397, 1.55532424, 1.62272161, 1.69010744,

How to calculate multivariate normal distribution function in R

偶尔善良 提交于 2019-12-10 21:07:53
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 3 years ago . Here's what I tried, making use of the mvtnorm package Sample Dataset library(mvtnorm) set.seed(2357) df <- data.frame( x = rnorm(1000, mean=80, sd=20), y = rnorm(1000, mean=0, sd=5), z = rnorm(1000, mean=0, sd=5) ) head(df) x y z 1 70.38 1.307 0.2005 2 59.76 5.781 -3.5095 3 54.14 -1.313 -1.9022 4 79.91 7.754 -6.2076 5 87.07 1.389 1.1065 6 75.89 1.684 6.2979 Fit multivariate

Vectorizing code to calculate (squared) Mahalanobis Distiance

℡╲_俬逩灬. 提交于 2019-12-10 18:46:03
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 4 years ago . EDIT 2: this post seems to have been moved from CrossValidated to StackOverflow due to it being mostly about programming, but that means by fancy MathJax doesn't work anymore. Hopefully this is still readable. Say I want to to calculate the squared Mahalanobis distance between two vectors x and y with covariance matrix S . This is a fairly simple function defined by M2(x, y; S)

Drawing decision boundary of two multivariate gaussian

青春壹個敷衍的年華 提交于 2019-12-10 11:17:12
问题 I am trying to plot something similar to below: I am using Matlab. I achieved drawing contour plots. However I could not draw the discriminant. Can anyone show a sample Matlab code or give some idea to draw the discriminant? 回答1: If you know the probability density function of each of the gaussian for a given point (x,y) , lets say its pdf1(x,y) and pdf2(x,y) then you can simply plot the contour line of f(x,y) := pdf1(x,y) > pdf2(x,y) . So you define function f to be 1 iff pdf1(x,y)>pdf2(x,y)

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

家住魔仙堡 提交于 2019-12-10 02:22:28
问题 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

point of intersection 2 normal curves

落花浮王杯 提交于 2019-12-09 04:58:58
问题 Although I think this is a basic question, I can't seem to find out how to calculate this in R: the point of intersection (I need the x-value) of 2 or more normal distributions (fitted on a histogram) which have for example the following parameters: d=data.frame(mod=c(1,2),mean=c(14,16),sd=c(0.9,0.6),prop=c(0.6,0.4)) With the mean and standard deviation of my 2 curves, and prop the proportions of contribution of each mod to the distribution. 回答1: You can use uniroot : f <- function(x) dnorm(x

R - multivariate normal distribution in R

早过忘川 提交于 2019-12-08 19:40:32
I would like to simulate a multivariate normal distribution in R. I've seen I need the values of mu and sigma. Unfortunately, I don't know how obtain them. In the following link you will find my data in a csv file "Input.csv". Thanks https://www.dropbox.com/sh/blnr3jvius8f3eh/AACOhqyzZGiDHAOPmyE__873a?dl=0 Please, could you show me an example? Raúl Your link is broken, but I understand that you want to generate random samples from empirical multivariate normal distribution. You can do it like that, assuming df is your data.frame with data: library('MASS') Sigma <- var(df) Means <- colMeans(df)

Function for testing system stability, which receives predicted time series as input

陌路散爱 提交于 2019-12-08 16:23:29
问题 I want to write a function that gets a time series and a standard deviation as parameters and returns an adjusted time series which looks like a forecast. With this function I want to test a system for stability, which gets a forecasted time series list for weather as input parameter. My approach for such a function, which is described below: vector<tuple<datetime, double>> get_adjusted_timeseries(vector<tuple<datetime, double>>& timeseries_original, const double stddev, const double dist_mid