Poisson regression: univariate vs multivariate

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

Poisson regression: univariate vs multivariate

Ed Hanna
How do I run univariate and multivariate poisson models in SPSS 15 or
16?  Can anyone recommend a good annoutated source?

Thanks,
Ed

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Poisson regression: univariate vs multivariate

Marta Garcia-Granero
Hi Ed:
> How do I run univariate and multivariate poisson models in SPSS 15 or
> 16?  Can anyone recommend a good annoutated source?
>
This topic was discussed time ago (november 2006), and here is the code,
with a clasic sample dataset.

DATA LIST list /id(F2.0) agegroup(F8.0) smoker(F1.0) pyears(F8.0)
deaths(F4.0).
BEGIN DATA
1 0 0 18790   2
2 1 0 10673  12
3 2 0  5712  28
4 3 0  2585  28
5 4 0  1462  31
6 0 1 52407  32
7 1 1 43248 104
8 2 1 28612 206
9 3 1 12663 186
10 4 1 5317 102
END DATA.
DOCUMENT 'Coronary deaths from British male doctors. Doll & Hill
          (Nat Cancer Inst Monog 1996; 19:205-68)'.
VARIABLE LABELS agegroup "Age group".
VALUE LABELS agegroup
 0 "35-44 years"
 1 "45-54 years"
 2 "55-64 years"
 3 "65-74 years"
 4 "75-84 years".
VARIABLE LABELS smoker "Smoking status".
VALUE LABELS smoker
 0 "No"
 1 "Yes".

* Dummy coding (indicator(first)) agegroup *.
DO REPEAT A=1 2 3 4 /B=agegrp1 agegrp2 agegrp3 agegrp4.
- COMPUTE B=(agegroup=A).
END REPEAT.

* Using SPSS 15 - GENLIN *.
COMPUTE logpyears=LN(pyears).
GENLIN deaths
  BY agegroup smoker
  (ORDER=DESCENDING)
 /MODEL agegroup smoker
  INTERCEPT=YES
  OFFSET=logpyears
  DISTRIBUTION=POISSON
  LINK=LOG
 /PRINT SOLUTION(EXPONENTIATED).

HTH,
Marta García-Granero

--
For miscellaneous statistical stuff, visit:
http://gjyp.nl/marta/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Poisson regression: univariate vs multivariate - adendum

Marta Garcia-Granero
In reply to this post by Ed Hanna
Forget the dummy coding for agegrp.  That part of the code was used only
when using GENLOG  instead of GENLIN. I copy-pasted the code from a file
that compared both methods, and forgot to eliminate the dummy coding.

Regards,
Marta


--
For miscellaneous statistical stuff, visit:
http://gjyp.nl/marta/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Poisson regression:

Jeff Stuewig
In reply to this post by Marta Garcia-Granero
        I had a question about the syntax Marta posted awhile back.  I want
to predict number of behavioral incidents while incarcerated.  Because of
the distribution of the dependent variable it seems that Poisson or negative
binomial regression is the best option. We want to control for time
incarcerated which seems to correspond to the "offset" variable below.

        I'm not sure I understand what "offset" exactly means and why one
would use that instead of just entering 'time' as a covariate?  Also why is
it log transformed?  Thoughts and/or references to beginning articles about
Poisson regression would be much appreciated.  Thanks.

                Jeff


> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
> Marta García-Granero
> Sent: Thursday, July 03, 2008 1:54 PM
> To: [hidden email]
> Subject: Re: Poisson regression: univariate vs multivariate
>
> Hi Ed:
> > How do I run univariate and multivariate poisson models in SPSS 15 or
> > 16?  Can anyone recommend a good annoutated source?
> >
> This topic was discussed time ago (november 2006), and here is the code,
> with a clasic sample dataset.
>
> DATA LIST list /id(F2.0) agegroup(F8.0) smoker(F1.0) pyears(F8.0)
> deaths(F4.0).
> BEGIN DATA
> 1 0 0 18790   2
> 2 1 0 10673  12
> 3 2 0  5712  28
> 4 3 0  2585  28
> 5 4 0  1462  31
> 6 0 1 52407  32
> 7 1 1 43248 104
> 8 2 1 28612 206
> 9 3 1 12663 186
> 10 4 1 5317 102
> END DATA.
> DOCUMENT 'Coronary deaths from British male doctors. Doll & Hill
>           (Nat Cancer Inst Monog 1996; 19:205-68)'.
> VARIABLE LABELS agegroup "Age group".
> VALUE LABELS agegroup
>  0 "35-44 years"
>  1 "45-54 years"
>  2 "55-64 years"
>  3 "65-74 years"
>  4 "75-84 years".
> VARIABLE LABELS smoker "Smoking status".
> VALUE LABELS smoker
>  0 "No"
>  1 "Yes".
>
> * Dummy coding (indicator(first)) agegroup *.
> DO REPEAT A=1 2 3 4 /B=agegrp1 agegrp2 agegrp3 agegrp4.
> - COMPUTE B=(agegroup=A).
> END REPEAT.
>
> * Using SPSS 15 - GENLIN *.
> COMPUTE logpyears=LN(pyears).
> GENLIN deaths
>   BY agegroup smoker
>   (ORDER=DESCENDING)
>  /MODEL agegroup smoker
>   INTERCEPT=YES
>   OFFSET=logpyears
>   DISTRIBUTION=POISSON
>   LINK=LOG
>  /PRINT SOLUTION(EXPONENTIATED).
>
> HTH,
> Marta García-Granero
>
> --
> For miscellaneous statistical stuff, visit:
> http://gjyp.nl/marta/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Poisson regression:

Marta Garcia-Granero
Jeff Stuewig escribió:

>         I had a question about the syntax Marta posted awhile back.  I want
> to predict number of behavioral incidents while incarcerated.  Because of
> the distribution of the dependent variable it seems that Poisson or negative
> binomial regression is the best option. We want to control for time
> incarcerated which seems to correspond to the "offset" variable below.
>
>         I'm not sure I understand what "offset" exactly means and why one
> would use that instead of just entering 'time' as a covariate?  Also why is
> it log transformed?  Thoughts and/or references to beginning articles about
> Poisson regression would be much appreciated.
>
Campbell, "Statistis at Square Two". I have to leave right now, but in
acouple of hours I'll be back, and I'll send you the chapter dedicated
to poisson regression (I have to scan the pages).

