Package descriptive, working with frequency lists



Hi, Andreas

It's a common situation with statistical software. Your data can be
either raw sample or grouped data (a frequency table). One common
solution is t fake data from your frequency table, You can use a
one-liner for tht:


replicate(what, count):=block([i:?gensym(),a, n],
flatten(fullmapl(lambda([a,n], makelist(a,i,1,n)), what, count)))

then

(%i10)  v:[178, 179, 180, 181, 182]$

(%i11)  f:[2, 4, 5, 6, 3]$

(%i12) replicate(v,f);
(%o12) [178, 178, 179, 179, 179, 179, 180, 180, 180, 180, 180, 181, 181, 181,
                                                  181, 181, 181, 182, 182, 182]
(%i13)


--

Andrei Zorine

2012/12/11 Fotios Kasolis <fotios.kasolis at gmail.com>:
> This is just a code improvement (??) suggestion. If I get that rightly, I
> would do it the following way. Given a list with values v, and a list f with
> the corresponding frequencies i calculate the inner product v . f which is
> equivalent to v^T f and then divide by the sum apply("+", f), for your
> example
>
> v:[178, 179, 180, 181, 182]$
> f:[2, 4, 5, 6, 3]$
> m: v . f;
> 3604
> t: apply("+",f);
> 20
> m / t, numer;
> 180.2
>
> So i suggest you write your function so that it takes the two lists s, c in
> order to avoid the for loop and shorten your code
>
> frequ_mean(v, f) := block([],
> v . f / apply("+", f)
> )$
>
> Best regards,
> /Fotis
>
>
> On Tue, Dec 11, 2012 at 12:36 PM, Andreas Goebel <a-goebel at gmx.de> wrote:
>>
>> Hi,
>>
>> this is my first post here, so hello from me. I?m a math teacher at a
>> grammar school in germany.
>>
>> My students have to work with frequency lists, like this:
>>
>> Size 178 179 180 181 182
>> count 2 4 5 5 3
>>
>> While the package "descriptive" provides functions for computing mean,
>> standard deviation and so on for lists, it does not do so for frequency
>> lists. So my students would have to enter the list like this:
>> 178 178 179 179 179 179 ....
>>
>> which is not really an option.
>>
>> To solve this, I have tried a bit with the descriptive package and have
>> introduced a function frequ_mean like this:
>>
>> /* UNIVARIATE DESCRIPTIVE STATISTICS */
>>
>> /* Arithmetic mean for frequency list */
>> frequ_mean(x) := block([i,mean, total],
>> mean:0, total:0,
>> for i:1 thru length(x) do( block(
>> mean:mean+x[i][1]*x[i][2],
>> total:total+x[i][2]
>> ) ),
>> mean/total
>> )$
>> /* Arithmetic mean */
>> ....
>>
>> A test run:
>> /* [wxMaxima: input start ] */
>> l:[[178,2],[179,4],[180,5],[181,5],[182,3]];
>> /* [wxMaxima: input end ] */
>> /* [wxMaxima: input start ] */
>> load(descriptive);
>> /* [wxMaxima: input end ] */
>> /* [wxMaxima: input start ] */
>> frequ_mean(l);
>> /* [wxMaxima: input end ] */
>> /* [wxMaxima: input start ] */
>> float(%);
>> /* [wxMaxima: input end ] */
>>
>> gives a correct result.
>>
>>
>> So my questions are:
>> - does this make sense?
>> - should there be some checks to avoid errors, for instance if the list
>> has the wrong form?
>> - who maintains the descriptive package? Whould he / she like to
>> implement functions for frequency lists himself, or should I do that and
>> submit them (and if so, how?)?
>> - I would also need to draw histograms for data like that, but have no
>> idea at the moment how to achieve this
>>
>> Best regards,
>>
>> Andreas
>> _______________________________________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>