When working with probit models, it is often useful to calculate the pseudo r2 value. This value provides an indication of how well the model fits the data. In this article, we will explore three different ways to calculate the pseudo r2 in probit using Julia.

## Option 1: Using the `GLM` package

The `GLM` package in Julia provides a convenient way to fit generalized linear models, including probit models. To calculate the pseudo r2, we can use the `deviance` function to obtain the deviance of the model, and then divide it by the null deviance. Here is the code:

```
using GLM
# Fit the probit model
model = glm(@formula(y ~ x), data, Binomial(), ProbitLink())
# Calculate the pseudo r2
pseudo_r2 = 1 - deviance(model) / null_deviance(model)
```

## Option 2: Manually calculating the pseudo r2

If you prefer a more manual approach, you can calculate the pseudo r2 by comparing the likelihood of the fitted model with the likelihood of the null model. Here is the code:

```
# Fit the probit model
model = glm(@formula(y ~ x), data, Binomial(), ProbitLink())
# Calculate the likelihood of the fitted model
fitted_likelihood = sum(logpdf.(Probit(), model.mu))
# Calculate the likelihood of the null model
null_likelihood = sum(logpdf.(Probit(), mean(y)))
# Calculate the pseudo r2
pseudo_r2 = 1 - fitted_likelihood / null_likelihood
```

## Option 3: Using the `StatsModels` package

The `StatsModels` package in Julia provides another way to fit statistical models. To calculate the pseudo r2, we can use the `NullDeviance` and `Deviance` functions. Here is the code:

```
using StatsModels
# Fit the probit model
model = glm(@formula(y ~ x), data, Binomial(), ProbitLink())
# Calculate the pseudo r2
pseudo_r2 = 1 - Deviance(model) / NullDeviance(model)
```

After exploring these three options, it is clear that using the `GLM` package is the most straightforward and convenient way to calculate the pseudo r2 in probit models. It provides a simple function to obtain the deviance and null deviance, making the calculation of the pseudo r2 a one-liner. Therefore, option 1 is the recommended approach.