I'm trying to plot a Gaussian (bell) shape in gnuplot. I am using the
function norm(x). The problem is that norm(x) plots just the first
part of the Gaussian bell shape, I don't know how to make the line
"come back down"... I used "help norm", but didn't get much
information either.
I feel like this is something trivial and simple, but I can't figure
it out...
Any help would be highly appreciated.
help norm
says "returns the CUMULATIVE normal (Gaussian)distribution function"
(emphasis added by me)
just plot your favourite variation of
gauss(x) = exp(-(x/t)**2)
Karl
normal(x, mu, sd) = (1/(sd*sqrt(2*pi)))*exp(-(x-mu)**2/(2*sd**2))
Then
plot [-3:3] normal(x,0,1)
will show you the standard normal.
Brendan
--
Brendan Halpin, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F1-009 x 3147
mailto:brendan...@ul.ie http://www.ul.ie/sociology/brendan.halpin.html
Thanks for your reply. I got the shape, but I am trying to constrain
it in the range:
set xrange [2.2:-2.2]
set yrange [0.01:0.15]
Instead of plot [-3:3] normal(x,0,1) , I used plot [-2.2:2.2]
normal(x,0.01,0.15) ... but it didn't cover the range I wanted... Am I
doing something wrong?
> Thanks for your reply. I got the shape, but I am trying to constrain
> it in the range:
>
> set xrange [2.2:-2.2]
> set yrange [0.01:0.15]
>
> Instead of plot [-3:3] normal(x,0,1) , I used plot [-2.2:2.2]
> normal(x,0.01,0.15) ... but it didn't cover the range I wanted... Am I
> doing something wrong?
normal() takes 3 parameters, x, the mean, and the standard deviation.
Thus normal(x,0,1) plots the standard normal distribution.
normal(x,100,10) plots a normal distribution with mean 100 and standard
deviation 10.
The standard deviation affects how wide and therefore how tall the
distribution is at its peak. For a standard deviation of 1 the peak is
about 0.4.
Brendan
--
Brendan Halpin, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F1-009 x 3147
mailto:brendan...@ul.ie http://www.ul.ie/sociology/brendan.halpin.html
If the value of x is more than 0.6 or less than -0.6, the
value of normal(x,0.01,0.15) is less than .001. This is
about 0.03% of the height of the graph. On my screen, that
means it is 0 when the pixel resolution of the display is
taken into account.
Thus the graph is present all the way from -2.2 to 2.2, but
it is covered up by the bottom border of the graph at y=0,
except in a range of about [-0.6:0.6].
Set the y range to include some negative values and you will
see the whole thing:
plot [-2.2:2.2] [-0.05:3.0] normal(x,0.01,0.15)
Dan
To reply by email, change LookInSig to luecking
Thanks!
If the integral of your function is approx. 1/3.6, then yes (e.g. if you
are plotting a distribution that is not normalized to 1 but so 1/3.6).
The standard deviation is related to the actual integral of your
Gaussian (the well-known 68% inclusion in the case of symmetric
1-sigma-limits), not necessarily to 1. The mean of a Gaussian is just
the position of the peak (this may not be valid for non-Gaussian
distributions), and therefore not depending on the y-scaling.
Ingo
Is there anyway I can add the skewness to this equation? So that the
curve can better fit my data?
> Is there anyway I can add the skewness to this equation? So that the
> curve can better fit my data?
Yes. But you really seem to be interested in statistical issues, rather
than simply plotting. If you want to go further with this, you ought to
investigate statistics software.
This link:
http://cran.r-project.org/doc/contrib/Ricci-distributions-en.pdf
leads to a nice discussion of how to fit data to distributions using R.
Brendan
--
Brendan Halpin, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F1-009 x 3147
mailto:brendan...@ul.ie http://www.ul.ie/sociology/brendan.halpin.html
Sorry for late reply.
If the Gaussian shape is always preserved (no distortion etc.), than you
can derive the normalization simply by the x- and y-scale. I.e., if the
maximum of the function is 0.399 (exact: 1/sqrt(2*pi)) but the curve is
stretched twice (i.e. sigma=2), than the integral and thus the
normalization factor is 2. The same would be true for sigma=1 but a
maximum = 0.798.
In short: x-stretch times y-stretch (all with respect to the standard
Gaussian function with sigma=1) is the normalization factor by which the
function has to be devided to get the integral=1.
Ingo
As some of you suggested, it appears that my data is not Gaussian.
Maybe I need to try other functions?? So if I want to check other
functions do I have to use the equation of each distribution and
check? Or is there a way that finds the distribution according to my
data?
I will separately include first my data, then the norm I created form
using the mean and standard deviation of my sample, and finally the
norm created by simply fitting the data:
[CODE]
-2.1 0.037037
-1.8 0.037037
-1.6 0.037037
-1.4 0.111111
-1.2 0.037037
-1.1 0.111111
-1.0 0.074074
-0.9 0.222222
-0.8 0.037037
-0.7 0.074074
-0.5 0.111111
-0.4 0.148148
-0.3 0.037037
-0.2 0.296296
-0.1 0.222222
0.0 0.185185
0.1 0.407407
0.2 0.111111
0.3 0.222222
0.4 0.185185
0.5 0.111111
0.6 0.148148
0.7 0.037037
0.8 0.037037
0.9 0.074074
1.0 0.037037
1.8 0.037037
[/CODE]
[CODE]
set boxwidth 0.1
set xrange [2.2:-2.2]
normal(x, mu, sd) = (1/(sd*sqrt(2*pi)))*exp(-(x-mu)**2/(2*sd**2))
plot normal(x,-0.25,0.95), "data.txt" using 1:2 w boxes
[/CODE]
[CODE]
set boxwidth 0.1
set xrange [2.2:-2.2]
f(x)= (1/(a*sqrt(2*pi)))*exp(-(x-b)**2/(2*a**2))
fit f(x) "check1234.txt" using 1:2 via a,b
normal(x, mu, sd) = (1/(sd*sqrt(2*pi)))*exp(-(x-mu)**2/(2*sd**2))
plot "data.txt" using 1:2 w boxes, f(x)
[/CODE]
Randa wrote:
>
> As some of you suggested, it appears that my data is not Gaussian.
> Maybe I need to try other functions?? So if I want to check other
> functions do I have to use the equation of each distribution and
> check? Or is there a way that finds the distribution according to my
> data?
well, usually the distribution should depend on the experiment or source
where you got your data from and the model associated with it.
You cannot use any distribution just to get a nice-looking curve.
Christoph
On Sep 27, 7:52 am, Christoph Bersch <use...@bersch.net> wrote:
> Hi,
Any suggestions?
> On Sep 27, 3:57 pm, Randa <asa...@mail.uc.edu> wrote:
>> This is a research project, so it's not something done before, I am
>> just studying a set of data I got trying to figure out if it follows a
>> certain statistical distribution.
> Any suggestions?
I'm not really clear what your data is. Is it a distribution? The plot
you show makes it look like a histogram, but in the data the second
column (which looks like a probability density or proportional
distribution) sums to about 3.2, so it is doesn't look like a relative
distribution.
If your data isn't in the form of a distribution, why compare it with a
standard distribution?
In the form you showed your data, if it were a distribution I would
interpret column 2 as the number of cases (or proportion of cases)
falling within a band centred on the column 1 value (where the with of
the band is the gap between successive values; I note your values are
not all the same distance apart).
Yes! You're right!! This is what it is:
"In the form you showed your data, if it were a distribution I would
interpret column 2 as the number of cases (or proportion of cases)
falling within a band centred on the column 1 value (where the with
of
the band is the gap between successive values";
But, actually the values are all the same values apart... I mean they
all have the same width, but some values are missing because the
number of cases there is zero.
Your density figure is wrong -- it looks like it is calculated with a
sample size of 27 whereas it is really 86 (or multiples thereof). Also
your mean and sd are wrong, because they seem to be calculated on the x
values without taking into account multiple instances of them.
On 86 observations, the mean is -.1616279, standard deviation .6860232.
If you re-define your density figures to sum to 1.0, it will work:
plot normal(x,-0.1616279,0.6860232), "x.dat" using 1:($2*86/27) w boxes
Brendan
PS: your data set is far too small for a real test of normality.
--
Brendan Halpin, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F1-009 x 3147
mailto:brendan...@ul.ie http://www.ul.ie/sociology/brendan.halpin.html
Thanks
> mailto:brendan.hal...@ul.ie http://www.ul.ie/sociology/brendan.halpin.html
> But still when I use the numbers you provided (the mean is -.1616279,
> standard deviation .6860232) I don't get a good fit. Did you tried it
> and it worked?
Using gnuplot and this code:
reset
set boxwidth 0.1
set xrange [-2.2:2.2]
normal(x, mu, sd) = (1/(sd*sqrt(2*pi)))*exp(-(x-mu)**2/(2*sd**2))
plot normal(x,-0.1616279,0.6860232), "x.dat" using 1:($2*86/27) w boxes
I get this result:
http://teaching.sociology.ul.ie/bhalpin/randa_gnuplot.pdf
Putting your data into another program (Stata), and recreating the
individual observations, I get this:
http://teaching.sociology.ul.ie/bhalpin/randa_stata.pdf
Stata chooses to create wider bins which reduce some of the jaggedness
of the gnuplot histogram, which is helpful, but even then the histogram
only loosely approximates the normal shape. However, as I said before
this is a very small data set so even if it was from a strictly normal
population it likely wouldn't look very like it.
Regards,
Brendan
--
Brendan Halpin, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F1-009 x 3147
mailto:brendan...@ul.ie http://www.ul.ie/sociology/brendan.halpin.html