fit_bunching {bunching} | R Documentation |

## Fit Bunching

### Description

Fit bunching model to (binned) data and estimate excess mass.

### Usage

```
fit_bunching(thedata, themodelformula, binwidth, notch = FALSE, zD_bin = NA)
```

### Arguments

`thedata` |
(binned) data that includes all variables necessary for fitting the model. |

`themodelformula` |
formula to fit. |

`binwidth` |
a numeric value for the width of each bin. |

`notch` |
whether analysis is for a kink or notch. Default is FALSE (kink). |

`zD_bin` |
the bin marking the upper end of the dominated region (notch case). |

### Value

`fit_bunching`

returns a list of the following results:

`coefficients` |
The coefficients from the fitted model. |

`residuals` |
The residuals from the fitted model. |

`cf_density` |
The estimated counterfactual density. |

`bunchers_excess` |
The estimate of the excess mass (not normalized). |

`cf_bunchers` |
The counterfactual estimate of counts in the bunching region. |

`b_estimate` |
The estimate of the normalized excess mass. |

`bins_bunchers` |
The number of bins in the bunching region. |

`model_formula` |
The model formula used for fitting. |

`B_zl_zstar` |
The count of bunchers in the bunching region below and up to zstar. |

`B_zstar_zu` |
The count of bunchers in the bunching region above zstar. |

`alpha` |
The estimated fraction of bunchers in the dominated region (only in notch case.) |

`zD_bin` |
The value of the bin which zD falls in. |

### See Also

### Examples

```
data(bunching_data)
binned_data <- bin_data(z_vector = bunching_data$kink, zstar = 10000,
binwidth = 50, bins_l = 20, bins_r = 20)
prepped_data <- prep_data_for_fit(binned_data, zstar = 10000, binwidth = 50,
bins_l = 20, bins_r = 20, poly = 4)
fitted <- fit_bunching(thedata = prepped_data$data_binned,
themodelformula = prepped_data$model_formula,
binwidth = 50)
# extract coefficients
fitted$coefficients
```

*bunching*version 0.8.6 Index]