scatterplots using loops

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

scatterplots using loops

LUCINDA M TEAR
Hello,

I asked a similar question to this before and received wonderful help.  I am hoping I can ask again without imposing.

I want to be able to produce some cumulative frequency distributions for a variety of chemicals and have created sets 43 adjacent chemical concentrations (lchem 1 to lchem43) and their rank percentiles (per1 to per43) where they are ranked within a break variariable called chg2.

What I want to do is create 43 scatterplots of the concentration of each chemical vs. its cumulative percentile distribution.  

Apparently the loop function works only for transformations - I have tried this and get an error message.

Vector chem=lchem1 to lchem43.
Vector rank=per1 to per43.
LOOP #i = 1 TO 43.
GRAPH
  /SCATTERPLOT(BIVAR)=chem(#i) WITH rank(#i) BY CHG2
  /MISSING=LISTWISE
 /TEMPLATE='C:\Afolder\scatter.sct'.
END LOOP.

However, I am not sure how to convert this to a macro.....also, when I have successfully created macros using one variable, the macro does not seem to want to read the template command and also does not pick up my SET CTemplate command....

I greatly appreciate any pointers anyone can give!

Thank you,

Lucinda
Reply | Threaded
Open this post in threaded view
|

Re: scatterplots using loops

Mike P-5
If your going down the Macro route this is potentially a better chance
to start learning python, if you have V14 or V15.  Even though this
would be a simple macro.

Sorry this is untested, but it should have most of the things you want
in this, you may latter want to add titles and other things to this as
well, if this is the case, by using the GPL and a variable dictionary to
fill another list for titles it will make the code a lot more
parsimonious

Something like.

Begin Program.
Import spss, spssaux
QRanges = {(1,43)}
for i in QRanges:
        (start_var, end_var) = QRanges[i]
        ChemList = ['lchem%i' % ele for ele in range(start_var,
end_var+1)]
        RankList = ['per%i' % ele for ele in range(start_var,
end_var+1)]
        spss_correlations_tables = """GRAPH
        /SCATTERPLOT(BIVAR)=%s WITH rank%s BY CHG2
        /MISSING=LISTWISE
        /TEMPLATE='C:\Afolder\scatter.sct'.""" % (i,i,ChemList[i],
RankList[i])
        spss.Submit(spss_correlations_tables)
end program

HtH

Mike

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
LUCINDA M TEAR
Sent: 21 May 2007 19:12
To: [hidden email]
Subject: scatterplots using loops

Hello,

I asked a similar question to this before and received wonderful help.
I am hoping I can ask again without imposing.

I want to be able to produce some cumulative frequency distributions for
a variety of chemicals and have created sets 43 adjacent chemical
concentrations (lchem 1 to lchem43) and their rank percentiles (per1 to
per43) where they are ranked within a break variariable called chg2.

What I want to do is create 43 scatterplots of the concentration of each
chemical vs. its cumulative percentile distribution.

Apparently the loop function works only for transformations - I have
tried this and get an error message.

Vector chem=lchem1 to lchem43.
Vector rank=per1 to per43.
LOOP #i = 1 TO 43.
GRAPH
  /SCATTERPLOT(BIVAR)=chem(#i) WITH rank(#i) BY CHG2
  /MISSING=LISTWISE
 /TEMPLATE='C:\Afolder\scatter.sct'.
END LOOP.

However, I am not sure how to convert this to a macro.....also, when I
have successfully created macros using one variable, the macro does not
seem to want to read the template command and also does not pick up my
SET CTemplate command....

I greatly appreciate any pointers anyone can give!

Thank you,

Lucinda

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: scatterplots using loops

Bob Walker-2
In reply to this post by LUCINDA M TEAR
Hi Lucinda,

VECTOR is great for looping through *numerical* calculations on your vars. However, LOOP cannot be used to generate the syntax needed to run your scatterplot x 43 variables. A macro is perfect for this; here's an example taht you can adapt using four LCHEM and PER vars...

SET MEXPAND ON / PRI ON / MPRINT OFF.
DATA LIST FREE / LCHEM1 TO LCHEM4 PER1 TO PER4 (8F1).
BEGIN DATA
1 3 3 2 1 3 3 2
3 2 3 2 1 2 3 2
3 3 3 3 2 1 1 1
2 1 1 1 3 3 3 3
1 1 3 3 2 1 2 1
END DATA.

DEFINE !TEST ()
!DO !Z = 1 !TO 4
GRAPH /SCATTERPLOT(BIVAR)=!CONCAT("LCHEM",!Z) WITH !CONCAT("PER",!Z) /MISSING=LISTWISE.
!DOEND
!ENDDEFINE.

PRESERVE.
SET MPRINT ON.

!TEST.
RESTORE.

HTH,

Bob Walker
Surveys & Forecasts, LLC
www.safllc.com



----- Original Message -----
From: LUCINDA M TEAR
Date: Monday, May 21, 2007 2:14 pm
Subject: scatterplots using loops
To: [hidden email]

> Hello,
>
> I asked a similar question to this before and received wonderful
> help. I am hoping I can ask again without imposing.
>
> I want to be able to produce some cumulative frequency
> distributions for a variety of chemicals and have created sets
> 43 adjacent chemical concentrations (lchem 1 to lchem43) and
> their rank percentiles (per1 to per43) where they are ranked
> within a break variariable called chg2.
>
> What I want to do is create 43 scatterplots of the concentration
> of each chemical vs. its cumulative percentile distribution.
>
> Apparently the loop function works only for transformations - I
> have tried this and get an error message.
>
> Vector chem=lchem1 to lchem43.
> Vector rank=per1 to per43.
> LOOP #i = 1 TO 43.
> GRAPH
> /SCATTERPLOT(BIVAR)=chem(#i) WITH rank(#i) BY CHG2
> /MISSING=LISTWISE
> /TEMPLATE='C:\Afolder\scatter.sct'.
> END LOOP.
>
> However, I am not sure how to convert this to a macro.....also,
> when I have successfully created macros using one variable, the
> macro does not seem to want to read the template command and
> also does not pick up my SET CTemplate command....
>
> I greatly appreciate any pointers anyone can give!
>
> Thank you,
>
> Lucinda
>

 Bob Walker
Surveys & Forecasts, LLC
www.safllc.com