Perhaps this has to be done in GPL but I want to avoid that if possible. Is it possible outside of GPL? So here’s the background. A bunch of folks recounted the timeline and history of their romantic relationships. In particular they rated each relationship on its stability, intimacy, and pleasure. Some people reported one relationship,
other folks, two relationships, others, nine relationships. The data are now structured as one record per relationship. So, long format. The plotting problem is this. We want to plot stability score, for instance, by relationship sequence number for persons have a given number of relationships. So, you could say plot stability by relationship sequence for number of relationships
= ‘x’. The result is as many lines on the graph/plot as persons having that number of relationships. Ideally but far less important, I’d also like each line to be color or line symbol (e.g., dashes etc) coded. I understand that too many lines will be a jumble;
I can deal with that by controlling the number of persons per graph, therefore multiple graphs per relationship. Certainly, an alternative is one chart/plot per person; that will be a lot of plots, too many to look at. Not acceptable at the moment. I’ve looked at the Graph command but it apparently can’t handle the ‘by’ element and absolutely can’t handle the ‘for’ element. The regression variable plots from the drop-down don’t respect the ‘by’ element and I don’t know how to specify
multiple lines per chart. Chartbuilder seems like it might work, I don’t see how either the ‘by’ element or the ‘for’ element is specified or controlled. All that said, I rarely use any graphing, from legacy dialogs (GGRAPH?) to GPL, so I really don’t know
anything. Can someone help? If something is not clear, I’ll certainly do my best to explain better.
Thanks, Gene Maguin |
Sorry I can't totally grasp what you want. Can you post a snippet of data and
maybe a hand drawn sketch of what you want? I'm guessing you will want to look up the "split()" modifier for GPL elements. ----- 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 |
In reply to this post by Maguin, Eugene
Gene,
How about paneling by the number of relationships? Something like (untested):
GRAPH
/LINE MEAN(Stability) BY Sequence /PANEL COLVAR=Number_of_Relationships COLOP=CROSS.
This doesn't have multiple lines on the same graph, but the paneling provides a side by side visual comparison without a potential jumble or the need to play with line types.
Brian Dates
From: SPSSX(r) Discussion <[hidden email]> on behalf of Maguin, Eugene <[hidden email]>
Sent: Friday, March 23, 2018 3:22:44 PM To: [hidden email] Subject: Now, on to graphing problems Perhaps this has to be done in GPL but I want to avoid that if possible. Is it possible outside of GPL? So here’s the background. A bunch of folks recounted the timeline and history of their romantic relationships. In particular they rated each relationship on its stability, intimacy, and pleasure. Some people reported one relationship, other folks, two relationships, others, nine relationships. The data are now structured as one record per relationship. So, long format.
The plotting problem is this. We want to plot stability score, for instance, by relationship sequence number for persons have a given number of relationships. So, you could say plot stability by relationship sequence for number of relationships = ‘x’. The result is as many lines on the graph/plot as persons having that number of relationships. Ideally but far less important, I’d also like each line to be color or line symbol (e.g., dashes etc) coded. I understand that too many lines will be a jumble; I can deal with that by controlling the number of persons per graph, therefore multiple graphs per relationship. Certainly, an alternative is one chart/plot per person; that will be a lot of plots, too many to look at. Not acceptable at the moment.
I’ve looked at the Graph command but it apparently can’t handle the ‘by’ element and absolutely can’t handle the ‘for’ element. The regression variable plots from the drop-down don’t respect the ‘by’ element and I don’t know how to specify multiple lines per chart. Chartbuilder seems like it might work, I don’t see how either the ‘by’ element or the ‘for’ element is specified or controlled. All that said, I rarely use any graphing, from legacy dialogs (GGRAPH?) to GPL, so I really don’t know anything. Can someone help? If something is not clear, I’ll certainly do my best to explain better.
Thanks, Gene Maguin |
Over the weekend I realized how to do the plotting, at least for the little example dataset. So I think I have the problem solved but I’ll see when I try out
what follows on the real dataset. I want to thank the folks that responded and tried their best to help me. The clear feedback I got was that my explanation—clear to me, of course—was not clear to anybody else. What follows is an example dataset, a couple
of Graph command things I tried last week and the solution I came up that produces what I wanted. Thanks, Gene Maguin
input program. loop person=1 to 3. loop relatseq=1 to 3. compute nrelats=3. compute stability=trunc(rv.uniform(5,11)). end case. end loop. end loop. loop person=4 to 5. loop relatseq=1 to 5. compute nrelats=5. compute stability=trunc(rv.uniform(5,11)). end case. end loop. end loop. end file. end input program. leave person. format person relatseq nrelats stability(f3.0). execute. print / person relatseq nrelats stability. execute. 1 1 3 10
1 2 3 7
1 3 3 7
2 1 3 5
2 2 3 8
2 3 3 9
3 1 3 6
3 2 3 8
3 3 3 6
4 1 5 9
4 2 5 5
4 3 5 6
4 4 5 7
4 5 5 10
5 1 5 8
5 2 5 5
5 3 5 10
5 4 5 5
5 5 5 10 temporary. select if (person eq 2). graph line(simple)=value(stability) by relatseq. temporary. select if (nrelats eq 3). graph line(simple)=value(stability) by relatseq. sort cases by nrelats relatseq person. casestovars id=nrelats relatseq. temporary. select if (nrelats eq 3). graph line(simple)=value(stability.1 stability.2 stability.3) by relatseq. temporary. select if (nrelats eq 5). graph line(simple)=value(stability.1 stability.2) by relatseq. |
Gene,
I've tried your syntax and I'm not getting Stability.1, Stability.2, and Stability.3. Instead I'm getting a variable Stability. Is there a bug in my software or does the syntax need tweaking? Thanks.
Brian
From: SPSSX(r) Discussion <[hidden email]> on behalf of Maguin, Eugene <[hidden email]>
Sent: Monday, March 26, 2018 10:29:54 AM To: [hidden email] Subject: Re: Now, on to graphing problems Over the weekend I realized how to do the plotting, at least for the little example dataset. So I think I have the problem solved but I’ll see when I try out what follows on the real dataset. I want to thank the folks that responded and tried their best to help me. The clear feedback I got was that my explanation—clear to me, of course—was not clear to anybody else. What follows is an example dataset, a couple of Graph command things I tried last week and the solution I came up that produces what I wanted.
Thanks, Gene Maguin
input program. loop person=1 to 3. loop relatseq=1 to 3. compute nrelats=3. compute stability=trunc(rv.uniform(5,11)). end case. end loop. end loop. loop person=4 to 5. loop relatseq=1 to 5. compute nrelats=5. compute stability=trunc(rv.uniform(5,11)). end case. end loop. end loop. end file. end input program. leave person. format person relatseq nrelats stability(f3.0). execute.
print / person relatseq nrelats stability. execute.
1 1 3 10 1 2 3 7 1 3 3 7 2 1 3 5 2 2 3 8 2 3 3 9 3 1 3 6 3 2 3 8 3 3 3 6 4 1 5 9 4 2 5 5 4 3 5 6 4 4 5 7 4 5 5 10 5 1 5 8 5 2 5 5 5 3 5 10 5 4 5 5 5 5 5 10
temporary. select if (person eq 2). graph line(simple)=value(stability) by relatseq.
temporary. select if (nrelats eq 3). graph line(simple)=value(stability) by relatseq.
sort cases by nrelats relatseq person. casestovars id=nrelats relatseq.
temporary. select if (nrelats eq 3). graph line(simple)=value(stability.1 stability.2 stability.3) by relatseq.
temporary. select if (nrelats eq 5). graph line(simple)=value(stability.1 stability.2) by relatseq. |
Hmm, I don’t know.
What did you get when you ran this? sort cases by nrelats relatseq person. casestovars id=nrelats relatseq. temporary. select if (nrelats eq 3). graph line(simple)=value(stability.1 stability.2 stability.3) by relatseq. Gene From: Dates, Brian <[hidden email]>
Gene, I've tried your syntax and I'm not getting Stability.1, Stability.2, and Stability.3. Instead I'm getting a variable Stability. Is there a bug in my software or does the syntax need tweaking? Thanks. Brian From: SPSSX(r) Discussion <[hidden email]>
on behalf of Maguin, Eugene <[hidden email]> Over the weekend I realized how to do the plotting, at least for the little example dataset. So I think I have the problem solved but I’ll see when I try out
what follows on the real dataset. I want to thank the folks that responded and tried their best to help me. The clear feedback I got was that my explanation—clear to me, of course—was not clear to anybody else. What follows is an example dataset, a couple
of Graph command things I tried last week and the solution I came up that produces what I wanted. Thanks, Gene Maguin
input program. loop person=1 to 3. loop relatseq=1 to 3. compute nrelats=3. compute stability=trunc(rv.uniform(5,11)). end case. end loop. end loop. loop person=4 to 5. loop relatseq=1 to 5. compute nrelats=5. compute stability=trunc(rv.uniform(5,11)). end case. end loop. end loop. end file. end input program. leave person. format person relatseq nrelats stability(f3.0). execute. print / person relatseq nrelats stability. execute. 1 1 3 10
1 2 3 7
1 3 3 7
2 1 3 5
2 2 3 8
2 3 3 9
3 1 3 6
3 2 3 8
3 3 3 6
4 1 5 9
4 2 5 5
4 3 5 6
4 4 5 7
4 5 5 10
5 1 5 8
5 2 5 5
5 3 5 10
5 4 5 5
5 5 5 10 temporary. select if (person eq 2). graph line(simple)=value(stability) by relatseq. temporary. select if (nrelats eq 3). graph line(simple)=value(stability) by relatseq. sort cases by nrelats relatseq person. casestovars id=nrelats relatseq. temporary. select if (nrelats eq 3). graph line(simple)=value(stability.1 stability.2 stability.3) by relatseq. temporary. select if (nrelats eq 5). graph line(simple)=value(stability.1 stability.2) by relatseq. ===================== 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
|
In reply to this post by Maguin, Eugene
Given your example data before reshaping, to superimpose all of the lines on
one plot you could something like below. *********************************************************************************************. *Jitter the points slightly. SET SEED 10. COMPUTE stabJitt = stability + RV.UNIFORM(-0.2,0.2). FORMATS stabJitt (F2.0). EXECUTE. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=relatseq stability stabJitt person MISSING=VARIABLEWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: relatseq=col(source(s), name("relatseq"), unit.category()) DATA: stability=col(source(s), name("stability")) DATA: stabJitt=col(source(s), name("stabJitt")) DATA: person=col(source(s), name("person"), unit.category()) GUIDE: axis(dim(1), label("relatseq")) GUIDE: axis(dim(2), label("stability"), delta(1), start(5)) SCALE: linear(dim(2), min(4.5), max(10.5)) ELEMENT: line(position(relatseq*stabJitt), split(person), missing.wings(), size(size."1")) END GPL. *********************************************************************************************. <http://spssx-discussion.1045642.n5.nabble.com/file/t329824/LinesGene.png> With the lines as is, I slightly jittered them so it is easier to see the overlap. With many folks, it will become a mess. So one way is to aggregate to typical patterns or cluster the trajectories and plot those different clusters in small-multiples. See https://stats.stackexchange.com/a/127023/1036 for an example. Another way that sometimes help with the lines overplotting is to use splines. But that will still be a mess if you have many more lines than here. Use of transparency can help some as well, see https://andrewpwheeler.wordpress.com/2016/08/12/plotting-panel-data-with-many-lines-in-spss/. *********************************************************************************************. *Sometimes using splines help figure out the orientation as well, note I am not using the jittered points, but the lines are all separated. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=relatseq stability stabJitt person MISSING=VARIABLEWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: relatseq=col(source(s), name("relatseq"), unit.category()) DATA: stability=col(source(s), name("stability")) DATA: stabJitt=col(source(s), name("stabJitt")) DATA: person=col(source(s), name("person"), unit.category()) GUIDE: axis(dim(1), label("relatseq")) GUIDE: axis(dim(2), label("stability"), delta(1), start(5)) SCALE: linear(dim(2), min(4.5), max(10.5)) ELEMENT: line(position(smooth.spline(relatseq*stability)), split(person), missing.wings(), size(size."1")) END GPL. *********************************************************************************************. <http://spssx-discussion.1045642.n5.nabble.com/file/t329824/LinesGene1.png> ----- 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,
Thank you for your suggestions. I had thought of jitter but not in the way you did it. I kind of think there is a jitter function in gpl but I wanted to stay out of gpl. I like the idea of person-specific plots because they do give better shape visualization and I'll try those out. You mentioned splines and they might be helpful/useful; however, are they implemented in spss and accessible for data series modeling? I haven't ever seen them but I've never wanted to use them. Gene Maguin -----Original Message----- From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Andy W Sent: Tuesday, March 27, 2018 9:24 AM To: [hidden email] Subject: Re: Now, on to graphing problems Given your example data before reshaping, to superimpose all of the lines on one plot you could something like below. *********************************************************************************************. *Jitter the points slightly. SET SEED 10. COMPUTE stabJitt = stability + RV.UNIFORM(-0.2,0.2). FORMATS stabJitt (F2.0). EXECUTE. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=relatseq stability stabJitt person MISSING=VARIABLEWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: relatseq=col(source(s), name("relatseq"), unit.category()) DATA: stability=col(source(s), name("stability")) DATA: stabJitt=col(source(s), name("stabJitt")) DATA: person=col(source(s), name("person"), unit.category()) GUIDE: axis(dim(1), label("relatseq")) GUIDE: axis(dim(2), label("stability"), delta(1), start(5)) SCALE: linear(dim(2), min(4.5), max(10.5)) ELEMENT: line(position(relatseq*stabJitt), split(person), missing.wings(), size(size."1")) END GPL. *********************************************************************************************. <http://spssx-discussion.1045642.n5.nabble.com/file/t329824/LinesGene.png> With the lines as is, I slightly jittered them so it is easier to see the overlap. With many folks, it will become a mess. So one way is to aggregate to typical patterns or cluster the trajectories and plot those different clusters in small-multiples. See https://stats.stackexchange.com/a/127023/1036 for an example. Another way that sometimes help with the lines overplotting is to use splines. But that will still be a mess if you have many more lines than here. Use of transparency can help some as well, see https://andrewpwheeler.wordpress.com/2016/08/12/plotting-panel-data-with-many-lines-in-spss/. *********************************************************************************************. *Sometimes using splines help figure out the orientation as well, note I am not using the jittered points, but the lines are all separated. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=relatseq stability stabJitt person MISSING=VARIABLEWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: relatseq=col(source(s), name("relatseq"), unit.category()) DATA: stability=col(source(s), name("stability")) DATA: stabJitt=col(source(s), name("stabJitt")) DATA: person=col(source(s), name("person"), unit.category()) GUIDE: axis(dim(1), label("relatseq")) GUIDE: axis(dim(2), label("stability"), delta(1), start(5)) SCALE: linear(dim(2), min(4.5), max(10.5)) ELEMENT: line(position(smooth.spline(relatseq*stability)), split(person), missing.wings(), size(size."1")) END GPL. *********************************************************************************************. <http://spssx-discussion.1045642.n5.nabble.com/file/t329824/LinesGene1.png> ----- 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 |
For person specific plots you would just replace the ELEMENT line in my
suggested plots with something like: COORD: rect(dim(1,2), wrap()) ELEMENT: line(position(relatseq*stabJitt*person), missing.wings(), size(size."1")) I'm not sure offhand if you can jitter entire lines in inline GPL, but yes it is easier often to do it to the data directly. I don't understand your spline question. The splines in the graphs assume no error, it is just a particular formula to interpolate the line. Are you perhaps asking about spline basis functions to model the trajectories over time -- like in https://andrewpwheeler.wordpress.com/2013/06/06/restricted-cubic-splines-in-spss/? Making those basis functions for individuals is sometimes hard, because if you don't have the same measure points you can sometimes wind up with basis variables that are not identified (depending on the modelling strategy, fixed effects especially). ----- 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 |
In reply to this post by Andy W
Andy,
Would you give me some help with this please. I am using your small multiples code as follows to plot stability by relateseq (relationship number) for only persons with three total relationships. What I get is the page but not charts. Thanks, Gene Maguin recode nrelats(3=1)(elsse=0) into pick. execute. filter by pick. * number of relationships=3. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=relatseq stability IDcode /GRAPHSPEC SOURCE=INLINE. BEGIN GPL PAGE: begin(scale(1000px,1000px)) SOURCE: s=userSource(id("graphdataset")) DATA: relatseq=col(source(s), name("RelatSeq")) DATA: stability=col(source(s), name("Stability")) DATA: IDcode=col(source(s), name("Person"), unit.category()) COORD: rect(dim(1,2), wrap()) GUIDE: axis(dim(1), null()) GUIDE: axis(dim(2), null()) GUIDE: axis(dim(3), opposite()) SCALE: linear(dim(1), min(1), max(3)) ELEMENT: line(position(relatseq*stability*IDcode)) PAGE: end() END GPL. filter off. ===================== 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 |
Free forum by Nabble | Edit this page |