Fwd: Re: Package descriptive, working with frequency lists



El vie, 14-12-2012 a las 17:01 +0100, Andreas Goebel escribi?:
> 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

As a simple solution for this problem I have added function build_sample
to package descriptive. It creates the complete sample from the table of
absolute frequencies, as someone suggested in this thread. The table is
introduced as a matrix or list of equal sized lists.

The returned sample is always in matrix format. This works in the
univariate case:

display2d:false $
sam1: build_sample([[6,4], [j,2], [2,1],[8,2],[1,2]]);
mean(sam1);
barsplot(sam1);

as well in the multivariate case:

sam2: build_sample([[6,3,4], [5,6,2], [u,2,1],[6,8,2]]) ;
cov(sam2); /* covariance matrix */
barsplot(sam2, grouping=stacked);


I think this is an acceptable solution and does not need to re-write a
lot of descriptive functions to maintain global coherence with the rest
of the package.

In any case, Andreas, if you prefer specific functions for frequency
tables, and you think I(we) can help, do not hesitate to send me(us) a
post.

Viel Glueck!
--
Mario