Best regards,
Marta

>> -----Original Message-----
>> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
>> Marta García-Granero
>> Sent: Thursday, July 03, 2008 1:54 PM
>> To: [hidden email]
>> Subject: Re: Poisson regression: univariate vs multivariate
>>
>> Hi Ed:
>>
>>> How do I run univariate and multivariate poisson models in SPSS 15 or
>>> 16?  Can anyone recommend a good annoutated source?
>>>
>>>
>> This topic was discussed time ago (november 2006), and here is the code,
>> with a clasic sample dataset.
>>
>> DATA LIST list /id(F2.0) agegroup(F8.0) smoker(F1.0) pyears(F8.0)
>> deaths(F4.0).
>> BEGIN DATA
>> 1 0 0 18790   2
>> 2 1 0 10673  12
>> 3 2 0  5712  28
>> 4 3 0  2585  28
>> 5 4 0  1462  31
>> 6 0 1 52407  32
>> 7 1 1 43248 104
>> 8 2 1 28612 206
>> 9 3 1 12663 186
>> 10 4 1 5317 102
>> END DATA.
>> DOCUMENT 'Coronary deaths from British male doctors. Doll & Hill
>>           (Nat Cancer Inst Monog 1996; 19:205-68)'.
>> VARIABLE LABELS agegroup "Age group".
>> VALUE LABELS agegroup
>>  0 "35-44 years"
>>  1 "45-54 years"
>>  2 "55-64 years"
>>  3 "65-74 years"
>>  4 "75-84 years".
>> VARIABLE LABELS smoker "Smoking status".
>> VALUE LABELS smoker
>>  0 "No"
>>  1 "Yes".
>>
>> * Dummy coding (indicator(first)) agegroup *.
>> DO REPEAT A=1 2 3 4 /B=agegrp1 agegrp2 agegrp3 agegrp4.
>> - COMPUTE B=(agegroup=A).
>> END REPEAT.
>>
>> * Using SPSS 15 - GENLIN *.
>> COMPUTE logpyears=LN(pyears).
>> GENLIN deaths
>>   BY agegroup smoker
>>   (ORDER=DESCENDING)
>>  /MODEL agegroup smoker
>>   INTERCEPT=YES
>>   OFFSET=logpyears
>>   DISTRIBUTION=POISSON
>>   LINK=LOG
>>  /PRINT SOLUTION(EXPONENTIATED).
>>
>> HTH,
>> Marta García-Granero
>>
>> --
>> For miscellaneous statistical stuff, visit:
>> http://gjyp.nl/marta/
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>> [hidden email] (not to SPSSX-L), with no body text except the
>> command. To leave the list, send the command
>> SIGNOFF SPSSX-L
>> For a list of commands to manage subscriptions, send the command
>> INFO REFCARD
>>
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>


--
For miscellaneous statistical stuff, visit:
http://gjyp.nl/marta/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Poisson regression:

Reutter, Alex
In reply to this post by Jeff Stuewig
Jeff,

The help for Generalized Linear Models (click Help on the Predictors tab of the dialog) explains the offset as follows:
"
Offset. The offset term is a "structural" predictor. Its coefficient is not estimated by the model but is assumed to have the value 1; thus, the values of the offset are simply added to the linear predictor of the dependent variable. This is especially useful in Poisson regression models, where each case may have different levels of exposure to the event of interest. For example, when modeling accident rates for individual drivers, there is an important difference between a driver who has been at fault in one accident in three years of experience and a driver who has been at fault in one accident in 25 years! The number of accidents can be modeled as a Poisson response if the experience of the driver is included as an offset term.
"

The case study analyzing Ship Damage Rates (click the "Show Me" link in the main help topic) also gives the following information:
"
Modeling the raw cell counts can be misleading in this situation because the Aggregate months of service varies by ship type. Variables like this that measure the amount of "exposure" to risk are handled within the generalized linear model as offset variables. Moreover, a Poisson regression assumes that the log of the dependent variable is linear in the predictors. Thus, to use generalized linear models to fit a Poisson regression to the accident rates, you need to use Logarithm of aggregate months of service.
"

Cheers,
Alex


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jeff Stuewig
Sent: Tuesday, September 09, 2008 12:38 PM
To: [hidden email]
Subject: Re: Poisson regression:

        I had a question about the syntax Marta posted awhile back.  I want
to predict number of behavioral incidents while incarcerated.  Because of
the distribution of the dependent variable it seems that Poisson or negative
binomial regression is the best option. We want to control for time
incarcerated which seems to correspond to the "offset" variable below.

        I'm not sure I understand what "offset" exactly means and why one
would use that instead of just entering 'time' as a covariate?  Also why is
it log transformed?  Thoughts and/or references to beginning articles about
Poisson regression would be much appreciated.  Thanks.

                Jeff


> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
> Marta García-Granero
> Sent: Thursday, July 03, 2008 1:54 PM
> To: [hidden email]
> Subject: Re: Poisson regression: univariate vs multivariate
>
> Hi Ed:
> > How do I run univariate and multivariate poisson models in SPSS 15 or
> > 16?  Can anyone recommend a good annoutated source?
> >
> This topic was discussed time ago (november 2006), and here is the code,
> with a clasic sample dataset.
>
> DATA LIST list /id(F2.0) agegroup(F8.0) smoker(F1.0) pyears(F8.0)
> deaths(F4.0).
> BEGIN DATA
> 1 0 0 18790   2
> 2 1 0 10673  12
> 3 2 0  5712  28
> 4 3 0  2585  28
> 5 4 0  1462  31
> 6 0 1 52407  32
> 7 1 1 43248 104
> 8 2 1 28612 206
> 9 3 1 12663 186
> 10 4 1 5317 102
> END DATA.
> DOCUMENT 'Coronary deaths from British male doctors. Doll & Hill
>           (Nat Cancer Inst Monog 1996; 19:205-68)'.
> VARIABLE LABELS agegroup "Age group".
> VALUE LABELS agegroup
>  0 "35-44 years"
>  1 "45-54 years"
>  2 "55-64 years"
>  3 "65-74 years"
>  4 "75-84 years".
> VARIABLE LABELS smoker "Smoking status".
> VALUE LABELS smoker
>  0 "No"
>  1 "Yes".
>
> * Dummy coding (indicator(first)) agegroup *.
> DO REPEAT A=1 2 3 4 /B=agegrp1 agegrp2 agegrp3 agegrp4.
> - COMPUTE B=(agegroup=A).
> END REPEAT.
>
> * Using SPSS 15 - GENLIN *.
> COMPUTE logpyears=LN(pyears).
> GENLIN deaths
>   BY agegroup smoker
>   (ORDER=DESCENDING)
>  /MODEL agegroup smoker
>   INTERCEPT=YES
>   OFFSET=logpyears
>   DISTRIBUTION=POISSON
>   LINK=LOG
>  /PRINT SOLUTION(EXPONENTIATED).
>
> HTH,
> Marta García-Granero
>
> --
> For miscellaneous statistical stuff, visit:
> http://gjyp.nl/marta/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Manually tweaking a chart template (.sgt)

