FITLINES sub-command for GGRAPH: An easier way to add a regression lines to scatter-plots

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

FITLINES sub-command for GGRAPH: An easier way to add a regression lines to scatter-plots

Bruce Weaver
Administrator
Apologies if someone has already posted on this.  My searches for FITLINE
were finding only references to the old IGRAPH command (which is now
deprecated, IIRC).  

I just noticed in the FM for v25 that GGRAPH now includes a FITLINES
sub-command which can be used to add an overall regression line or
regression lines for sub-groups.  FITLINES is much easier (I think) than the
old method, which required adding an ELEMENT line to the GPL section.
Here's an example to illustrate both approaches.

* Example from the v25 FM entry for GGRAPH:
*
https://www.ibm.com/support/knowledgecenter/en/SSLVMB_25.0.0/statistics_reference_project_ddita/spss/base/syn_ggraph_examples.html.
* Simple Scatterplot with Fit Line.

* Change path on the next line as needed.
GET FILE "C:\SPSSdata\Employee data.sav".

* First, the old method:  Notice the final ELEMENT 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.

* Now the new method, via FITLINES.
* Notice that the ELEMENT line used above has been removed.

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=salbegin salary
  /GRAPHSPEC SOURCE=INLINE
  /FITLINES TOTAL=YES SUBGROUP=NO.
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))
END GPL.

Using v25 for Windows, I get essentially the same scatter-plot both ways.
(The FITLINES method adds the value of Rsq to the chart.)

Finally, here's another example that adds gender as a third variable, and
adds separate regression lines for males & females.

* Add gender as a grouping variable, and plot separate regression
* lines for males & females.

* Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=salbegin salary gender
MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE
  /FITLINES TOTAL=NO SUBGROUP=YES.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: salbegin=col(source(s), name("salbegin"))
  DATA: salary=col(source(s), name("salary"))
  DATA: gender=col(source(s), name("gender"), unit.category())
  GUIDE: axis(dim(1), label("Beginning Salary"))
  GUIDE: axis(dim(2), label("Current Salary"))
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("Gender"))
  GUIDE: text.title(label("Grouped Scatter of Current Salary by Beginning
Salary by Gender"))
  SCALE: cat(aesthetic(aesthetic.color.interior), include("f", "m"))
  ELEMENT: point(position(salbegin*salary), color.interior(gender))
END GPL.


I think this is a very nice addition to GGRAPH, and I suggest that the
example in the FM be updated to use FITLINES.  

Cheers,
Bruce




-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|

Re: FITLINES sub-command for GGRAPH: An easier way to add a regression lines to scatter-plots

Jon Peck
The Chart Builder (Graphs > Chart Builder) in version 25 of Statistics has a number of new features that reduce the need to resort to GPL or manual chart editing.

On Fri, Mar 16, 2018 at 3:36 PM, Bruce Weaver <[hidden email]> wrote:
Apologies if someone has already posted on this.  My searches for FITLINE
were finding only references to the old IGRAPH command (which is now
deprecated, IIRC).

I just noticed in the FM for v25 that GGRAPH now includes a FITLINES
sub-command which can be used to add an overall regression line or
regression lines for sub-groups.  FITLINES is much easier (I think) than the
old method, which required adding an ELEMENT line to the GPL section.
Here's an example to illustrate both approaches.

* Example from the v25 FM entry for GGRAPH:
*
https://www.ibm.com/support/knowledgecenter/en/SSLVMB_25.0.0/statistics_reference_project_ddita/spss/base/syn_ggraph_examples.html.
* Simple Scatterplot with Fit Line.

* Change path on the next line as needed.
GET FILE "C:\SPSSdata\Employee data.sav".

* First, the old method:  Notice the final ELEMENT 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.

* Now the new method, via FITLINES.
* Notice that the ELEMENT line used above has been removed.

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=salbegin salary
  /GRAPHSPEC SOURCE=INLINE
  /FITLINES TOTAL=YES SUBGROUP=NO.
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))
END GPL.

Using v25 for Windows, I get essentially the same scatter-plot both ways.
(The FITLINES method adds the value of Rsq to the chart.)

Finally, here's another example that adds gender as a third variable, and
adds separate regression lines for males & females.

* Add gender as a grouping variable, and plot separate regression
* lines for males & females.

* Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=salbegin salary gender
MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE
  /FITLINES TOTAL=NO SUBGROUP=YES.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: salbegin=col(source(s), name("salbegin"))
  DATA: salary=col(source(s), name("salary"))
  DATA: gender=col(source(s), name("gender"), unit.category())
  GUIDE: axis(dim(1), label("Beginning Salary"))
  GUIDE: axis(dim(2), label("Current Salary"))
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("Gender"))
  GUIDE: text.title(label("Grouped Scatter of Current Salary by Beginning
Salary by Gender"))
  SCALE: cat(aesthetic(aesthetic.color.interior), include("f", "m"))
  ELEMENT: point(position(salbegin*salary), color.interior(gender))
END GPL.


I think this is a very nice addition to GGRAPH, and I suggest that the
example in the FM be updated to use FITLINES.

Cheers,
Bruce




-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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



--
Jon K Peck
[hidden email]

===================== 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: FITLINES sub-command for GGRAPH: An easier way to add a regression lines to scatter-plots

Bruce Weaver
Administrator
What are they trying to do, make Andy's website obsolete?  ;-)  

   https://andrewpwheeler.wordpress.com/category/spss/



Jon Peck wrote
> The Chart Builder (Graphs > Chart Builder) in version 25 of Statistics has
> a number of new features that reduce the need to resort to GPL or manual
> chart editing.
>
> On Fri, Mar 16, 2018 at 3:36 PM, Bruce Weaver &lt;

> bruce.weaver@

> &gt;
> wrote:
>
>> Apologies if someone has already posted on this.  My searches for FITLINE
>> were finding only references to the old IGRAPH command (which is now
>> deprecated, IIRC).
>>
>> I just noticed in the FM for v25 that GGRAPH now includes a FITLINES
>> sub-command which can be used to add an overall regression line or
>> regression lines for sub-groups.  FITLINES is much easier (I think) than
>> the
>> old method, which required adding an ELEMENT line to the GPL section.
>> Here's an example to illustrate both approaches.
>>
>> * Example from the v25 FM entry for GGRAPH:
>> *
>> https://www.ibm.com/support/knowledgecenter/en/SSLVMB_25.
>> 0.0/statistics_reference_project_ddita/spss/base/syn_ggraph_examples.html.
>> * Simple Scatterplot with Fit Line.
>>
>> * Change path on the next line as needed.
>> GET FILE "C:\SPSSdata\Employee data.sav".
>>
>> * First, the old method:  Notice the final ELEMENT 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.
>>
>> * Now the new method, via FITLINES.
>> * Notice that the ELEMENT line used above has been removed.
>>
>> GGRAPH
>>   /GRAPHDATASET NAME="graphdataset" VARIABLES=salbegin salary
>>   /GRAPHSPEC SOURCE=INLINE
>>   /FITLINES TOTAL=YES SUBGROUP=NO.
>> 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))
>> END GPL.
>>
>> Using v25 for Windows, I get essentially the same scatter-plot both ways.
>> (The FITLINES method adds the value of Rsq to the chart.)
>>
>> Finally, here's another example that adds gender as a third variable, and
>> adds separate regression lines for males & females.
>>
>> * Add gender as a grouping variable, and plot separate regression
>> * lines for males & females.
>>
>> * Chart Builder.
>> GGRAPH
>>   /GRAPHDATASET NAME="graphdataset" VARIABLES=salbegin salary gender
>> MISSING=LISTWISE
>>     REPORTMISSING=NO
>>   /GRAPHSPEC SOURCE=INLINE
>>   /FITLINES TOTAL=NO SUBGROUP=YES.
>> BEGIN GPL
>>   SOURCE: s=userSource(id("graphdataset"))
>>   DATA: salbegin=col(source(s), name("salbegin"))
>>   DATA: salary=col(source(s), name("salary"))
>>   DATA: gender=col(source(s), name("gender"), unit.category())
>>   GUIDE: axis(dim(1), label("Beginning Salary"))
>>   GUIDE: axis(dim(2), label("Current Salary"))
>>   GUIDE: legend(aesthetic(aesthetic.color.interior), label("Gender"))
>>   GUIDE: text.title(label("Grouped Scatter of Current Salary by Beginning
>> Salary by Gender"))
>>   SCALE: cat(aesthetic(aesthetic.color.interior), include("f", "m"))
>>   ELEMENT: point(position(salbegin*salary), color.interior(gender))
>> END GPL.
>>
>>
>> I think this is a very nice addition to GGRAPH, and I suggest that the
>> example in the FM be updated to use FITLINES.
>>
>> Cheers,
>> Bruce
>>
>>
>>
>>
>> -----
>> --
>> Bruce Weaver
>>

> bweaver@

>> http://sites.google.com/a/lakeheadu.ca/bweaver/
>>
>> "When all else fails, RTFM."
>>
>> NOTE: My Hotmail account is not monitored regularly.
>> To send me an e-mail, please use the address shown above.
>>
>> --
>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>>

> LISTSERV@.UGA

>  (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
>>
>
>
>
> --
> Jon K Peck

> jkpeck@

>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|

Re: FITLINES sub-command for GGRAPH: An easier way to add a regression lines to scatter-plots

Andy W
No complaints from me if my stuff is obsolete due to better options. I will
have to play around with some of those new options to see how they interact
with chart templates (GRIDLINES and FRAME in particular -- I don't foresee
using COLORCYCLE, but I see how it could be handy). Also could see how
DATAFILTER is useful, but I currently use TEMPORARY and then SELECT IF just
before the GGRAPH call to accomplish the same thing.

In my V25 it also says there is a new subcommand OVERRIDE under GRAPHSPEC,
but I don't see it documented anywhere in the help,
https://www.ibm.com/support/knowledgecenter/en/SSLVMB_25.0.0/statistics_reference_project_ddita/spss/base/syn_ggraph.html.
(That is a nice update too, sending the help to an online website, so can be
updated, is that new in V25?)



-----
Andy W
[hidden email]
http://andrewpwheeler.wordpress.com/
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/