<jupyter_start><jupyter_text>basic dummy coding<jupyter_code>import pandas as pd
import statsmodels.formula.api as smf
import numpy as np

gfr = pd.read_csv("data/GlastonburyFestivalRegression.dat",sep="\t")

gfr["change"]=gfr["change"].replace('^\s*$',np.nan,regex=True)
gfr["change"]=gfr["change"].astype("float64")
gfr=gfr.dropna()
gfr
gfr.describe()<jupyter_output><empty_output><jupyter_text>Use dummy codingThere are 4 groups, and Group "No Musical Affiliation" is the baseline.<jupyter_code>import patsy

model=smf.ols(formula="change ~ C(music, Treatment('No Musical Affiliation'))",data=gfr)
fit = model.fit()
fit.summary()<jupyter_output><empty_output><jupyter_text>Set dummy coding manually<jupyter_code>gfr["music"]=gfr["music"].astype("category")

gfr["music"]<jupyter_output><empty_output><jupyter_text>Note there are 4 groups ('Crusty','Indie Kid''Metaller''No Musical Affiliation').And Pay attention to their orders.<jupyter_code>code = [
    [1,0,0],
    [0,1,0],
    [0,0,1],
    [0,0,0]
]
model=smf.ols(formula="change ~ C(music, code)",data=gfr)
fit = model.fit()
fit.summary()
gfr.groupby("music")["change"].mean()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1759656652360515, 'fraction_numerical': 0.013733905579399141, 'mean_word_length': 8.479674796747968, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '658365', 'license': 'MIT', 'n_tokens_mistral': 462, 'n_tokens_neox': 445, 'n_words': 71, 'path': 'References/Data.Analysis/Discovery.Statistics/7-2.multiple.regression.with.categorical.predictors.ipynb', 'repo_name': 'royqh1979/python_libs_usage', 'size': '1165'}