## Friday, 29 March 2013

### Statistical tests

In landscape mode, when you swipe up, you obtain a pink display with various statistical tests, as below (you can watch the demo on http://www.youtube.com/watch?v=vwbfddgwDwo).

The paired/unpaired t-tests and the small sample hypothesis test are two-tailed as the Student-t distribution is symmetric, so the 95% confidence interval lies between the two tails, where the area of each tail is 0.025 (i.e. 2.5% of the total probability).

For the chi-squred test, the probability is asymmetric, as its support occurs for only positive values, so it is a one-tailed test (i.e. for the 95 % confidence interval, the single tail area is 0.05, hence 5% of the total probability). The x2 value is the chi-squared value, df is the degree of freedom (one less the number of categories), and the c2 parameter is the Critical Value. If the chi-squared value exceeds the critical value we reject the Null Hypothesis that the observed frequencies do come from the assumed distribution with the expected frequencies. Note that all expected frequencies need to be greater than 0.

A worked example of the chi-squared test is displayed in the screenshot below (the right box, Box B, needs to be populated with the expected frequencies while Box A needs to be populated by the observed frequencies - the number of degrees is 3):-

From the above screenshot, the chi squared value is much lower than the Critical value, so we accept the null hypothesis.

Note that the critical value for 3 degrees of freedom is 7.81473 - as a cross check, you can swipe down then swipe left/right to the chi-squared distribution, and enter 0.95 in the probability field, 0 in the lower limit, and 3 for the k parameter (i.e. the degrees of freedom), leaving the Upper Limit blank, finally pressing calculate

The upper limit will be the critical value, and this is indeed the case. If you wanted a different confidence interval, say for 99%, you would enter 0.99 in the probability field, and obtain a new Critical Value against which to compare the chi squared value x2 with.

### The normalised incomplete gamma function and its inverse.

The Scientific calculator has the two types of normalised incomplete gamma function (in addition to the single-parameter Gamma function $\Gamma(x)$ itself) - the lower and upper functions, denoted by $P(a,x)$ and $Q(a,x)$ respectively. These are accessible using the fourth segment, as shown below:-

The functions take in two arguments, so you need to enter a number (the $a$ parameter), then press the relevant function button, followed by another number ($x$), then press the equal button to obtain the result.

The (complete) Gamma function is:-
$\Gamma(a)=\int_0^\infty t^{a-1}e^{-t}dt$

The equation for the Lower Normalised Incomplete Gamma function is:-
$P(a,x)=\frac{1}{\Gamma(a)}\int_0^xt^{a-1}e^{-t}dt$

while that for the Upper Normalised Incomplete Gamma function is:-
$Q(a,x)=\frac{1}{\Gamma(a)}\int_x^{\infty}t^{a-1}e^{-t}dt$

Note that $P(a,x) + Q(a,x) = 1$.

The Lower Normalised Incomplete Gamma function is the CDF of the Gamma probability density function $\Gamma(\alpha,\beta)$, with $\beta$ set to 1, so we can use the landscape mode CDF/inverse-CDF calculator to find its inverse with respect to $x$.

Thus, to invert the lower function (i.e. to find $x$), enter the $\alpha$ parameter, put the input in the probability field, put 1 into the $\beta$ parameter, and set the lower limit to 0. The result will populate the Upper Limit, once the calculate button is pressed. For a worked example, finding $x$ such that $P(3,x) = 0.5$ (i.e. $\alpha = 3$), see screenshot below (the result is approx. 2.6741):-

As the underlying algorithm is quite numerically intensive for yielding high precision results, there will be a delay of a few seconds.

To invert the upper normalised function, simply subtract its value from 1 and enter the result into the probability field.

As a side note, you can use the Gamma function to evaluate the Beta function
($B(a,b)=\int_0^1t^{(a-1)}(1-t)^{(b-1)}dt$) as follows:-

$B(a,b) = \frac{\Gamma(a)\Gamma(b)}{\Gamma(a+b)}$

## Wednesday, 27 March 2013

### Inverse CDF method: Simulating random variates

Using the inverse CDF method, you can generate a random number from any of the 17 distributions supported by SciStatCalc by generating a uniformly distributed random number (which has a value between 0 and 1) as below,

and then copying and pasting the red result onto the probability field of the distribution of interest (swipe down first!), filling in the lower limit field (which will be either 0 or -inf, depending on the support of the distribution) and all the relevant parameter fields.

Press calculate to evaluate the upper limit - this value will be your desired random variate. These are shown below, for the case where we wish to generate a beta distributed random variable with alpha set to 1 and beta set to 2 - the result is approximately 0.3899.

## Saturday, 9 March 2013

### Introducing the iOS app SciStatCalc

Welcome to the support page for the iOS app SciStatCalc. The portrait mode operation is a Scientific Calculator, a screenshot of which is displayed below. There are five segments.

The mathematical function buttons are colour coded - the inverse counterpart to a function is red, while the function itself is blue. Functions and corresponding inverses occur on the same display.

The following functions are supported: sin, cos, tan, arcsin, arccos, arctan, square root, square, sinh, cosh, tanh, arcsinh, arccosh, arctanh, cube root, cube, $x^y$, $log_yx$ ,$10^x$, $log_ex$, $e^x$, $nPr$, $nCr$, $1/x$, $\Gamma(x)$, error function, inverse error function, lower and upper normalised incomplete gamma functions $P(a,x)$ and $Q(a,x)$. For the trigonometric functions, you can select between degrees and radians. There is also an $lcm$ (least common multiple) and a $gcd$ (greatest common divisor) function.

In the last segment, there is a number stack system, where you can push numbers and pop numbers off a stack, clear the entire stack, calculate the sum, average and the standard deviation of the numbers within the stack.

When the device is oriented in landscape mode, ensuring that the Home button is on the left, a CDF/inverse-CDF Calculator is displayed. In this mode, swiping left/right results in a different distribution being displayed. Two out of the three fields (Upper Limit,  Lower Limit, Probability) must be filled in, as do all the settable parameter fields - pressing the Calculate button results in the single missing field being updated with the result. When filling in the lower/upper limit, you can enter -inf or inf for minus/plus infinity respectively - of course, the ranges will only be valid for the support of the particular distribution. Screenshots occur below.

The following distributions are supported:-
1. Beta
2. Binomial
3. Cauchy-Lorentz
4. Chi-squared
5. Exponential
6. F-distribution
7. Gamma (two parameterisations)
8. Gaussian
9. Geometric
10. Laplace
11. Logistic
12. Log-Normal
13. Pascal
14. Poisson
15. Rayleigh
16. Student-t
17. Weibull
Staying in landscape mode, if you swipe up, you obtain a statistical tests calculator, which includes the following:

1. Unpaired Student's t-test
2. Paired Student's t-test
3. Small sample hypothesis test
4. Chi-squared test
5. Uniform Random Number Generator

In this mode, swiping left/right will select one of the statistical tests. To revert back to the CDF/inverse-CDF calculator, simply swipe down. Some screenshots occur below.

Orienting the device in Portrait mode will bring back the Scientific Calculator.

In Portrait mode, you can copy the number displayed by swiping LEFT resulting in the following display, in order to paste to a textfield in the landscape StatsCalc (swiping right while entering a number will erase the last digit..)

Orienting the device in landscape mode, you simply paste following the usual way.

To paste from landscape to portrait mode, once in portrait mode, pan with two fingers on the display.

You can purchase the App from the App Store.