“ANOVA Using JavaScript” in Visual Studio Magazine

I wrote an article titled “ANOVA Using JavaScript” in the November 2025 edition of Microsoft Visual Studio Magazine. See https://visualstudiomagazine.com/articles/2025/11/03/anova-using-javascript.aspx.

Analysis of variance (ANOVA) is a classical statistics technique that’s used to infer if the unknown means (averages) of three or more groups are likely to all be equal or not, based on the variances of samples from the groups. For example, imagine that there are four high schools and you want to know if the average math abilities of students in the four schools are the same or not.

Suppose that it’s too difficult and expensive to give all the students in the four schools a math test. So you randomly select 10 students from each school and give them the test. Some of the students fail to take the test so not all groups have the same size. You can use ANOVA to infer if the average math ability in all four schools is the same or not.

The output of my demo program is:

Begin ANOVA using JavaScript
The goal is infer if 3 or more population
means are all equal based on samples.

The sample data is:

Group1:     3.0    4.0    6.0    5.0
Group2:     8.0   12.0    9.0   11.0   10.0    8.0
Group3:    13.0    9.0   11.0    8.0   12.0

Calculating F-statistic (verbosely)
Group [0] mean = 4.50
Group [1] mean = 9.67
Group [2] mean = 10.60
Overall mean = 8.60

Calculated SSb = 94.0667
Calculated MSb = 47.0333
Calculated SSw = 35.5333
Calculated MSw = 2.9611

F stat = MSb / MSw
F stat = 15.884
The degrees of freedom are
2, 12

Calculating p-value from F stat, df1, df2
p-value = 0.00042480

The p-value is probability that all
group means are equal.
Interpreting the p-value is a bit subtle.

End demo

Calculating the F-statistics is very simple. But calculating the p-value is very difficult. The p-value is computed using I(x; a, b) which is the regularized incomplete beta function, which is computed using the using the log-beta function, and the log-beta function is computed using the log-gamma function, and the log-gamma function is computed using the Lanczos g=5, n=7 approximation algorithm. Whew!

One significant weakness of ANOVA is that it’s often impossible to test the assumptions that the data sources are Gaussian distributed and have equal variances. This is another reason why ANOVA conclusions should be conservative.

An ANOVA analysis is intended for scenarios with three or more populations/groups. A closely related classical statistics technique is called the Student’s t-test. The t-test is used to infer if the unknown means of exactly two populations are the same or not. It is possible to use ANOVA for just two groups, but the t-test is a more common approach. Mathematically, ANOVA with two groups is exactly equivalent to the t-test.



Comedy movies are a funny thing. There’s a huge variance in opinions: What’s funny to one person is not funny to another. Here are three comedy movies that received terrible reviews, but are movies that I think are very entertaining.

Left: “Year One” (2009) – Zed (actor Jack Black) and Oh (Michael Cera) are members of a primitive tribe in Biblical times. They get banished from their village and have all kinds of adventures. This film received just a 13% approval. Typical review: “Scattershot and silly, squandering its potential by relying on juvenile bawdy humor”. But I give the movie my personal A- grade.

Center: “Stuck on You” (2003) – Bob and Walt Tenor (actors Matt Damon and Greg Kinnear) are conjoined twins who live in Massachusetts. They go to Hollywood so Walt can become an actor. They find girlfriends May and April. This film is rated just 5 out of 10 stars. Typical review: “Implausible, overheated potboiler that squanders a stellar cast”. But I give the movie my personal A grade.

Right: “Blended” (2014) – Widower Jim (actor Adam Sandler) has three daughters and divorcee Lauren (Drew Barrymore) has two boys. Jim and Lauren go on a disastrous blind date then later the two families end up on vacation in Africa together. This movie got only 16% approval. Typical review: “Retrograde gender politics and sentimental hypocrisy about male behavior”. But I give the movie my personal A- grade.


This entry was posted in Machine Learning. Bookmark the permalink.

Leave a Reply