Marta Garcia-Granero
Hi everybody

I'm trying to build a chart template (with SPSS 15) to make this graph
the way it should:

data list list/time (f8) sj lower upper (f8.1).
begin data
0    1    1    1
9    .985    .954    .995
10    .980    .947    .992
11    .975    .940    .989
12    .970    .933    .986
13    .964    .927    .983
14    .959    .920    .979
15    .954    .914    .976
16    .949    .908    .972
17    .939    .895    .965
21    .924    .877    .953
22    .908    .858    .941
23    .888    .835    .925
24    .883    .829    .920
29    .872    .817    .912
31    .867    .811    .908
33    .857    .800    .899
34    .836    .777    .881
35    .831    .771    .877
36    .821    .760    .868
37    .816    .754    .863
40    .811    .748    .859
41    .805    .743    .854
45    .800    .737    .850
46    .790    .726    .841
47    .779    .714    .831
51    .773    .708    .826
55    .763    .695    .818
56    .752    .680    .810
57    .738    .662    .800
58    .704    .615    .776
end data.

GRAPH /SCATTERPLOT(OVERLAY)=time WITH sj lower upper
 /TITLE='KM estimate with Kalbfleish-Prentice 95%CI'
 /TEMPLATE='C:\Temp\KPSurvival.sgt'.

This chart template, along with the code, is part of a big macro that
computes Kalbfleish-Prentice 95%CI for survival estimates and plots them
(just in case someone is wondering what's the use of all this code).

Basically, I have succeeded  in:

- Adding titles to x axis ("follow-up time") and y axis ("Cumulative
survival") (that required manual editing of the chart template, I found
no way of adding the titles to the graph directly)
- Adding interpolation lines (left step) to the three sets of data (time
WITH sj, time WITH lower and time WITH upper)
- Modifying the range and increment for y axis (from 0 to 1, delta=0.1)
- Hiding the scatter dots (they insisted in showing up as 5 pixel
diameter circles, even if I modified the graph to hide them and saved a
chart template afterwards) I had to manually tweak the template for that
too (lots of trial&error).

But... although I have manually edited the graph to change the
interpolation lines from blue, green and dusty to: solid line, black, 2
pixels (for "time WITH sj") and dashed line, black 1 pixel (for both
"time WITH lower" and "time WITH upper"), these modifications are
nowhere to be seen inside the chart template (at least to my untrained
eyes), and don't get applied to new graphs (although I'm sure I selected
everything that could be selected to be saved in the chart template). Is
there a way to add that instructions to it? Second item: since the chart
template will be dynamically created by the macro (using WRITE
OUTFILE='C:\Temp\KPSurvival.sgt'..........), is there any redundant line
that could be safely erased?

Any help/advice will be greatly appreciated,
Marta

*************

So far, my chart template has the following (rather difficult to
understand, BTW) lines:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template SPSS-Version="1.4" date="2008-09-10" description=""
selectPath="87 80 12 13 17 18 19 47 43 "
xmlns="http://xml.spss.com/spss/visualization"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xml.spss.com/spss/visualization
http://xml.spss.com/spss/visualization/vizml-template-3.0.xsd">
    <setAxisInterval lowerMapping="exact" max="1.0" min="0.0" role="y"
upperMapping="exact"/>
    <setAxisMajorTicks>
        <majorTicks categorical="false" delta="0.1" derived="false"
position="outside" role="y">
            <markStyle>
                <style color="#000000" stroke-width="1pt" visible="true"/>
            </markStyle>
            <tickLabelStyle>
                <style color="#000000" font-size="8pt" visible="true"/>
            </tickLabelStyle>
        </majorTicks>
    </setAxisMajorTicks>
    <setAxisMinorTicks>
        <minorTicks categorical="false" derived="false" number="2"
position="outside" role="y">
            <markStyle>
                <style color="#000000" visible="true"/>
            </markStyle>
        </minorTicks>
    </setAxisMinorTicks>
    <setAxisStyle categorical="false" role="y">
        <label>Cumulative Survival</label>
        <axisLabelStyle>
            <style color="#000000" color2="transparent" font-size="11pt"
font-weight="bold" labelLocationHorizontal="center"
labelLocationVertical="center" visible="true"/>
        </axisLabelStyle>
    </setAxisStyle>
    <setAxisStyle categorical="false" role="x">
        <label>Follow-up time</label>
        <axisLabelStyle>
            <style color="#000000" color2="transparent" font-size="11pt"
font-weight="bold" labelLocationHorizontal="center"
labelLocationVertical="center" visible="true"/>
        </axisLabelStyle>
    </setAxisStyle>
    <setAxisMargin categorical="false" lowerMargin="0%" role="x"
upperMargin="5%"/>
    <setAxisMargin categorical="false" lowerMargin="0%" role="y"
upperMargin="5%"/>
    <addInterpolationLine>
        <interpolation missingRepresentation="wings"
pointPosition="left" type="step"/>
        <style color="#000000" visible="true" width="1pt"/>
    </addInterpolationLine>
    <addFrame count="1" styleOnly="true" type="legend">
        <style color="transparent" color2="transparent" visible="false"/>
        <style color="transparent" color2="transparent" number="0"
