12c: Anyone have a good way to program this? :-) - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: 12c: Anyone have a good way to program this? :-) (/thread-84419.html) |
12c: Anyone have a good way to program this? :-) - Gene Wright - 12-16-2005 http://www.xycoon.com/dispersion.htm It is the "coefficient of dispersion". Given that it needs the median, this appears problematic for the HP12c. I would think it requires:
1) keeping all individual data values, That seems like a real pain. Any suggestions?
Re: 12c: Anyone have a good way to program this? :-) - hugh steers - 12-16-2005
if it must be the median, you have to store (at least) half of the input values. otherwise you can't be sure to have the n/2'th largest.
Re: 12c: Anyone have a good way to program this? :-) - Gene Wright - 12-16-2005 Yep. That's the problem! I'm pretty sure that the cash flow registers could be used, but to get the median, some sorting would have to occur, and on the HP12c, that's just painful. And, the number of data points would be variable, so you can't hard code for 10 of them each time.
Just wondering if anyone saw a way to do this without this much pain/suffering. Re: 12c: Anyone have a good way to program this? :-) - Vieira, Luiz C. (Brazil) - 12-16-2005 Hi Gene, folks;
1/r(inverse of the correlation coefficient)? If so, it is easier to compute through summations and linear regression. As I said, maybe I'm wrong. Cheers.
Luiz (Brazil)
Re: 12c: Anyone have a good way to program this? :-) - Namir - 12-16-2005 Why not use the ratio between the standard deviation and the mean? That should give you a good feel for the dispersion of data. As the other posts indicated, getting the median requires the storage and sorting of data. Maybe that's why statisticians use the mean more than the median, since you can accumulate data using a sequence of single observations (storage of ALL the data is not mandatory).
Namir
Re: 12c: Anyone have a good way to program this? :-) - Gene Wright - 12-17-2005 Luiz: I'll check on 1/r. Namir: I know there are plenty of measures of dispersion, but in this case, the individual wants this specific one, the formula for which requires the median. I just wanted to make sure I wasn't overlooking something. :-)
It's not too bad if you determine the median outside of the 12c and input it separately. But storing individual values and sorting them and then evaluating each of them for a variable number of data points? Yuck!
Re: 12c: Anyone have a good way to program this? :-) - Namir - 12-17-2005 Gene, I suggest using Excel to enter sample data (one or more sets) and then do the following:
1) Sort the column of data
You can test the above with several sets and see how the two statistics compare with each other.
Re: 12c: Anyone have a good way to program this? :-) - Joao - 12-17-2005 Gene, I guess with a 12c you are in big trouble... You can't escape the median, and doing it on the 12c is not practical at all. About the previous suggestions: a) the coefficient of dispersion is not 1/r (sorry Luiz). b) ratio between the standard deviation and the mean measures the same thing (actually, that is what is generally termed coefficient of dispersion), but it is not robust to outliers in the data. That is the advantage of using the median. I guess you either have to compute the median outside the machine or upgrade to a 15c! Sorry for the bad news.
Joao
Re: 12c: Anyone have a good way to program this? :-) - tony (nz) - 12-20-2005 Gene, Re: 12c: Anyone have a good way to program this? :-) - Valentin Albillo - 12-20-2005 Hi, Gene: Gene posted:
"I would think it requires:
Any suggestions?"
All of this is perfectly implementable in a few steps, and as the time required for the sort is distributed among the time required to input each element, it would feel faster to the user.
Best regards from V.
Re: 12c: Anyone have a good way to program this? :-) - Gene Wright - 12-21-2005 Hi Valentin! I'm certain that I'm not the only one who would really love to see what you can come up with (I already know Tony would too). You always have a way of finding unique, amazing solutions to problems like this and it would be very helpful/instructive to me (and others I'm sure) to see what you'd do with this problem. I have seen Tony's approach and it does about what I'd expect ( but certainly more optimized than I'd come up with)...it sorts, it uses the CF registers, etc.
But, I have no doubt a non-sorting approach would be very amazing. Please share? :-)
Re: 12c: Anyone have a good way to program this? :-) - Katie Wasserman - 12-21-2005 If we're talking about the good old basic 12C, I'm going to go out on a limb and suggest that it's going to be nearly impossible to do better than the bubble sort program that I wrote with picking the middle element after the sort completes. Insertion sort during input as Valentin suggest is no better than bubble sort as far as overall time is concerned and it might be more annoying to the user to have to wait an increasingly long time between entries. There are linear-time median algorithms but all require at least O(log(n)) additional memory and a good amount of programming complexity in that you'd have to simulate recursion.
Re: 12c: Anyone have a good way to program this? :-) - tony (nz) - 12-23-2005 Katie,
For fun, I took your 12C 21 liner below and changed it to do an
I needed 5 extra lines and 1 extra register. One could say
Insertion sorting does seem more efficient, even on the 12C.
Personally I still really like your Bubble sort - for me it is
---------------- Bubble Sort on HP12CCheers, Tony |