Administrator
|
I apologize if there is an obvious answer to this somewhere in the GPL Reference Guide, but I've not been able to find it. I'm working on a little demo of the fact that the sum of the squared deviations about the MEAN is a minimum. At the end of my syntax, I plot the sum of the squared deviations around C, with C taking on several different values, including the mean. Here's the GPL command:
GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=C SS Flag MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: C=col(source(s), name("C")) DATA: SS=col(source(s), name("SS")) DATA: Flag=col(source(s), name("Flag"), unit.category()) GUIDE: axis(dim(1), label("C")) GUIDE: axis(dim(2), label("Sum of Squared Deviations About C")) GUIDE: legend(aesthetic(aesthetic.color.exterior), label("C=Mean")) ELEMENT: point(position(C*SS), color.exterior(Flag)) ELEMENT: line(position(smooth.quadratic(C*SS)), shape(shape.solid), color(color.black)) END GPL. I want to add two GUIDE lines as follows: GUIDE: form.line(position(MEAN, *),shape(shape.dash)) GUIDE: form.line(position(*, MIN),shape(shape.dash)) But I've not been able to find functions that allow me to plot these reference lines at the MEAN of C and the MIN of SS. I have seen SUMMARY.MIN and SUMMARY.MEAN in the reference guide, but if they are what I need here, I have not yet found a relevant example that shows me how to make them work in this context. One other thing, while we're at it: Is there a way in GPL to change the chart area color from the default grey? I'd like to set it to no color. 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/). |
Does this help?: http://spssx-discussion.1045642.n5.nabble.com/adding-a-vertical-reference-line-to-a-line-graph-td5728859.html#a5728866
You would have to add MEAN of C and the MIN of SS as variables in the dataset, I believe. I think you can only change background as a post-hoc edit or tweak the chart template beforehand: https://andrewpwheeler.wordpress.com/2012/01/03/hacking-the-default-spss-chart-template/ |
In reply to this post by Bruce Weaver
Agree with Jignesh - background color can not be specified via GPL, if you want all charts as transparent you need to edit the chart template.
You can do the mean of the Y axis variable using: ELEMENT: line(position(smooth.mean.uniform(X*Y))) But the min and max lines are not as easily accomplished. The "summary.???" functions need the X axis to be binned to work properly. You might be able to hack something together using the binning functions over the range of the entire data, but then you would need to specify the min and max X coordinates in SCALE statement. Example below of the suggestions. ****************************************************************. *Fake data. INPUT PROGRAM. LOOP #i = 1 TO 100. COMPUTE C = #i. COMPUTE SS = RV.NORMAL(0,1). COMPUTE Flag = RV.BERNOULLI(0.5). END CASE. END LOOP. END FILE. END INPUT PROGRAM. DATASET NAME test. *Bruces original. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=C SS Flag MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: C=col(source(s), name("C")) DATA: SS=col(source(s), name("SS")) DATA: Flag=col(source(s), name("Flag"), unit.category()) GUIDE: axis(dim(1), label("C")) GUIDE: axis(dim(2), label("Sum of Squared Deviations About C")) GUIDE: legend(aesthetic(aesthetic.color.exterior), label("C=Mean")) ELEMENT: point(position(C*SS), color.exterior(Flag)) ELEMENT: line(position(smooth.quadratic(C*SS)), shape(shape.solid), color(color.black)) END GPL. *Line for the overall mean of Y. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=C SS Flag MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: C=col(source(s), name("C")) DATA: SS=col(source(s), name("SS")) DATA: Flag=col(source(s), name("Flag"), unit.category()) GUIDE: axis(dim(1), label("C")) GUIDE: axis(dim(2), label("Sum of Squared Deviations About C")) GUIDE: legend(aesthetic(aesthetic.color.exterior), label("C=Mean")) ELEMENT: point(position(C*SS), color.exterior(Flag)) ELEMENT: line(position(smooth.mean.uniform(C*SS)), shape(shape.solid), color(color.red), size(size."4")) ELEMENT: line(position(smooth.quadratic(C*SS)), shape(shape.solid), color(color.black)) END GPL. *To get a minimum line is more challenging, the easiest way is to add a variable in the dataset. AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK /MinV = MIN(SS). GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=C SS Flag MinV MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: C=col(source(s), name("C")) DATA: SS=col(source(s), name("SS")) DATA: MinV=col(source(s), name("MinV")) DATA: Flag=col(source(s), name("Flag"), unit.category()) GUIDE: axis(dim(1), label("C")) GUIDE: axis(dim(2), label("Sum of Squared Deviations About C")) GUIDE: legend(aesthetic(aesthetic.color.exterior), label("C=Mean")) ELEMENT: point(position(C*SS), color.exterior(Flag)) ELEMENT: line(position(C*MinV), color(color.green)) ELEMENT: line(position(smooth.mean.uniform(C*SS)), shape(shape.solid), color(color.red), size(size."4")) ELEMENT: line(position(smooth.quadratic(C*SS)), shape(shape.solid), color(color.black)) END GPL. ****************************************************************. |
Administrator
|
Thanks Jignesh & Andy. With your guidance, I was able to come up with the following, which gives me (more or less) what I was looking for.
Cheers, Bruce GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=C SS SS_min C_mean Flag MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: C=col(source(s), name("C")) DATA: SS=col(source(s), name("SS")) DATA: Flag=col(source(s), name("Flag"), unit.category()) DATA: SS_min=col(source(s), name("SS_min")) DATA: C_mean=col(source(s), name("C_mean")) GUIDE: axis(dim(1), label("C")) GUIDE: axis(dim(2), label("Sum of Squared Deviations About C")) GUIDE: legend(aesthetic(aesthetic.color.exterior), label("C=Mean")) ELEMENT: point(position(C*SS), color.exterior(Flag), color.interior(Flag), size(size."10")) ELEMENT: line(position(smooth.quadratic(C*SS)), shape(shape.solid), color(color.black)) ELEMENT: line(position(C*SS_min), shape(shape.dash), color(color.black)) ELEMENT: line(position(C_mean*SS), shape(shape.dash), color(color.black)) END GPL.
--
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/). |
I have [successfully] tried the undocumented INLINETEMPLATE directive to force some simple modifications. I compared two templates with only the background changed and extracted the code where the changes were found. I remember reading about some maximum line length but cannot find it again. Empirically it works.
David Marso (1) pointed out that the often long inline statements can be divided into multiple lines with a plus sign. Be sure to use apostrophy (') as quotes (") are used in the inlinetemplate. This example sets the graph background to bright yellow. INLINETEMPLATE=['<addFrame count="1" type="graph">' + '<style color="#fbf873" color2="#000000" coordinate="1" number="1" pattern="0" visible="true"/>' + '</addFrame>']. Your GPL with inlinetemplate to get a transparent background: GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=C SS Flag MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE INLINETEMPLATE=['<addFrame count="1" type="graph">' + '<style color="transparent" color2="#000000" coordinate="1" number="1" pattern="0" visible="true"/>' + '</addFrame>']. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: C=col(source(s), name("C")) DATA: SS=col(source(s), name("SS")) DATA: Flag=col(source(s), name("Flag"), unit.category()) GUIDE: axis(dim(1), label("C")) GUIDE: axis(dim(2), label("Sum of Squared Deviations About C")) GUIDE: legend(aesthetic(aesthetic.color.exterior), label("C=Mean")) ELEMENT: point(position(C*SS), color.exterior(Flag)) ELEMENT: line(position(smooth.quadratic(C*SS)), shape(shape.solid), color(color.black)) END GPL. HTH, PR (1) http://spssx-discussion.1045642.n5.nabble.com/INLINETEMPLATE-with-line-break-tp5713563.html |
Administrator
|
That's great. Thanks very much, PRogman.
--
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/). |
Free forum by Nabble | Edit this page |