visible="false"/>
    </addFrame>
    <addFrame count="1" styleOnly="true" type="visualization">
        <style color="#ffffff" color2="transparent" number="0"
visible="true"/>
        <style font-family="SansSerif" font-size="8pt" number="1"
pattern="0" stroke-linecap="butt" text-fit="true" visible="true"/>
    </addFrame>
    <addFrame count="1" styleOnly="true" type="graph">
        <style color="transparent" color2="transparent" visible="true"/>
        <style color="#ffffff" color2="#ffffff" number="1" visible="true"/>
    </addFrame>
    <addFrame count="1" styleOnly="true" type="title">
        <style color="transparent" color2="transparent" visible="true"/>
    </addFrame>
    <setShowLineMarkers>
        <style color="transparent" color2="#000000" size="1pt"
symbol="circle" visible="false"/>
    </setShowLineMarkers>
    <setStyle subtype="simple" type="line">
        <style color="#000000" visible="true" width="2pt"/>
    </setStyle>
    <setStyle subtype="simple" type="scatter">
        <style color="transparent" color2="#000000" size="5pt"
symbol="circle" visible="false"/>
    </setStyle>
    <setStyleCycle id="styleCycleDefault" styleByNumber="1">
        <cycle>
            <style color="#000000" color2="#000000" glyph-angle="90.0"
size="2px" symbol="line" visible="true"/>
            <style color="#000000" color2="#000000" glyph-angle="90.0"
size="1px" symbol="line" visible="true"/>
            <style color="#000000" color2="#000000" glyph-angle="90.0"
size="1px" symbol="line" visible="true"/>
        </cycle>
    </setStyleCycle>
    <setStyleCycle id="styleCycle_4160" styleByNumber="1">
        <cycle>
            <style color="#000000" stroke-width="2pt" visible="true"/>
            <style color="#000000" stroke-dasharray="3px,2px"
visible="true"/>
            <style color="#000000" stroke-dasharray="3px,2px"
visible="true"/>
        </cycle>
    </setStyleCycle>
</template>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Manually tweaking a chart template (.sgt)

ViAnn Beadle
It sounds like quite a bit of this can be done using GGRAPH directly without
relying upon the template. If you send me a picture of what you want this
chart to look like I'll give it a try.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Marta García-Granero
Sent: Wednesday, September 10, 2008 10:46 AM
To: [hidden email]
Subject: Manually tweaking a chart template (.sgt)

Hi everybody

I'm trying to build a chart template (with SPSS 15) to make this graph
the way it should:

data list list/time (f8) sj lower upper (f8.1).
begin data
0    1    1    1
9    .985    .954    .995
10    .980    .947    .992
11    .975    .940    .989
12    .970    .933    .986
13    .964    .927    .983
14    .959    .920    .979
15    .954    .914    .976
16    .949    .908    .972
17    .939    .895    .965
21    .924    .877    .953
22    .908    .858    .941
23    .888    .835    .925
24    .883    .829    .920
29    .872    .817    .912
31    .867    .811    .908
33    .857    .800    .899
34    .836    .777    .881
35    .831    .771    .877
36    .821    .760    .868
37    .816    .754    .863
40    .811    .748    .859
41    .805    .743    .854
45    .800    .737    .850
46    .790    .726    .841
47    .779    .714    .831
51    .773    .708    .826
55    .763    .695    .818
56    .752    .680    .810
57    .738    .662    .800
58    .704    .615    .776
end data.

GRAPH /SCATTERPLOT(OVERLAY)=time WITH sj lower upper
 /TITLE='KM estimate with Kalbfleish-Prentice 95%CI'
 /TEMPLATE='C:\Temp\KPSurvival.sgt'.

This chart template, along with the code, is part of a big macro that
computes Kalbfleish-Prentice 95%CI for survival estimates and plots them
(just in case someone is wondering what's the use of all this code).

Basically, I have succeeded  in:

- Adding titles to x axis ("follow-up time") and y axis ("Cumulative
survival") (that required manual editing of the chart template, I found
no way of adding the titles to the graph directly)
- Adding interpolation lines (left step) to the three sets of data (time
WITH sj, time WITH lower and time WITH upper)
- Modifying the range and increment for y axis (from 0 to 1, delta=0.1)
- Hiding the scatter dots (they insisted in showing up as 5 pixel
diameter circles, even if I modified the graph to hide them and saved a
chart template afterwards) I had to manually tweak the template for that
too (lots of trial&error).

But... although I have manually edited the graph to change the
interpolation lines from blue, green and dusty to: solid line, black, 2
pixels (for "time WITH sj") and dashed line, black 1 pixel (for both
"time WITH lower" and "time WITH upper"), these modifications are
nowhere to be seen inside the chart template (at least to my untrained
eyes), and don't get applied to new graphs (although I'm sure I selected
everything that could be selected to be saved in the chart template). Is
there a way to add that instructions to it? Second item: since the chart
template will be dynamically created by the macro (using WRITE
OUTFILE='C:\Temp\KPSurvival.sgt'..........), is there any redundant line
that could be safely erased?

Any help/advice will be greatly appreciated,
Marta

*************

So far, my chart template has the following (rather difficult to
understand, BTW) lines:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template SPSS-Version="1.4" date="2008-09-10" description=""
selectPath="87 80 12 13 17 18 19 47 43 "
xmlns="http://xml.spss.com/spss/visualization"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xml.spss.com/spss/visualization
http://xml.spss.com/spss/visualization/vizml-template-3.0.xsd">
    <setAxisInterval lowerMapping="exact" max="1.0" min="0.0" role="y"
upperMapping="exact"/>
    <setAxisMajorTicks>
        <majorTicks categorical="false" delta="0.1" derived="false"
position="outside" role="y">
            <markStyle>
                <style color="#000000" stroke-width="1pt" visible="true"/>
            </markStyle>
            <tickLabelStyle>
                <style color="#000000" font-size="8pt" visible="true"/>
            </tickLabelStyle>
        </majorTicks>
    </setAxisMajorTicks>
    <setAxisMinorTicks>
        <minorTicks categorical="false" derived="false" number="2"
