<jupyter_start><jupyter_text>We start with a simple model:$$ \mathrm{pitch} = \mathrm{int} + \mathrm{politeness} + \mathrm{sex} + (1|subject) + \varepsilon $$<jupyter_code>data = data.dropna()
md = smf.mixedlm("pitch ~ subject", data, groups=data["subject"])
mdf = md.fit()
mdf.summary()
pitch_by_subject = data.groupby('subject')['pitch'].mean()
pitch_by_subject
mdf.params['Intercept'] + mdf.params['subject[T.F2]']
md = smf.mixedlm("pitch ~ condition + C(gender, Helmert)", data, groups=data["subject"])
mdf = md.fit()
mdf.summary()
deviance = -2*mdf.llf
deviance
p = 4 # number of parameters = 3 (fixed) + 1 (random)
deviance + 2*(p+1) # total parameters = 4 + 1 for estimated residual variance
data_by_subject = data.groupby('subject')['pitch'].mean()
data_by_subject.to_frame().reset_index()
(
    ggplot(data=data_by_subject.to_frame().reset_index())
     + geom_point(aes(x='subject', y='pitch', color='subject'))
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18782791185729275, 'fraction_numerical': 0.01049317943336831, 'mean_word_length': 6.453125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '434209', 'license': 'MIT', 'n_tokens_mistral': 366, 'n_tokens_neox': 343, 'n_words': 67, 'path': 'content/post/multilevel-models/Untitled.ipynb', 'repo_name': 'TomKealy/academic-kickstart', 'size': '953'}