Charts with cumulative sums and log scale?

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

Charts with cumulative sums and log scale?

Robert L
Inspired by an article on charting corona cases (https://www.qualitydigest.com/inside/healthcare-article/tracking-covid-19-040620.html), I thought I would set up a chart with cumulative sums of counts with log scale on the y axis. But it doesn't work, the numbers on the y axis is not what I had hoped for.

In Chart Builder, I used the options for "Point1" and "Y-Axis1" in the wondow for "Edit Properties of" to set up a chart with linear scale (which works) followed by  switching to a log scale. The following syntax (with a small data set) is generated:

DATA LIST FREE/time(F2) counts(F2).
BEGIN DATA
1 2 2 2 3 2 4 2 5 1 6 4 7 5 8 6 9 6 10 6
END DATA.
DATASET NAME log_cumsum WINDOW=FRONT.

VARIABLE LEVEL time(ORDINAL) counts(SCALE).

* Linear scale on y axis which works fine.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=time SUM(counts)[name="SUM_counts"] MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE
  /FITLINE TOTAL=NO.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: time=col(source(s), name("time"), unit.category())
  DATA: SUM_counts=col(source(s), name("SUM_counts"))
  GUIDE: axis(dim(1), label("time"))
  GUIDE: axis(dim(2), label("Cumulative Sum counts"))
  GUIDE: text.title(label("Simple Scatter Cumulative Sum of counts by time"))
  SCALE: linear(dim(2), include(0))
  ELEMENT: point(position(summary.sum.cumulative(time*SUM_counts)))
END GPL.

* Attempt at log scale on y axis.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=time SUM(counts)[name="SUM_counts"] MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE
  /FITLINE TOTAL=NO.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: time=col(source(s), name("time"), unit.category())
  DATA: SUM_counts=col(source(s), name("SUM_counts"))
  GUIDE: axis(dim(1), label("time"))
  GUIDE: axis(dim(2), label("Cumulative Sum counts"))
  GUIDE: text.title(label("Simple Scatter Cumulative Sum of counts by time"))
  SCALE: log(dim(2), base(10))
  ELEMENT: point(position(summary.sum.cumulative(time*SUM_counts)))
END GPL.

Any suggestions about what is happening and what should be made to make it work?

Robert

=====================
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
Robert Lundqvist
Reply | Threaded
Open this post in threaded view
|

Re: Charts with cumulative sums and log scale?

Andy W
Yeah that is a bit strange behavior! Simplest solution is to calculate the
cumulative sum outside of ggraph and then just plot that variable.

CREATE /CumCount = CSUM(counts).

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=time CumCount MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE
  /FITLINE TOTAL=NO.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: time=col(source(s), name("time"), unit.category())
  DATA: CumCount=col(source(s), name("CumCount"))
  GUIDE: axis(dim(1), label("time"))
  GUIDE: axis(dim(2), label("Cumulative Sum counts"))
  SCALE: log(dim(2), base(2))
  ELEMENT: line(position(time*CumCount)))
END GPL.



-----
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/
Reply | Threaded
Open this post in threaded view
|

SV: Charts with cumulative sums and log scale?

Robert L
Thanks Andy! I had forgotten about the CREATE functions, nearly began using LAG functions to calculate cumulative sum for the variables at hand. The CREATE functions is much better, a oneliner for calculating several new variables at once is always nice.

Robert

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För Andy W
Skickat: den 7 april 2020 23:35
Till: [hidden email]
Ämne: Re: Charts with cumulative sums and log scale?

Yeah that is a bit strange behavior! Simplest solution is to calculate the cumulative sum outside of ggraph and then just plot that variable.

CREATE /CumCount = CSUM(counts).

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=time CumCount MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE
  /FITLINE TOTAL=NO.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: time=col(source(s), name("time"), unit.category())
  DATA: CumCount=col(source(s), name("CumCount"))
  GUIDE: axis(dim(1), label("time"))
  GUIDE: axis(dim(2), label("Cumulative Sum counts"))
  SCALE: log(dim(2), base(2))
  ELEMENT: line(position(time*CumCount))) END GPL.



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

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