Fwd: Re: Package descriptive, working with frequency lists
Subject: Fwd: Re: Package descriptive, working with frequency lists
From: Andreas Goebel
Date: Fri, 14 Dec 2012 17:01:01 +0100
Am 11.12.2012 15:56, schrieb Jaime Villate:
>>
> Here is a suggestion:
>
> histogram(data):=
> block([xmin:first(data)[1]-1,xmax:last(data)[1]+1,ymax:0,h:[]],
> for p in data do
>
> (h:cons(['discrete,[p[1]-1/2,p[1]-1/2,p[1]+1/2,p[1]+1/2],[0,p[2],p[2],0]],h),
> if p[2] > ymax then ymax: p[2]),
> plot2d
> (h,['x,xmin,xmax],['y,0,ymax+1],[xlabel,"value"],[ylabel,"count"],
> [legend,false],[color,blue]))$
>
> histogram([[178,2],[179,4],[180,5],[181,5],[182,3]]);
>
Thank you!
I have improved that a bit. I think I can assume that the intervals are
equally spaced, but the interval length won?t be 1 usually.
So now it goes like this, what do you think?
histogram(data):=
block([dx:
data[2][1]-data[1][1],xmin:first(data)[1]-dx,xmax:last(data)[1]+dx,ymax:0,h:[]],
for p in data do
(h:cons(['discrete,[p[1]-1/2*dx,p[1]-1/2*dx,p[1]+1/2*dx,p[1]+1/2*dx],[0,p[2],p[2],0]],h),
if p[2] > ymax then ymax: p[2]),
plot2d (h,['x,xmin,xmax],['y,0,ymax+1],[xlabel,"value"],[ylabel,"count"],
[legend,false],[color,blue]))$
Best regards,
Andreas