IBM Support

How to add line for grand mean to a profile plot of group means

Question & Answer


Question

I wish to produce a profile plot as a line graph where 4 dependent variables represent points on the X axis and there is a line for each of 4 groups. The points on the Y axis represent the means on the respective dependent variables. This graph can be produced with the Chart Builder (from the Graph menu in SPSS). However, I would like to add a fifth line that represents the profile for the grand mean, averaged across all of the cases in the file. Can I request lines for the group means and the grand mean in the same one the line graph dialogs of the Chart Builder?

Answer

The Graph Builder does not have an option to request group means and the grand mean within a single line graph. A feature request has been filed with SPSS Development to include this option.

You can build the graph that you describe with some additional data transfsormations prior to building the graph. The basic strategy is as follows:
1. Use the Aggregate procedure (Data Aggregate) to create a data set with the grand mean on each of the dependent variables. This data set would have a single case.
2. Add the data set with the grand means to the bottom of the case level file (Data->Merge->Add Cases). Use the /IN subcommand to mark the last case as the grand mean with the value 1 on an indicator variable.
3. For the case with the grand means, assign the group variable a value that is 1 higher than the value for the last group. So, if the group variable ranges from 1 to 4, set the group variable to 5 for this case and assign a value label to 5 that indicates that it is the grand mean case.
4 Build the line graph in the Chart Builder as a multiple line graph. Pull the dependent variables to the Y axis and and pull the group variable to the legend. The Overall means line will appear along with the lines for each group.

Here is an example set of syntax commands. The 4 dependent variables are SC1 to SC4. The group variable is SEXRACE (a combination of gender and ethnic variables), which has values 1 to 4. The grand means for SC1 to SC4 are saved in the dataset SCMEANS by the Aggregate procedure. This dataset with the original file as a new case. SEXRACE is set to 5 for this new case and a value label is assigned to the value 5. The graph is then drawn.

COMPUTE brk = 1.
DATASET DECLARE scmeans.
AGGREGATE
/OUTFILE='scmeans'
/BREAK=brk
/sc1 to sc4 = MEAN(sc1 to sc4)
/N_BREAK=N.
ADD FILES /FILE=*
/FILE='scmeans'
/in = avggp.
IF (avggp = 1) sexrace = 5.
ADD VALUE LABELS sexrace 5 "Overall Avg" .
EXECUTE.

* Chart Builder.
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=MEAN(sc1) MEAN(sc2) MEAN(
sc3) MEAN(sc4) sexrace MISSING=LISTWISE REPORTMISSING=NO
TRANSFORM=VARSTOCASES(SUMMARY="#SUMMARY" INDEX="#INDEX")
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: INDEX=col(source(s), name("#INDEX"), unit.category())
DATA: SUMMARY=col(source(s), name("#SUMMARY"))
DATA: sexrace=col(source(s), name("sexrace"), unit.category())
GUIDE: axis(dim(1))
GUIDE: axis(dim(2), label("Mean"))
GUIDE: legend(aesthetic(aesthetic.color.interior), label("Sex & race ",
"classification"))
SCALE: cat(dim(1), include("0", "1", "2", "3"))
SCALE: linear(dim(2), include(0))
SCALE: cat(aesthetic(aesthetic.color.interior), include("1", "2", "3",
"4"))
ELEMENT: line(position(INDEX*SUMMARY), color.interior(sexrace),
missing.wings())
END GPL.

[{"Product":{"code":"SSLVMB","label":"IBM SPSS Statistics"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Not Applicable","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"Not Applicable","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Historical Number

72198

Document Information

Modified date:
16 April 2020

UID

swg21479140