position="outside" role="y">
            <markStyle>
                <style color="#000000" visible="true"/>
            </markStyle>
        </minorTicks>
    </setAxisMinorTicks>
    <setAxisStyle categorical="false" role="y">
        <label>Cumulative Survival</label>
        <axisLabelStyle>
            <style color="#000000" color2="transparent" font-size="11pt"
font-weight="bold" labelLocationHorizontal="center"
labelLocationVertical="center" visible="true"/>
        </axisLabelStyle>
    </setAxisStyle>
    <setAxisStyle categorical="false" role="x">
        <label>Follow-up time</label>
        <axisLabelStyle>
            <style color="#000000" color2="transparent" font-size="11pt"
font-weight="bold" labelLocationHorizontal="center"
labelLocationVertical="center" visible="true"/>
        </axisLabelStyle>
    </setAxisStyle>
    <setAxisMargin categorical="false" lowerMargin="0%" role="x"
upperMargin="5%"/>
    <setAxisMargin categorical="false" lowerMargin="0%" role="y"
upperMargin="5%"/>
    <addInterpolationLine>
        <interpolation missingRepresentation="wings"
pointPosition="left" type="step"/>
        <style color="#000000" visible="true" width="1pt"/>
    </addInterpolationLine>
    <addFrame count="1" styleOnly="true" type="legend">
        <style color="transparent" color2="transparent" visible="false"/>
        <style color="transparent" color2="transparent" number="0"
visible="false"/>
    </addFrame>
    <addFrame count="1" styleOnly="true" type="visualization">
        <style color="#ffffff" color2="transparent" number="0"
visible="true"/>
        <style font-family="SansSerif" font-size="8pt" number="1"
pattern="0" stroke-linecap="butt" text-fit="true" visible="true"/>
    </addFrame>
    <addFrame count="1" styleOnly="true" type="graph">
        <style color="transparent" color2="transparent" visible="true"/>
        <style color="#ffffff" color2="#ffffff" number="1" visible="true"/>
    </addFrame>
    <addFrame count="1" styleOnly="true" type="title">
        <style color="transparent" color2="transparent" visible="true"/>
    </addFrame>
    <setShowLineMarkers>
        <style color="transparent" color2="#000000" size="1pt"
symbol="circle" visible="false"/>
    </setShowLineMarkers>
    <setStyle subtype="simple" type="line">
        <style color="#000000" visible="true" width="2pt"/>
    </setStyle>
    <setStyle subtype="simple" type="scatter">
        <style color="transparent" color2="#000000" size="5pt"
symbol="circle" visible="false"/>
    </setStyle>
    <setStyleCycle id="styleCycleDefault" styleByNumber="1">
        <cycle>
            <style color="#000000" color2="#000000" glyph-angle="90.0"
size="2px" symbol="line" visible="true"/>
            <style color="#000000" color2="#000000" glyph-angle="90.0"
size="1px" symbol="line" visible="true"/>
            <style color="#000000" color2="#000000" glyph-angle="90.0"
size="1px" symbol="line" visible="true"/>
        </cycle>
    </setStyleCycle>
    <setStyleCycle id="styleCycle_4160" styleByNumber="1">
        <cycle>
            <style color="#000000" stroke-width="2pt" visible="true"/>
            <style color="#000000" stroke-dasharray="3px,2px"
visible="true"/>
            <style color="#000000" stroke-dasharray="3px,2px"
visible="true"/>
        </cycle>
    </setStyleCycle>
</template>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Manually tweaking a chart template (.sgt)

ViAnn Beadle
In reply to this post by Marta Garcia-Granero
With the exception of the inner frame background, the GGRAPH command will
create this chart. Marta sent me an example which I was nearly able to
replicate. The principle differences are:

1) GPL doesn't provide the line format that Marta set exactly. The closest I
could get is with the half_dash constant.
2) I couldn't get the exact same interpolation that Marta set within the
chart editor. My chart's interpolation end point goes down.

So here's the GGRAPH syntax:

* Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=time sj lower upper
MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE
TEMPLATE="C:\Users\Vi\Desktop\whitebackground.sgt".
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: time=col(source(s), name("time"))
  DATA: sj=col(source(s), name("sj"))
  DATA: lower=col(source(s), name("lower"))
  DATA: upper=col(source(s), name("upper"))
  SCALE: linear(dim(2), include(0))
  GUIDE: axis(dim(1), label("Follow-up Time"))
  GUIDE: axis(dim(2), label("Cumulative Survival"), delta(0.1))
  GUIDE: legend(aesthetic(aesthetic.shape.interior), null())
  ELEMENT: line(position(smooth.step.left(time*lower)), missing.wings(),
           shape.interior(shape.half_dash), color(color.gray))
  ELEMENT: line(position(smooth.step.left(time*upper)), missing.wings(),
           shape.interior(shape.half_dash), color(color.gray))
  ELEMENT: line(position(smooth.step.left(time*sj)), missing.wings(),
           shape.interior(shape.solid), size(size."2px"))
END GPL.

Comments on this syntax:

1. The include(0) forces the Y axis to include the value 0.
2. The delta(0.1) forces the 10 tick values on Y.
3. Three elements are used to create the three lines. Marta used the points
and then tried to remove them. I created three lines with an applied
interpolation function to them using the smooth.step.left function.
4. I removed the legend with the null() function.
5. I changed the shape of the lines for upper and lower to half_dash and
made them gray.
6. I made the sj line a bit thicker. I also made it last so that it would
sit on top of the lower and upper lines where they collided.
7. I tested this in SPSS 16.02.

--------------------------------------------------------
The Chart Template:

The default SPSS template provides a light gray inner frame background.
Marta's example has a white background. I edited the chart to change the
fill. All other changes that Marta had done in the editor were done with
functions in GPL.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template SPSS-Version="2.4" date="2008-09-11" description="" selectPath="12
" xmlns="http://xml.spss.com/spss/visualization"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xml.spss.com/spss/visualization
http://xml.spss.com/spss/visualization/vizml-template-3.0.xsd">
        <addFrame count="1" styleOnly="true" type="visualization">
                <style color="#ffffff" color2="transparent" number="0"
visible="true"/>
                <style font-family="SansSerif" font-size="8pt" number="1"
