A Little UX and HCI
I’ve been working with a student doing experiments based on Gestalt psychology and User Experience (UX) and Human Computer Interaction (HCI). She wanted to find out whether the Gestalt concepts of similarity and proximity could be applied to a user interface (UI). So she set up an experiment to see what happened.
In summary, she tested using UIs with similarity/no similarity and proximity/no proximity. The subjects were given a task that would test each condition and their times were compared. After each test, the times were saved in a MySQL database and then retrieved to compare the mean times (average amount of time) that each task took. As predicted, the raw data showed that when the Gestalt principles were observed, the task took less time than when they were not.
While just looking at the data showed a difference, she did not know whether the differences were significant. The most appropriate way to find whether the differences are significant is to conduct a statistical test called a “means test” or “t-test” that compares two means. The t-test would tell us with a precise degree of probability whether the differences were random or not. Use the following buttons to view the outcome and download the files:
The T-Test

Figure 1: The t-test
- t: This is the value generated by the t-test. Using it, we use a statistical look-up table to see to what degree this is significant or not. (Because the sample size is 50, the degrees of freedom is 49, and so the t value must be 3.2651 or greater for the difference to be significant at the .001 level of significance. That means there’s about 1 chance in 1000 that these differences would be random.)
- x1, x2: The x1 and x2 values are the means. This value is easy to calculate. You just divide the total of the values in the array using the function array_sum($array) by the number of cases–count($array). (In the diagram you see the x’es with a line over them and the numbers are subscripted.)
- Triangle: The triangle (or delta) is the symbol used for difference in the samples. The null hypothesis is that there will be no differences, and so the value of delta is zero.
- s1,s2: The s values are standard deviations. These are the amount of differences between the observed value and the mean. In the formula, the s values are squared–s^2.The standard deviation algorithm can be found in your PHP Manual.
- n1, n2: The n values are the total number of values in the samples. In PHP, those values can easily be determined by the count($array) function.
- Square root symbol: We need to divide the top part of the formula by the square root of the standard deviations divided by the total number of cases in each sample. Again, that’s easy using the sqrt($calc) function built into PHP.
By breaking down the problem in this manner, you can quickly see that you need only three values and two arrays:
- Mean
- Standard Deviation
- Number of cases
The arrays need to be numeric, and the delta value in this case is zero; so that could be left out of the formula if we wanted. However, just to keep it in mind, it will be represented by the literal 0.
Making Simple
The purpose of this post is to illustrate the OOP principle,
A class should only have a single responsibility.
The principle is both to modularize problem solving and create reusable parts. Most PHP programmers don’t want to “waste time” creating additional code, and OOP programming that modularizes problem solving certainly requires more code than one that does not. However, the more code in a file or class, the more particularized it is and the more difficult it is to reuse. So, rather than “wasting time,” in the long run you save time by having reusable code. Keep in mind that businesses that hired coders encouraged OOP programming because over time, they spend less effort starting all over every time they wanted to change a program or write a new one. Modularized coding allowed many parts to be reused and changes could be made to even the most complex programs.
Keeping this in mind, we can modularize the t-test into parts that not only solve the problem at hand and make it simpler to understand but is flexible enough to be reusable.
Figure 2 shows the class diagram for the t-test. As with the Chi Square example a while back, this example also uses the Template Method design pattern. However, it breaks the solution down into more parts.

Figure 2: Class diagram for means test.
The MeansTest class implements the IMeansTest interface (an abstract class) that includes a templateMethod() function to order the steps in the means test. The steps in the algorithm are cast as abstract functions to be implemented in the child class. First, it gets the means from the Mean class, then, using the mean value, it gets the standard deviation from the StandardDeviation class, and finally the MeansTest object puts them together for the t-test value.
Continue reading ‘Breaking Down Large PHP Problems into Classes: A Class Should Only have a Single Responsibility’
Recent Comments