# SPSS Statistics

View Only

## Diagram for illustrating KS test?

• #### 1.  Diagram for illustrating KS test?

Posted Sat December 11, 2021 10:08 AM

Dear SPSS community,

I am looking for a way to create a diagram of the empirical CDF with an overlaid estimated theoretical CDF (e.g. normal). To me, this seems the natural diagram to go with the Kolmogorov Smirnov goodness of fit test (that's a wish :-)), but I can't find a way to produce that diagram with SPSS (version 28). I have managed to obtain a diagram of the empirical CDF via the survival functionality (though that is too much of a detour for my taste), but I am lost how I can overlay the theoretical CDF on that diagram. Am I overlooking something nice and simple? (So far, I have gone back to using R for this illustration ...) ​
Best regards,

Ulrike Grömping

------------------------------
Ulrike Grömping
------------------------------

• #### 2.  RE: Diagram for illustrating KS test?

Posted Sat December 11, 2021 11:54 AM
Perhaps a better plot would be a Q-Q plot, which you can produce with the PPLOT (Analyze > Descriptive Statistics > Q-Q Plot) procedure.  It's a little harder to understand, but it gives a better view of the difference between the data and the reference distribution.

However, you can create the cusums of the data using the CREATE (Transform > Create Time Series) procedure, albeit somewhat misnamed, and normalize that and the CDF using a function like CDF.Normal. and then plot these as a scatter or line chart.

If you want to dig into GPL with GGraph, there are cumulative functions that can be used as transformations.  The GPL Examples section has an example of a histogram with a normal  curve.

Here is a snippet of GPL for a histogram with a distribution curve
SOURCE: s = userSource(id("Employeedata"))
DATA: salary=col(source(s), name("salary"))
GUIDE: axis(dim(2), label("Count"))
GUIDE: axis(dim(1), label("Salary"))
ELEMENT: interval(position(summary.count(bin.rect(salary))))
ELEMENT: line(position(density.normal(salary)))

--

• #### 3.  RE: Diagram for illustrating KS test?

Posted Sat December 11, 2021 12:59 PM

Thanks for your thoughts, John! I agree that a QQ plot would be the best choice for inspecting how well the data fit the reference distribution. But for illustrating what the KS test does, i want to compare the CDFs.

Thanks for your pointer to the GGRAPH / GPL. I tried this out using the Chart Builder and modifying the code from there. However, with my small data set, the lines produced look completely unacceptable "as is". I would have to create a fine grid and produce function values for that in order to obtain at least an approximate step function for the ECDF and a smooth curve for the normal CDF. This is all very inconvenient, and definitely not something I want to keep my students busy with - so I guess I stick with R for the time being - unless there is a simpler solution hidden somewhere.

And I still think that it would be a good idea to offer an option for obtaining the chart that shows the empirical cumulative distribution function together with the theoretical cumulative distribution function, whenever someone requests a Kolmogorv Smirnov One-Sample test.

Best regards,

Ulrike Grömping

------------------------------
Ulrike Grömping
------------------------------