pattern="0" stroke-linecap="butt" text-fit="true" visible="true"/>
        </addFrame>
        <addFrame count="1" styleOnly="true" type="graph">
                <style color="transparent" color2="transparent"
visible="true"/>
                <style color="#ffffff" color2="#000000" number="1"
visible="true"/>
        </addFrame>
</template>

Comments on the template:

1. Since I'm using SPSS16 I have an updated schema for the template.
2. I only checked Styles>Non-data element styles>Fill and border styles.


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Marta García-Granero
Sent: Wednesday, September 10, 2008 10:46 AM
To: [hidden email]
Subject: Manually tweaking a chart template (.sgt)

Hi everybody

I'm trying to build a chart template (with SPSS 15) to make this graph
the way it should:

data list list/time (f8) sj lower upper (f8.1).
begin data
0    1    1    1
9    .985    .954    .995
10    .980    .947    .992
11    .975    .940    .989
12    .970    .933    .986
13    .964    .927    .983
14    .959    .920    .979
15    .954    .914    .976
16    .949    .908    .972
17    .939    .895    .965
21    .924    .877    .953
22    .908    .858    .941
23    .888    .835    .925
24    .883    .829    .920
29    .872    .817    .912
31    .867    .811    .908
33    .857    .800    .899
34    .836    .777    .881
35    .831    .771    .877
36    .821    .760    .868
37    .816    .754    .863
40    .811    .748    .859
41    .805    .743    .854
45    .800    .737    .850
46    .790    .726    .841
47    .779    .714    .831
51    .773    .708    .826
55    .763    .695    .818
56    .752    .680    .810
57    .738    .662    .800
58    .704    .615    .776
end data.

GRAPH /SCATTERPLOT(OVERLAY)=time WITH sj lower upper
 /TITLE='KM estimate with Kalbfleish-Prentice 95%CI'
 /TEMPLATE='C:\Temp\KPSurvival.sgt'.

This chart template, along with the code, is part of a big macro that
computes Kalbfleish-Prentice 95%CI for survival estimates and plots them
(just in case someone is wondering what's the use of all this code).

Basically, I have succeeded  in:

- Adding titles to x axis ("follow-up time") and y axis ("Cumulative
survival") (that required manual editing of the chart template, I found
no way of adding the titles to the graph directly)
- Adding interpolation lines (left step) to the three sets of data (time
WITH sj, time WITH lower and time WITH upper)
- Modifying the range and increment for y axis (from 0 to 1, delta=0.1)
- Hiding the scatter dots (they insisted in showing up as 5 pixel
diameter circles, even if I modified the graph to hide them and saved a
chart template afterwards) I had to manually tweak the template for that
too (lots of trial&error).

But... although I have manually edited the graph to change the
interpolation lines from blue, green and dusty to: solid line, black, 2
pixels (for "time WITH sj") and dashed line, black 1 pixel (for both
"time WITH lower" and "time WITH upper"), these modifications are
nowhere to be seen inside the chart template (at least to my untrained
eyes), and don't get applied to new graphs (although I'm sure I selected
everything that could be selected to be saved in the chart template). Is
there a way to add that instructions to it? Second item: since the chart
template will be dynamically created by the macro (using WRITE
OUTFILE='C:\Temp\KPSurvival.sgt'..........), is there any redundant line
that could be safely erased?

Any help/advice will be greatly appreciated,
Marta

*************

So far, my chart template has the following (rather difficult to
understand, BTW) lines:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template SPSS-Version="1.4" date="2008-09-10" description=""
selectPath="87 80 12 13 17 18 19 47 43 "
xmlns="http://xml.spss.com/spss/visualization"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xml.spss.com/spss/visualization
http://xml.spss.com/spss/visualization/vizml-template-3.0.xsd">
    <setAxisInterval lowerMapping="exact" max="1.0" min="0.0" role="y"
upperMapping="exact"/>
    <setAxisMajorTicks>
        <majorTicks categorical="false" delta="0.1" derived="false"
position="outside" role="y">
            <markStyle>
                <style color="#000000" stroke-width="1pt" visible="true"/>
            </markStyle>
            <tickLabelStyle>
                <style color="#000000" font-size="8pt" visible="true"/>
            </tickLabelStyle>
        </majorTicks>
    </setAxisMajorTicks>
    <setAxisMinorTicks>
        <minorTicks categorical="false" derived="false" number="2"
position="outside" role="y">
            <markStyle>
                <style color="#000000" visible="true"/>
            </markStyle>
        </minorTicks>
    </setAxisMinorTicks>
    <setAxisStyle categorical="false" role="y">
        <label>Cumulative Survival</label>
        <axisLabelStyle>
            <style color="#000000" color2="transparent" font-size="11pt"
font-weight="bold" labelLocationHorizontal="center"
labelLocationVertical="center" visible="true"/>
        </axisLabelStyle>
    </setAxisStyle>
    <setAxisStyle categorical="false" role="x">
        <label>Follow-up time</label>
        <axisLabelStyle>
            <style color="#000000" color2="transparent" font-size="11pt"
font-weight="bold" labelLocationHorizontal="center"
labelLocationVertical="center" visible="true"/>
        </axisLabelStyle>
    </setAxisStyle>
    <setAxisMargin categorical="false" lowerMargin="0%" role="x"
upperMargin="5%"/>
    <setAxisMargin categorical="false" lowerMargin="0%" role="y"
upperMargin="5%"/>
    <addInterpolationLine>
        <interpolation missingRepresentation="wings"
pointPosition="left" type="step"/>
        <style color="#000000" visible="true" width="1pt"/>
    </addInterpolationLine>
    <addFrame count="1" styleOnly="true" type="legend">
        <style color="transparent" color2="transparent" visible="false"/>
        <style color="transparent" color2="transparent" number="0"
visible="false"/>
    </addFrame>
    <addFrame count="1" styleOnly="true" type="visualization">
        <style color="#ffffff" color2="transparent" number="0"
visible="true"/>
        <style font-family="SansSerif" font-size="8pt" number="1"
pattern="0" stroke-linecap="butt" text-fit="true" visible="true"/>
    </addFrame>
    <addFrame count="1" styleOnly="true" type="graph">
        <style color="transparent" color2="transparent" visible="true"/>
        <style color="#ffffff" color2="#ffffff" number="1" visible="true"/>
    </addFrame>
    <addFrame count="1" styleOnly="true" type="title">
        <style color="transparent" color2="transparent" visible="true"/>
    </addFrame>
    <setShowLineMarkers>
        <style color="transparent" color2="#000000" size="1pt"
