Calculating a mean within a vector

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

Calculating a mean within a vector

TimBakers
Dear all,

I'm fairly new to spss so please forgive me if i'm over or undercomplicating this problem..

I am trying to calculate 5 means per testsubject in my spss datafile (i have over 550 subjects).
These means represent time periods from start to finish and my goal is to do a repeated measure on this data.
It is the case that not all test subjects have recieved the same amount of scores over the entire period, some have over a 100, while others have less than 20 for example.
I still want to obtain 5 mean scores per subject, so this means for a person with a 100 scores i will have to average 20 scores per period, while a subject with 20 scores only needs 4 scores per period.

my thought was to create a vector of all the scores (scores 1 to 116 with 116 being the maximum amount of scores 1 person has obtained. This vector is called "Gesprekstevredenheid"

I have also created an interval index which comes down to the total amount of scores recieved, devided by 5, to indicate how many scores per period need to be averaged per person. this variable is called Interval_AFG.

my syntax so far...

Vector Gesprekstevredenheid = Gesprekstevredenheid.1 to Gesprekstevredenheid.116 .
Vector Meting = Meting1 to Meting5 .

loop b = 1 to 5.
compute meting(b) = mean (Gesprekstevredenheid((Interval_AFG*b)-(Interval_AFG-1)) TO Gesprekstevredenheid(Interval_AFG*b)) .
end loop .
EXECUTE .

Meting 1 to 5 are the variables i want to put the averages per period. The math part seems to work ((Interval_AFG*b)-(Interval_AFG-1)), (Interval_AFG*b)), but I keep getting error messages about the TO oparator between the two vectorindexes. I have come to the conclusion that a TO oparator does not work when working with a vector (because if I use normal variables instead the code works), but I have totally no clue how to do it otherwise..

If someone has an idea what to typ instead of the TO operator, or an entirely new way of doing what I am intending to do, you help would be very very welcome...

Best regards, Tim

Reply | Threaded
Open this post in threaded view
|

Re: Calculating a mean within a vector

David Marso
Administrator
Add an inner loop and manually calculate your means.
Vector Gesprekstevredenheid = Gesprekstevredenheid.1 to Gesprekstevredenheid.116 .
Vector Meting(5).
***NOT  Vector= Meting1 to Meting5 (unless these already exist).
<aircode>
LOOP b=1 to 5.
+  compute Interval_AFG=whatever......
+  COMPUTE mysum=0.
+  compute myN=0.
+  LOOP c=(Interval_AFG*b)-(Interval_AFG-1) TO Interval_AFG*b.
+        compute mysum=mysum+Gesprekstevredenheid(c).
+        compute myN=myN+1.
+  END LOOP.
+  COMPUTE meting(b) =mysum/myn.
END LOOP.

TimBakers wrote
Dear all,

I'm fairly new to spss so please forgive me if i'm over or undercomplicating this problem..

I am trying to calculate 5 means per testsubject in my spss datafile (i have over 550 subjects).
These means represent time periods from start to finish and my goal is to do a repeated measure on this data.
It is the case that not all test subjects have recieved the same amount of scores over the entire period, some have over a 100, while others have less than 20 for example.
I still want to obtain 5 mean scores per subject, so this means for a person with a 100 scores i will have to average 20 scores per period, while a subject with 20 scores only needs 4 scores per period.

my thought was to create a vector of all the scores (scores 1 to 116 with 116 being the maximum amount of scores 1 person has obtained. This vector is called "Gesprekstevredenheid"

I have also created an interval index which comes down to the total amount of scores recieved, devided by 5, to indicate how many scores per period need to be averaged per person. this variable is called Interval_AFG.

my syntax so far...

Vector Gesprekstevredenheid = Gesprekstevredenheid.1 to Gesprekstevredenheid.116 .
Vector Meting = Meting1 to Meting5 .

loop b = 1 to 5.
compute meting(b) = mean (Gesprekstevredenheid((Interval_AFG*b)-(Interval_AFG-1)) TO Gesprekstevredenheid(Interval_AFG*b)) .
end loop .
EXECUTE .

Meting 1 to 5 are the variables i want to put the averages per period. The math part seems to work ((Interval_AFG*b)-(Interval_AFG-1)), (Interval_AFG*b)), but I keep getting error messages about the TO oparator between the two vectorindexes. I have come to the conclusion that a TO oparator does not work when working with a vector (because if I use normal variables instead the code works), but I have totally no clue how to do it otherwise..

If someone has an idea what to typ instead of the TO operator, or an entirely new way of doing what I am intending to do, you help would be very very welcome...

Best regards, Tim
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: Calculating a mean within a vector

TimBakers
Hey David

Thanks for your swift reply! You entirely solved the problem thank you!
As I was reading your reply I was like "OOH ofcourse!!", but I could never have figured this out myself!

Thanks again!

Best regards, Tim