|
Hi all,
I was wondering if it's possible to do the following with SPSS: I want to create a error bar chart with 10 variables and that is easy to do with the drop down menus. I created a separate variable from these 10 variables that creates a new variable that is the mean of all 10 variables. I want this to be a line that goes through the mean so that the reader can quickly where the 10 variables fit in the aggregate. So, an error bar chart of the 10 variables, with a line showing the mean of a different variable. Can this be done? I appreciate your help! Govind -- - Govind Acharya Assistant Director/Senior Research Associate Survey Research Institute, Cornell University 391 Pine Tree Rd. Ithaca, NY 14850 phone: (607) 255-0375; fax: (607) 255-7118 http://www.sri.cornell.edu |
|
As you note, both Graphics>Chart Builder and the Graphics>Error Bar dialogs
will draw the error bars. However neither will provide the reference line defined by the mean of your mean of variables variable. You can add a reference line in the chart editor but you will need to manually provide the value which can be computed in a number of procedures. Descriptives comes to mind as the easiest way to do this. You can get something that looks a bit like of reference line via a constant line drawn between points on the x-axis via GPL. See if this syntax meets your needs. Note that I've only used 3 variables here but you can extend this to 10 with a bit of copy/paste then edit. That crude reference line won't look quite so silly with 10 points on X. input program. loop #i = 1 to 100. do repeat x = v1 to v3. compute x = normal(2). end repeat. compute meanvar=mean(v1 to v3). end case. end loop. end file. end input program. * Chart Builder. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=v1 to v3 meanvar MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: meanvar=col(source(s), name("meanvar")) DATA: v1=col(source(s), name("v1")) DATA: v2=col(source(s), name("v2")) DATA: v3=col(source(s), name("v3")) ELEMENT: interval(position(region.confi.mean( "v1" * v1 )), shape.interior(shape.ibeam) ) ELEMENT: interval(position(region.confi.mean( "v2" * v2 )), shape.interior(shape.ibeam) ) ELEMENT: interval(position(region.confi.mean( "v3" * v3 )), shape.interior(shape.ibeam) ) ELEMENT: point(position(summary.mean( "v1" * v1 )), color.interior(color.red) ) ELEMENT: point(position(summary.mean( "v2" * v2 )), color.interior(color.red) ) ELEMENT: point(position(summary.mean( "v3" * v3 )), color.interior(color.red) ) ELEMENT: line(position(summary.mean(( "v1" + "v2" + "v3" ) *meanvar)), color(color.gray)) END GPL. Notes: * I did this in SPSS 15. No guarantees that it will work in 14. * The interval (bar) ELEMENT draws the error bar for each summary variable while the point ELEMENT displays the mean as a red point. * The line ELEMENT needs one constant for each of the 10 variables on the X axis and draws the "reference" line. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Govind Acharya Sent: Monday, August 13, 2007 8:32 AM To: [hidden email] Subject: error bar chart with mean line Hi all, I was wondering if it's possible to do the following with SPSS: I want to create a error bar chart with 10 variables and that is easy to do with the drop down menus. I created a separate variable from these 10 variables that creates a new variable that is the mean of all 10 variables. I want this to be a line that goes through the mean so that the reader can quickly where the 10 variables fit in the aggregate. So, an error bar chart of the 10 variables, with a line showing the mean of a different variable. Can this be done? I appreciate your help! Govind -- - Govind Acharya Assistant Director/Senior Research Associate Survey Research Institute, Cornell University 391 Pine Tree Rd. Ithaca, NY 14850 phone: (607) 255-0375; fax: (607) 255-7118 http://www.sri.cornell.edu |
|
Hi Govind
I am not sure, if I understand your question correctly. The solution given by ViAnn Beadle gives me a forth point on the x axis labelled 'v1v2v3' with no line. (I am using SPSS 15). I therefore have written a syntax that uses the GPL code from ViAnn Beadle but adds dynamically the reference line. Note: there are two solutions. The first solution assumes you have missing data. The second and simpler solution deals with a data set that has no missing data. Copy the Syntax into the SPSS syntax editor and test it out. Eventually you have to change the information in the template information. The easiest is to produce a template by your own and copy the information into the WRITE OUTFILE command. Have fun Christian ******************************* la volta statistics Christian Schmidhauser, Dr.phil.II Weinbergstrasse 108 Ch-8006 Zurich Tel: +41 (043) 233 98 01 Fax: +41 (043) 233 98 02 email: mailto:[hidden email] internet: http://www.lavolta.ch/ ***************************. * Example with missing data. ***************************. DATA LIST LIST /v1(F8) v2(F8) v3(F8). BEGIN DATA. 2 4 4 4 7 3 5 7 END DATA. * Since we have missing data the command 'compute meanvar=mean(v1 to v3)' will give * a wrong mean. Therefore you have to use VARSTOCASES, then calculate the mean and * restructure back with CASESTOVARS . * adjust the number in the Index1 accordingly. VARSTOCASES /ID = id /MAKE v FROM v1 v2 v3 /INDEX = Index1(3) /NULL = KEEP. Compute break = 1. * compute mean. AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=break /meanvar = MEAN(v). * restructe back . SORT CASES BY ID Index1 . CASESTOVARS /ID = ID /INDEX = Index1 /Separator = "". * Write a template for the reference line. * The template is saved as: d:\temp\ReferenceLine.sgt. * The mean is written as meanvar (from the variabel meanvar) into the template. * The template was generated by saving a template and copying its content into the * WRITE OUTFILE command. Do if $casenum = 1. WRITE OUTFILE='d:\temp\ReferenceLine.sgt' /'<?xml version="1.0" encoding="UTF-8" standalone="no"?>' /'<template SPSS-Version="2.2" ' /' selectPath="900 " ' /' xmlns="http://xml.spss.com/spss/visualization" ' /' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' /' xsi:schemaLocation="http://xml.spss.com/spss/visualization ' /' http://xml.spss.com/spss/visualization/vizml-template-3.0.xsd">' /' <addReferenceLine styleOnly="false" y=" ' /meanvar /' " ycategorical="false"/>' /'</template>'. End if. EXECUTE. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=v1 to v3 MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE TEMPLATE=[ "D:\Temp\ReferenceLine.sgt"]. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: v1=col(source(s), name("v1")) DATA: v2=col(source(s), name("v2")) DATA: v3=col(source(s), name("v3")) ELEMENT: interval(position(region.confi.mean( "v1" * v1 )), shape.interior(shape.ibeam) ) ELEMENT: interval(position(region.confi.mean( "v2" * v2 )), shape.interior(shape.ibeam) ) ELEMENT: interval(position(region.confi.mean( "v3" * v3 )), shape.interior(shape.ibeam) ) ELEMENT: point(position(summary.mean( "v1" * v1 )), color.interior(color.red) ) ELEMENT: point(position(summary.mean( "v2" * v2 )), color.interior(color.red) ) ELEMENT: point(position(summary.mean( "v3" * v3 )), color.interior(color.red) ) END GPL. *******************************. * Example without missing data . *******************************. DATA LIST LIST /v1(F8) v2(F8) v3(F8). BEGIN DATA. 2 4 90 4 4 7 3 5 7 END DATA. compute meanvar_1=mean(v1 to v3). compute break = 1. AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=break /meanvar = MEAN(meanvar_1). * Write a template for the reference line. * The template is saved as: d:\temp\ReferenceLine.sgt. * The mean is written as meanvar (from the variabel meanvar) into the template. * The line style is set to red here. Do if $casenum = 1. WRITE OUTFILE='d:\temp\ReferenceLine.sgt' /'<?xml version="1.0" encoding="UTF-8" standalone="no"?>' /'<template SPSS-Version="2.2" ' /' selectPath="900 " ' /' xmlns="http://xml.spss.com/spss/visualization" ' /' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' /' xsi:schemaLocation="http://xml.spss.com/spss/visualization ' /' http://xml.spss.com/spss/visualization/vizml-template-3.0.xsd">' /' <addReferenceLine styleOnly="false" y=" ' /meanvar /' " ycategorical="false">' /' <style color="#f50000" visible="true"/>' /' </addReferenceLine>' /'</template>'. End if. EXECUTE. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=v1 to v3 MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE TEMPLATE=[ "D:\Temp\ReferenceLine.sgt"]. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: v1=col(source(s), name("v1")) DATA: v2=col(source(s), name("v2")) DATA: v3=col(source(s), name("v3")) ELEMENT: interval(position(region.confi.mean( "v1" * v1 )), shape.interior(shape.ibeam) ) ELEMENT: interval(position(region.confi.mean( "v2" * v2 )), shape.interior(shape.ibeam) ) ELEMENT: interval(position(region.confi.mean( "v3" * v3 )), shape.interior(shape.ibeam) ) ELEMENT: point(position(summary.mean( "v1" * v1 )), color.interior(color.red) ) ELEMENT: point(position(summary.mean( "v2" * v2 )), color.interior(color.red) ) ELEMENT: point(position(summary.mean( "v3" * v3 )), color.interior(color.red) ) END GPL. * Clean up. ERASE FILE = "D:\Temp\ReferenceLine.sgt". -----Ursprungliche Nachricht----- Von: SPSSX(r) Discussion [mailto:[hidden email]]Im Auftrag von ViAnn Beadle Gesendet: Montag, 13. August 2007 18:59 An: [hidden email] Betreff: Re: error bar chart with mean line As you note, both Graphics>Chart Builder and the Graphics>Error Bar dialogs will draw the error bars. However neither will provide the reference line defined by the mean of your mean of variables variable. You can add a reference line in the chart editor but you will need to manually provide the value which can be computed in a number of procedures. Descriptives comes to mind as the easiest way to do this. You can get something that looks a bit like of reference line via a constant line drawn between points on the x-axis via GPL. See if this syntax meets your needs. Note that I've only used 3 variables here but you can extend this to 10 with a bit of copy/paste then edit. That crude reference line won't look quite so silly with 10 points on X. input program. loop #i = 1 to 100. do repeat x = v1 to v3. compute x = normal(2). end repeat. compute meanvar=mean(v1 to v3). end case. end loop. end file. end input program. * Chart Builder. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=v1 to v3 meanvar MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: meanvar=col(source(s), name("meanvar")) DATA: v1=col(source(s), name("v1")) DATA: v2=col(source(s), name("v2")) DATA: v3=col(source(s), name("v3")) ELEMENT: interval(position(region.confi.mean( "v1" * v1 )), shape.interior(shape.ibeam) ) ELEMENT: interval(position(region.confi.mean( "v2" * v2 )), shape.interior(shape.ibeam) ) ELEMENT: interval(position(region.confi.mean( "v3" * v3 )), shape.interior(shape.ibeam) ) ELEMENT: point(position(summary.mean( "v1" * v1 )), color.interior(color.red) ) ELEMENT: point(position(summary.mean( "v2" * v2 )), color.interior(color.red) ) ELEMENT: point(position(summary.mean( "v3" * v3 )), color.interior(color.red) ) ELEMENT: line(position(summary.mean(( "v1" + "v2" + "v3" ) *meanvar)), color(color.gray)) END GPL. Notes: * I did this in SPSS 15. No guarantees that it will work in 14. * The interval (bar) ELEMENT draws the error bar for each summary variable while the point ELEMENT displays the mean as a red point. * The line ELEMENT needs one constant for each of the 10 variables on the X axis and draws the "reference" line. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Govind Acharya Sent: Monday, August 13, 2007 8:32 AM To: [hidden email] Subject: error bar chart with mean line Hi all, I was wondering if it's possible to do the following with SPSS: I want to create a error bar chart with 10 variables and that is easy to do with the drop down menus. I created a separate variable from these 10 variables that creates a new variable that is the mean of all 10 variables. I want this to be a line that goes through the mean so that the reader can quickly where the 10 variables fit in the aggregate. So, an error bar chart of the 10 variables, with a line showing the mean of a different variable. Can this be done? I appreciate your help! Govind -- - Govind Acharya Assistant Director/Senior Research Associate Survey Research Institute, Cornell University 391 Pine Tree Rd. Ithaca, NY 14850 phone: (607) 255-0375; fax: (607) 255-7118 http://www.sri.cornell.edu |
|
In reply to this post by ViAnn Beadle
Thanks so much ViAnn for your help!
best, Govind - Govind Acharya Assistant Director/Senior Research Associate Survey Research Institute, Cornell University 391 Pine Tree Rd. Ithaca, NY 14850 phone: (607) 255-0375; fax: (607) 255-7118 http://www.sri.cornell.edu ViAnn Beadle wrote: > As you note, both Graphics>Chart Builder and the Graphics>Error Bar dialogs > will draw the error bars. However neither will provide the reference line > defined by the mean of your mean of variables variable. > > You can add a reference line in the chart editor but you will need to > manually provide the value which can be computed in a number of procedures. > Descriptives comes to mind as the easiest way to do this. > > You can get something that looks a bit like of reference line via a constant > line drawn between points on the x-axis via GPL. See if this syntax meets > your needs. Note that I've only used 3 variables here but you can extend > this to 10 with a bit of copy/paste then edit. That crude reference line > won't look quite so silly with 10 points on X. > > input program. > loop #i = 1 to 100. > do repeat x = v1 to v3. > compute x = normal(2). > end repeat. > compute meanvar=mean(v1 to v3). > end case. > end loop. > end file. > end input program. > * Chart Builder. > GGRAPH > /GRAPHDATASET NAME="graphdataset" VARIABLES=v1 to v3 meanvar > MISSING=LISTWISE REPORTMISSING=NO > /GRAPHSPEC SOURCE=INLINE. > BEGIN GPL > SOURCE: s=userSource(id("graphdataset")) > DATA: meanvar=col(source(s), name("meanvar")) > DATA: v1=col(source(s), name("v1")) > DATA: v2=col(source(s), name("v2")) > DATA: v3=col(source(s), name("v3")) > ELEMENT: interval(position(region.confi.mean( "v1" * v1 )), > shape.interior(shape.ibeam) ) > ELEMENT: interval(position(region.confi.mean( "v2" * v2 )), > shape.interior(shape.ibeam) ) > ELEMENT: interval(position(region.confi.mean( "v3" * v3 )), > shape.interior(shape.ibeam) ) > ELEMENT: point(position(summary.mean( "v1" * v1 )), > color.interior(color.red) ) > ELEMENT: point(position(summary.mean( "v2" * v2 )), > color.interior(color.red) ) > ELEMENT: point(position(summary.mean( "v3" * v3 )), > color.interior(color.red) ) > ELEMENT: line(position(summary.mean(( "v1" + "v2" + "v3" ) *meanvar)), > color(color.gray)) > END GPL. > > Notes: > > * I did this in SPSS 15. No guarantees that it will work in 14. > > * The interval (bar) ELEMENT draws the error bar for each summary variable > while the point ELEMENT displays the mean as a red point. > > * The line ELEMENT needs one constant for each of the 10 variables on the X > axis and draws the "reference" line. > > > > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of > Govind Acharya > Sent: Monday, August 13, 2007 8:32 AM > To: [hidden email] > Subject: error bar chart with mean line > > Hi all, > > I was wondering if it's possible to do the following with SPSS: > > I want to create a error bar chart with 10 variables and that is easy to > do with the drop down menus. I created a separate variable from these > 10 variables that creates a new variable that is the mean of all 10 > variables. I want this to be a line that goes through the mean so that > the reader can quickly where the 10 variables fit in the aggregate. So, > an error bar chart of the 10 variables, with a line showing the mean of > a different variable. Can this be done? > > I appreciate your help! > > Govind > > -- > - > Govind Acharya > Assistant Director/Senior Research Associate > Survey Research Institute, Cornell University > 391 Pine Tree Rd. > Ithaca, NY 14850 > phone: (607) 255-0375; fax: (607) 255-7118 > http://www.sri.cornell.edu > |
| Free forum by Nabble | Edit this page |