symbol="circle" visible="false"/>
    </setShowLineMarkers>
    <setStyle subtype="simple" type="line">
        <style color="#000000" visible="true" width="2pt"/>
    </setStyle>
    <setStyle subtype="simple" type="scatter">
        <style color="transparent" color2="#000000" size="5pt"
symbol="circle" visible="false"/>
    </setStyle>
    <setStyleCycle id="styleCycleDefault" styleByNumber="1">
        <cycle>
            <style color="#000000" color2="#000000" glyph-angle="90.0"
size="2px" symbol="line" visible="true"/>
            <style color="#000000" color2="#000000" glyph-angle="90.0"
size="1px" symbol="line" visible="true"/>
            <style color="#000000" color2="#000000" glyph-angle="90.0"
size="1px" symbol="line" visible="true"/>
        </cycle>
    </setStyleCycle>
    <setStyleCycle id="styleCycle_4160" styleByNumber="1">
        <cycle>
            <style color="#000000" stroke-width="2pt" visible="true"/>
            <style color="#000000" stroke-dasharray="3px,2px"
visible="true"/>
            <style color="#000000" stroke-dasharray="3px,2px"
visible="true"/>
        </cycle>
    </setStyleCycle>
</template>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Manually tweaking a chart template (.sgt) solved but.. a new problem shows its ugly face

Marta Garcia-Granero
ViAnn Beadle escribió:
> With the exception of the inner frame background, the GGRAPH command will
> create this chart. Marta sent me an example which I was nearly able to
> replicate. The principle differences are:
>
> 1) GPL doesn't provide the line format that Marta set exactly. The closest I
> could get is with the half_dash constant.
> 2) I couldn't get the exact same interpolation that Marta set within the
> chart editor. My chart's interpolation end point goes down.
>

My mistake, sorry, I skipped the last two lines of data when
copy-pasting the intermediate results generated by my macro.

Good news is: with some minor modifications of the GGRAPH (and chart
template), it now does exactly what I needed 8see code at the end of
this message). I'm deeply grateful for that. I hadn't though of using
GGRAPH because the main part of the code was written using SPSS 12. I
should keep in mind that I'm using SPSS 15 now.

Bad news: when I insert all the code from GGRAPH to END GPL inside my
macro, I get the following error message:

Warnings
GPL error: id('graphdataset')
Not a quoted string: 'graphdataset'
The command will not be executed.

And no graph is produced. It looks like some instructions are
differently interpreted inside the macro than in direct mode. I swear
that the string graphdataset is correctly quoted.

Absolutely mystified,
Marta

-----------------------------------------------------------------------
This is the last (fully working in direct mode) version of the
dataset&syntax:

data list free/time (f8) sj lower upper (3 f8.1).
begin data
 0  1    1    1    9 .985 .954 .995 10 .980 .947 .992 11 .975 .940 .989
12 .970 .933 .986 13 .964 .927 .983 14 .959 .920 .979 15 .954 .914 .976
16 .949 .908 .972 17 .939 .895 .965 21 .924 .877 .953 22 .908 .858 .941
23 .888 .835 .925 24 .883 .829 .920 29 .872 .817 .912 31 .867 .811 .908
33 .857 .800 .899 34 .836 .777 .881 35 .831 .771 .877 36 .821 .760 .868
37 .816 .754 .863 40 .811 .748 .859 41 .805 .743 .854 45 .800 .737 .850
46 .790 .726 .841 47 .779 .714 .831 51 .773 .708 .826 55 .763 .695 .818
56 .752 .680 .810 57 .738 .662 .800 58 .704 .615 .776 59 .704 .615 .776
60 .704 .615 .776
end data.

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=time sj lower upper
MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE TEMPLATE="C:\Temp\Template.sgt".
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: time=col(source(s), name("time"))
  DATA: sj=col(source(s), name("sj"))
  DATA: lower=col(source(s), name("lower"))
  DATA: upper=col(source(s), name("upper"))
  SCALE: linear(dim(2), include(0))
  GUIDE: axis(dim(1), label("Follow-up Time"))
  GUIDE: axis(dim(2), label("Cumulative Survival"), delta(0.1))
  GUIDE: legend(aesthetic(aesthetic.shape.interior), null())
  GUIDE: text.title(label("KM estimate with Kalbfleish-Prentice 95%CI"))
  ELEMENT: line(position(smooth.step.left(time*lower)), missing.wings(),
           shape.interior(shape.dash), color(color.black))
  ELEMENT: line(position(smooth.step.left(time*upper)), missing.wings(),
           shape.interior(shape.dash), color(color.black))
  ELEMENT: line(position(smooth.step.left(time*sj)), missing.wings(),
           shape.interior(shape.solid), size(size."2px"))
END GPL.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Manually tweaking a chart template (.sgt) solved but.. a new problem shows its ugly face

ViAnn Beadle
Yes, this is because GGRAPH requires quotation marks and not apostrophes. So
you have do something like this for every quoted string in your macro:

!LET !gdataset=!CONCAT('"',graphdataset,'"')

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Marta García-Granero
Sent: Thursday, September 11, 2008 10:24 AM
To: [hidden email]
Subject: Re: Manually tweaking a chart template (.sgt) solved but.. a new
problem shows its ugly face

ViAnn Beadle escribió:
> With the exception of the inner frame background, the GGRAPH command will
> create this chart. Marta sent me an example which I was nearly able to
> replicate. The principle differences are:
>
> 1) GPL doesn't provide the line format that Marta set exactly. The closest
I
> could get is with the half_dash constant.
> 2) I couldn't get the exact same interpolation that Marta set within the
> chart editor. My chart's interpolation end point goes down.
>

My mistake, sorry, I skipped the last two lines of data when
copy-pasting the intermediate results generated by my macro.

Good news is: with some minor modifications of the GGRAPH (and chart
template), it now does exactly what I needed 8see code at the end of
this message). I'm deeply grateful for that. I hadn't though of using
GGRAPH because the main part of the code was written using SPSS 12. I
should keep in mind that I'm using SPSS 15 now.

