GPL scatter-plot: fit-lines for sub-groups

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

GPL scatter-plot: fit-lines for sub-groups

Bruce Weaver
Administrator
[ Also posted to comp.soft-sys.stat.spss ]

I wonder if someone better versed in the GPL can help with this.  The following example from the Command Syntax Reference manual shows how to create a simple scatter-plot with a regression line.

GGRAPH
 /GRAPHDATASET NAME="graphdataset" VARIABLES=salbegin salary
 /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
 SOURCE: s=userSource(id("graphdataset"))
 DATA: salbegin=col(source(s), name("salbegin"))
 DATA: salary=col(source(s), name("salary"))
 GUIDE: axis(dim(1), label("Beginning Salary"))
 GUIDE: axis(dim(2), label("Current Salary"))
 ELEMENT: point(position(salbegin*salary))
 ELEMENT: line(position(smooth.linear(salbegin*salary)))
END GPL.


And here is syntax to create a scatter-plot with a grouping variable (MD).


GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=age RC_pred md MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: age=col(source(s), name("age"))
  DATA: RC_pred=col(source(s), name("RC_pred"))
  DATA: md=col(source(s), name("md"), unit.category())
  GUIDE: axis(dim(1), label("Age (yrs)"))
  GUIDE: axis(dim(2), label("Predicted Values"))
  GUIDE: legend(aesthetic(aesthetic.color.exterior), label("Doctor"))
  ELEMENT: point(position(age*RC_pred), color.exterior(md))
END GPL.


For this second example, I can get an overall regression line by adding:

  ELEMENT: line(position(smooth.linear(age*RC_pred)))

But how do I modify that to get a separate regression line for each group?  If there's an example of this in the documentation, I've not found it.

Thanks,
Bruce
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: GPL scatter-plot: fit-lines for sub-groups

Marta Garcia-Granero
Hi Bruce:

Bruce Weaver wrote:

> [ Also posted to comp.soft-sys.stat.spss ]
>
> I wonder if someone better versed in the GPL can help with this.  The
> following example from the Command Syntax Reference manual shows how to
> create a simple scatter-plot with a regression line.
>
> GGRAPH
>  /GRAPHDATASET NAME="graphdataset" VARIABLES=salbegin salary
>  /GRAPHSPEC SOURCE=INLINE.
> BEGIN GPL
>  SOURCE: s=userSource(id("graphdataset"))
>  DATA: salbegin=col(source(s), name("salbegin"))
>  DATA: salary=col(source(s), name("salary"))
>  GUIDE: axis(dim(1), label("Beginning Salary"))
>  GUIDE: axis(dim(2), label("Current Salary"))
>  ELEMENT: point(position(salbegin*salary))
>  ELEMENT: line(position(smooth.linear(salbegin*salary)))
> END GPL.
>
>
>
GUIDE: legend(aesthetic(aesthetic.shape.interior), label("Dependent"))
SCALE: linear(dim(2), min(-0.5))
SCALE: cat(aesthetic(aesthetic.shape.interior))
ELEMENT: point(position(x6*DV), shape.interior(Group))
ELEMENT: line(position(smooth.linear(x6*DV)), shape.interior(Group))
END GPL.

> And here is syntax to create a scatter-plot with a grouping variable (MD).
>
>
> GGRAPH
>   /GRAPHDATASET NAME="graphdataset" VARIABLES=age RC_pred md
> MISSING=LISTWISE REPORTMISSING=NO
>   /GRAPHSPEC SOURCE=INLINE.
> BEGIN GPL
>   SOURCE: s=userSource(id("graphdataset"))
>   DATA: age=col(source(s), name("age"))
>   DATA: RC_pred=col(source(s), name("RC_pred"))
>   DATA: md=col(source(s), name("md"), unit.category())
>   GUIDE: axis(dim(1), label("Age (yrs)"))
>   GUIDE: axis(dim(2), label("Predicted Values"))
>   GUIDE: legend(aesthetic(aesthetic.color.exterior), label("Doctor"))
>   ELEMENT: point(position(age*RC_pred), color.exterior(md))
> END GPL.
>
>
> For this second example, I can get an overall regression line by adding:
>
>   ELEMENT: line(position(smooth.linear(age*RC_pred)))
>


> But how do I modify that to get a separate regression line for each group?
> If there's an example of this in the documentation, I've not found it.
>

Try adding the following elements.

GUIDE: legend(aesthetic(aesthetic.shape.interior), label("Doctor"))
SCALE: cat(aesthetic(aesthetic.shape.interior))
ELEMENT: line(position(smooth.linear(age*RC_pred)), shape.interior(md))

HTH,
Marta GG

--
For miscellaneous SPSS related 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: GPL scatter-plot: fit-lines for sub-groups

Bruce Weaver
Administrator
Marta GarcĂ­a-Granero-3 wrote
Hi Bruce:

--- snip ---
> And here is syntax to create a scatter-plot with a grouping variable (MD).
>
>
> GGRAPH
>   /GRAPHDATASET NAME="graphdataset" VARIABLES=age RC_pred md
> MISSING=LISTWISE REPORTMISSING=NO
>   /GRAPHSPEC SOURCE=INLINE.
> BEGIN GPL
>   SOURCE: s=userSource(id("graphdataset"))
>   DATA: age=col(source(s), name("age"))
>   DATA: RC_pred=col(source(s), name("RC_pred"))
>   DATA: md=col(source(s), name("md"), unit.category())
>   GUIDE: axis(dim(1), label("Age (yrs)"))
>   GUIDE: axis(dim(2), label("Predicted Values"))
>   GUIDE: legend(aesthetic(aesthetic.color.exterior), label("Doctor"))
>   ELEMENT: point(position(age*RC_pred), color.exterior(md))
> END GPL.
>
>
> For this second example, I can get an overall regression line by adding:
>
>   ELEMENT: line(position(smooth.linear(age*RC_pred)))
>


> But how do I modify that to get a separate regression line for each group?
> If there's an example of this in the documentation, I've not found it.
>

Try adding the following elements.

GUIDE: legend(aesthetic(aesthetic.shape.interior), label("Doctor"))
SCALE: cat(aesthetic(aesthetic.shape.interior))
ELEMENT: line(position(smooth.linear(age*RC_pred)), shape.interior(md))

HTH,
Marta GG
Thanks Marta, that did indeed give me a nudge in the right direction. However, I changed the last two lines to:

  SCALE: cat(aesthetic(aesthetic.color.interior))
  ELEMENT: line(position(smooth.linear(age*RC_pred)), color.interior(md))

This gives me lines with different colours rather than different line styles.

Cheers,
Bruce
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).