density graph

Econometrics questions and discussions
ivory4
Posts: 144
Joined: Mon Aug 24, 2009 12:16 pm

density graph

Unread post by ivory4 »

I have a serie generated and from histogram it looks quite bell-shaped.
To draw the density, I use

Code: Select all

density(type=gauss) bn 1 2000 x bnd
x are 100 grids automatically generated using 1%-ile to 99%-ile, why there is a 0.0, because there is no zero in my series?

Code: Select all

compute fract=%fractiles(bn,||.025,.975||)
compute bar = fract(1)
scatter(style=lines,$
header="Figure 3 ",hshade=||0.0,bar||) 1
# x bnd / 1
I want to shade the area left to 2.5%-ile point, but this would shade the whole area, I tried to add a vshade but only real is allowed as arguments. Is there any way to do that?

how do I put text near the shade or in the shade or with an arrow?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: density graph

Unread post by TomDoan »

ivory4 wrote:I have a serie generated and from histogram it looks quite bell-shaped.
To draw the density, I use

Code: Select all

density(type=gauss) bn 1 2000 x bnd
x are 100 grids automatically generated using 1%-ile to 99%-ile, why there is a 0.0, because there is no zero in my series?
SCATTER will round the limits up and down to allow reasonable looking labels.
ivory4 wrote:

Code: Select all

compute fract=%fractiles(bn,||.025,.975||)
compute bar = fract(1)
scatter(style=lines,$
header="Figure 3 ",hshade=||0.0,bar||) 1
# x bnd / 1
I want to shade the area left to 2.5%-ile point, but this would shade the whole area, I tried to add a vshade but only real is allowed as arguments. Is there any way to do that?
That should do what you want. It's possible that the range is so thin that you can't really see much shading. Try something like 10% first.
ivory4 wrote: how do I put text near the shade or in the shade or with an arrow?
Use SPGRAPH..SCATTER..GRTEXT..SPGRAPH(DONE) like

Code: Select all

set bn 1 2000 = %rangamma(5.0)
density(type=gauss) bn 1 2000 x bnd
compute fract=%fractiles(bn,||.025,.975||)
compute bar = fract(1)
spgraph
scatter(style=lines,$
header="Figure 3 ",hshade=||0.0,bar||) 1
# x bnd / 1
grtext(position=upleft) "description"
spgraph(done)
ivory4
Posts: 144
Joined: Mon Aug 24, 2009 12:16 pm

Re: density graph

Unread post by ivory4 »

How to shade the intersection of two density functions? If HSHADE(VSHADE) is used, it does not allow series as element, but only REAL.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: density graph

Unread post by TomDoan »

I'm not 100% sure of what you mean by the intersection, but see if this is what you want:

Code: Select all

set x  1 500 = .01*t
set f1 1 500 = %density((x-0.5)*4)
set f2 1 500 = %density((x-0.4)*9)
set minf = %min(f1,f2)
scatter(style=line,overlay=polygon,ovsame) 3
# x f1
# x f2
# x minf
ivory4
Posts: 144
Joined: Mon Aug 24, 2009 12:16 pm

Re: density graph

Unread post by ivory4 »

Yes I would like to shade the area left to 97.5quantile.I think i get it
ivory4
Posts: 144
Joined: Mon Aug 24, 2009 12:16 pm

Re: density graph

Unread post by ivory4 »

Looking at the histogram, it is quite concentrated to the left "tail", like a normal distribution with very high positve skewness.
To use option of GAUSS, it seems inappropriate.
What would be a good choice?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: density graph

Unread post by TomDoan »

ivory4 wrote:Looking at the histogram, it is quite concentrated to the left "tail", like a normal distribution with very high positve skewness.
To use option of GAUSS, it seems inappropriate.
What would be a good choice?
The shape of the kernel has very little to do with the shape of the density. Any of them should work reasonably well particularly with a target density that really has no particularly sharp features. The default of the Epanechnikov has certain optimality properties.
The only advantage of the Gaussian kernel over the others is that it's differentiable, which is important only if you need the derivative of the density, and you probably don't.
Post Reply