Bad news: when I insert all the code from GGRAPH to END GPL inside my
macro, I get the following error message:

Warnings
GPL error: id('graphdataset')
Not a quoted string: 'graphdataset'
The command will not be executed.

And no graph is produced. It looks like some instructions are
differently interpreted inside the macro than in direct mode. I swear
that the string graphdataset is correctly quoted.

Absolutely mystified,
Marta

-----------------------------------------------------------------------
This is the last (fully working in direct mode) version of the
dataset&syntax:

data list free/time (f8) sj lower upper (3 f8.1).
begin data
 0  1    1    1    9 .985 .954 .995 10 .980 .947 .992 11 .975 .940 .989
12 .970 .933 .986 13 .964 .927 .983 14 .959 .920 .979 15 .954 .914 .976
16 .949 .908 .972 17 .939 .895 .965 21 .924 .877 .953 22 .908 .858 .941
23 .888 .835 .925 24 .883 .829 .920 29 .872 .817 .912 31 .867 .811 .908
33 .857 .800 .899 34 .836 .777 .881 35 .831 .771 .877 36 .821 .760 .868
37 .816 .754 .863 40 .811 .748 .859 41 .805 .743 .854 45 .800 .737 .850
46 .790 .726 .841 47 .779 .714 .831 51 .773 .708 .826 55 .763 .695 .818
56 .752 .680 .810 57 .738 .662 .800 58 .704 .615 .776 59 .704 .615 .776
60 .704 .615 .776
end data.

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=time sj lower upper
MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE TEMPLATE="C:\Temp\Template.sgt".
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: time=col(source(s), name("time"))
  DATA: sj=col(source(s), name("sj"))
  DATA: lower=col(source(s), name("lower"))
  DATA: upper=col(source(s), name("upper"))
  SCALE: linear(dim(2), include(0))
  GUIDE: axis(dim(1), label("Follow-up Time"))
  GUIDE: axis(dim(2), label("Cumulative Survival"), delta(0.1))
  GUIDE: legend(aesthetic(aesthetic.shape.interior), null())
  GUIDE: text.title(label("KM estimate with Kalbfleish-Prentice 95%CI"))
  ELEMENT: line(position(smooth.step.left(time*lower)), missing.wings(),
           shape.interior(shape.dash), color(color.black))
  ELEMENT: line(position(smooth.step.left(time*upper)), missing.wings(),
           shape.interior(shape.dash), color(color.black))
  ELEMENT: line(position(smooth.step.left(time*sj)), missing.wings(),
           shape.interior(shape.solid), size(size."2px"))
END GPL.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Manually tweaking a chart template (.sgt) solved but.. a new problem shows its ugly face

Marta Garcia-Granero
ViAnn Beadle escribió:
> Yes, this is because GGRAPH requires quotation marks and not apostrophes. So
> you have do something like this for every quoted string in your macro:
>
> !LET !gdataset=!CONCAT('"',graphdataset,'"')
>

Wow, it finally works. I will post the complete macro at the usual place
(http://gjyp.nl/marta/ ) once I finish it (now I have to add the
creation of the chart template from inside the macro), just in case
anyone wants a macro that computes and plots 95%CI for Kaplan-Meier
survival estimates using Kalbfleish-Prentice method.

Many, many thanks.
Marta

------------------------------------
I have checked tht all is OK with this short macro

DEFINE MYGRAPH().
!LET !gdataset=!CONCAT('"','graphdataset','"').
!LET !time=!CONCAT('"','time','"').
!LET !sj=!CONCAT('"','sj','"').
!LET !lower=!CONCAT('"','lower','"').
!LET !upper=!CONCAT('"','upper','"').
!LET !ylabel=!CONCAT('"','Cumulative Survival','"').
!LET !xlabel=!CONCAT('"','Follow-up Time','"').
!LET !title=!CONCAT('"','KM estimate with Kalbfleish-Prentice 95%CI','"').
!LET !px=!CONCAT('"','2px','"').
GGRAPH
  /GRAPHDATASET NAME=!gdataset VARIABLES=time sj lower upper
  MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id(!gdataset))
  DATA: time=col(source(s), name(!time))
  DATA: sj=col(source(s), name(!sj))
  DATA: lower=col(source(s), name(!lower))
  DATA: upper=col(source(s), name(!upper))
  SCALE: linear(dim(2), include(0))
  GUIDE: axis(dim(1), label(!xlabel))
  GUIDE: axis(dim(2), label(!ylabel), delta(0.1))
  GUIDE: legend(aesthetic(aesthetic.shape.interior), null())
  GUIDE: text.title(label(!title))
  ELEMENT: line(position(smooth.step.left(time*lower)), missing.wings(),
           shape.interior(shape.dash), color(color.black))
  ELEMENT: line(position(smooth.step.left(time*upper)), missing.wings(),
           shape.interior(shape.dash), color(color.black))
  ELEMENT: line(position(smooth.step.left(time*sj)), missing.wings(),
           shape.interior(shape.solid), size(size.!px))
END GPL.
!ENDDEFINE.

data list free/time (f8) sj lower upper (3 f8.1).
begin data
 0  1    1    1    9 .985 .954 .995 10 .980 .947 .992 11 .975 .940 .989
12 .970 .933 .986 13 .964 .927 .983 14 .959 .920 .979 15 .954 .914 .976
16 .949 .908 .972 17 .939 .895 .965 21 .924 .877 .953 22 .908 .858 .941
23 .888 .835 .925 24 .883 .829 .920 29 .872 .817 .912 31 .867 .811 .908
33 .857 .800 .899 34 .836 .777 .881 35 .831 .771 .877 36 .821 .760 .868
37 .816 .754 .863 40 .811 .748 .859 41 .805 .743 .854 45 .800 .737 .850
46 .790 .726 .841 47 .779 .714 .831 51 .773 .708 .826 55 .763 .695 .818
56 .752 .680 .810 57 .738 .662 .800 58 .704 .615 .776 59 .704 .615 .776
60 .704 .615 .776
end data.

MYGRAPH.

--
For miscellaneous statistical stuff, visit:
http://gjyp.nl/marta/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD