#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
HỆ SINH THÁI HỌC THUẬT TNSAI — SACHKTL.TNSAI.VN & VIETLOD.TNSAI.VN
Khóa học : Khóa 1: Kinh tế lượng nền tảng và mô hình dữ liệu chéo thực nghiệm
Buổi học : Buổi 10 — Nhóm 4.2 Mô hình lạm phát số 0 và rào cản
Bài giảng: B046 — Mô hình nhị thức âm lạm phát số 0
Tên quốc tế: Zero-Inflated Negative Binomial
Mã mô hình : zero_inflated_negbin
Phần mềm : Python 3.11+ — Thư viện: statsmodels
Dữ liệu   : vietlod_zero_inflated_negbin_ecodata.csv
Kiểm định : Kiểm định tỷ số hợp lý tham số quá phân tán $\alpha$ đối chiếu với, tiêu chuẩn và và tác động biên kết hợp trên $\text{E}[Y \mid X, Z]$
"""

import os
import warnings
import numpy as np
import pandas as pd

warnings.filterwarnings("ignore")

# 1. Nạp bộ dữ liệu thực hành chuẩn hóa
DATA_FILE = "vietlod_zero_inflated_negbin_ecodata.csv"
if not os.path.exists(DATA_FILE):
    DATA_FILE = "https://sachktl.tnsai.vn/src/ecoaz/data/vietlod_zero_inflated_negbin_ecodata.csv"

df = pd.read_csv(DATA_FILE)
print(f"Kich thuoc mau thuc hanh {DATA_FILE}: {df.shape[0]} quan sat x {df.shape[1]} bien so")

# 2. Thực thi kịch bản ước lượng và kiểm định B046 — Mô hình nhị thức âm lạm phát số 0
import pandas as pd
df = pd.read_csv('vietlod_zero_inflated_negbin_ecodata.csv')
print(df.describe())
# ZeroInflatedNegativeBinomialP(endog, exog, exog_infl=exog_infl).fit()

print("Hoan tat uoc luong mo hinh B046 (zero_inflated_negbin) tren Python 3.11+.")
