Given a frequency distribution, calculate a median

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Given a frequency distribution, calculate a median

apb218
Hi all,

A client is able to provide me with a frequency distribution but not the raw data for the number of seconds a video is streamed on different devices.  So the variables might be VideoName, Device, NumberOfSeconds, Frequency.  An example row would be Episode 1, iPad, 1 (second), 1000 (users streamed for 1 second).  The client wants to know the median number of seconds each video was streamed on each device (actually, it's more complicated than that, but that's the essence).  

Is there a way to do this in SPSS?  The client, for whatever reason, cannot provide the raw user-level data.  I think I have done what would seemingly be the reverse operation using the 'Restructure' command (I think it's the CASESTOVARS syntax), but I couldn't quite figure out how to use 'Restructure' for this purpose.  I ended up doing a lot of sorting and filesplitting and transforming the frequency variable as follows...

CREATE cumulativefrequency=CSUM(frequency).

...and then actually scrolling down the list to find the middle NumberofSeconds value for each VideoName/Device combo, but that was kind of painful and probably begging for an error on my part.

Help appreciated.

Thanks,

apb218
Reply | Threaded
Open this post in threaded view
|

Re: Given a frequency distribution, calculate a median

David Marso
Administrator
See in the Manual.
SORT.
SPLIT FILE.
WEIGHT.
FREQ.
A single sample row is not terribly informative here!!!
however consider the following:  
I will leave it to you to read up on SPLIT FILE for the rest of your task.
----
data list free/sec n.
begin data
1 100   2 150  3 200  4 500  5 200  6   30
end data.
WEIGHT BY n.
FREQUENCIES  VARIABLES=sec /STATISTICS=MEDIAN.

 




Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Given a frequency distribution, calculate a median

apb218
Thanks David.  Using the frequency as a weight - genius!