#!/usr/bin/env python3 """Write results/tables/rev_vif.tex from the VIFs stored in rev_key_numbers.json (companion of 10_revision_reanalysis.py).""" import json from pathlib import Path ROOT = Path(__file__).resolve().parent.parent k = json.loads((ROOT / "results/tables/rev_key_numbers.json").read_text()) LAB = {"ln_bedrooms": "ln(bedrooms)", "ln_bathrooms": "ln(1 + bathrooms)", "ln_guests": "ln(guests)", "shared_bath": "Shared bathroom", "studio": "Studio", "ln_amenities": "ln(1 + amenities)", "pets_allowed": "Pets allowed", "ln_images": "ln(1 + photos)", "is_superhost": "Superhost", "is_guest_favorite": "Guest Favourite", "ln_reviews": "ln(1 + reviews)", "rated": "Rated (star shown)", "rating_c": "Rating $-$ 4.8 (rated only)", "ln_dist": "ln(1 + km to centre)", "ln_density_1km": "ln(1 + listings within 1 km)", "Hotel/B&B/hostel": "Hotel/B\\&B/hostel"} rows = ["\\begin{tabular}{lr}", "\\toprule", "Regressor & VIF \\\\", "\\midrule"] for v, x in k["vif"].items(): rows.append(f"{LAB.get(v, v)} & {x:.2f} \\\\") rows += ["\\bottomrule", "\\end{tabular}"] (ROOT / "results/tables/rev_vif.tex").write_text("\n".join(rows)) print("rev_vif.tex written; max VIF", round(k["vif_max"], 2), k["vif_argmax"])