Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Horseshoe Prior #836

Merged
merged 19 commits into from
Sep 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update of the examples section of README.md file and homepage from in…
…dex.qmd
julianlheureux committed Mar 30, 2024

Verified

This commit was signed with the committer’s verified signature.
torkelrogstad Torkel Rogstad
commit 31c3b1734d6dc13107b3ed804290bd41223ff407
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -19,3 +19,4 @@ docs/_build
.vscode/
pytest.ini
/.quarto/
.Rproj.user
49 changes: 36 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -32,45 +32,68 @@ Bambi requires working versions of ArviZ, formulae, NumPy, pandas and PyMC. Depe
In the following two examples we assume the following basic setup

```python
import arviz as az
import bambi as bmb
import numpy as np
import pandas as pd

data = pd.DataFrame({
"y": np.random.normal(size=50),
"g": np.random.choice(["Yes", "No"], size=50),
"x1": np.random.normal(size=50),
"x2": np.random.normal(size=50)
})
```

### Linear regression

A simple fixed effect model is shown in the example below.

```python
model = bmb.Model("y ~ x1 + x2", data)
fitted = model.fit()
#### Read in a database from the package content
data = bmb.load_data("sleepstudy")

# Initialize the fixed effect only model
model = bmb.Model('Reaction ~ Days', data)
print(model) # Get model description

# Fit the model using 1000 on each chain
results = model.fit(draws=1000)

# Key summary and diagnostic info on the model parameters
az.summary(results)

# Use ArviZ to plot the results
az.plot_trace(results)
```

In the first line we create and build a Bambi `Model`. The second line tells the sampler to start
First, we create and build a Bambi `Model`. Then, the function `model.fit` tells the sampler to start
running and it returns an `InferenceData` object, which can be passed to several ArviZ functions
such as `az.summary()` to get a summary of the parameters distribution and sample diagnostics or
`az.plot_trace()` to visualize them.

`az.plot_trace()` to visualize them.

### Logistic regression

In this example we will use a simulated dataset created as shown below.

```python
data = pd.DataFrame({
"g": np.random.choice(["Yes", "No"], size=50),
"x1": np.random.normal(size=50),
"x2": np.random.normal(size=50)
})
```

Here we just add the `family` argument set to `"bernoulli"` to tell Bambi we are modelling a binary
response. By default, it uses a logit link. We can also use some syntax sugar to specify which event
we want to model. We just say `g['Yes']` and Bambi will understand we want to model the probability
of a `"Yes"` response. But this notation is not mandatory. If we use `"g ~ x1 + x2"`, Bambi will
pick one of the events to model and will inform us which one it picked.


```python
model = bmb.Model("g['Yes'] ~ x1 + x2", data, family="bernoulli")
fitted = model.fit()
```

After this, we can evaluate the model as before.

### More

There are many additional examples in our [Examples](https://bambinos.github.io/bambi/notebooks/) webpage.

## Documentation

The Bambi documentation can be found in the [official docs](https://bambinos.github.io/bambi/index.html)
64 changes: 54 additions & 10 deletions docs/index.qmd
Original file line number Diff line number Diff line change
@@ -58,31 +58,75 @@ If you use Conda, you can also install the latest release of Bambi with the foll
conda install -c conda-forge bambi
```

## Usage
## Examples of usage

A simple fixed effects model is shown in the example below.
## Example

In the following two examples we assume the following basic setup

```python
import arviz as az
import bambi as bmb
import numpy as np
import pandas as pd
```

### Linear regression

# Read in a tab-delimited file containing our data
data = pd.read_table('my_data.txt', sep='\t')
A simple fixed effect model is shown in the example below.

# Initialize the fixed effects only model
model = bmb.Model('DV ~ IV1 + IV2', data)
```python
#### Read in a database from the package content
data = bmb.load_data("sleepstudy")

# Fit the model using 1000 on each of 4 chains
results = model.fit(draws=1000, chains=4)
# Initialize the fixed effect only model
model = bmb.Model('Reaction ~ Days', data)
print(model) # Get model description

# Use ArviZ to plot the results
az.plot_trace(results)
# Fit the model using 1000 on each chain
results = model.fit(draws=1000)

# Key summary and diagnostic info on the model parameters
az.summary(results)

# Use ArviZ to plot the results
az.plot_trace(results)
```

First, we create and build a Bambi `Model`. Then, the function `model.fit` tells the sampler to start
running and it returns an `InferenceData` object, which can be passed to several ArviZ functions
such as `az.summary()` to get a summary of the parameters distribution and sample diagnostics or
`az.plot_trace()` to visualize them.

### Logistic regression

In this example we will use a simulated dataset created as shown below.

```python
data = pd.DataFrame({
"g": np.random.choice(["Yes", "No"], size=50),
"x1": np.random.normal(size=50),
"x2": np.random.normal(size=50)
})
```

Here we just add the `family` argument set to `"bernoulli"` to tell Bambi we are modelling a binary
response. By default, it uses a logit link. We can also use some syntax sugar to specify which event
we want to model. We just say `g['Yes']` and Bambi will understand we want to model the probability
of a `"Yes"` response. But this notation is not mandatory. If we use `"g ~ x1 + x2"`, Bambi will
pick one of the events to model and will inform us which one it picked.

```python
model = bmb.Model("g['Yes'] ~ x1 + x2", data, family="bernoulli")
fitted = model.fit()
```

After this, we can evaluate the model as before.

### More

There are many additional examples in our [Examples](https://bambinos.github.io/bambi/notebooks/) webpage.

For a more in-depth introduction to Bambi see our
[Quickstart](https://github.com/bambinos/bambi#quickstart) or our set of example notebooks.