<jupyter_start><jupyter_text>ANALYSIS NOTEBOOK  - DONNELLY 2019 PLOS ONE <NAME>   University of Washington September 25, 2020<jupyter_code># import necessary databases and libraries
import pandas as pd
import numpy as np
from scipy import stats
# pull data from data folder in repository
data = pd.read_csv('data/data.csv')<jupyter_output><empty_output><jupyter_text>Demographics TableT-tests and Wilcoxon signed rank tests for Demographics Table 1  Age<jupyter_code>stats.wilcoxon(corr_data.visit_age, corr_data_cntrl.visit_age)<jupyter_output><empty_output><jupyter_text>Gender<jupyter_code>stats.wilcoxon(corr_data.gender, corr_data_cntrl.gender)<jupyter_output><empty_output><jupyter_text>Norm-referenced Measures<jupyter_code># WJ Basic Reading Skills composite
stats.ttest_ind(corr_data.wj_brs, corr_data_cntrl.wj_brs)
# TOWRE-2 Index
stats.ttest_ind(corr_data.twre_index, corr_data_cntrl.twre_index)
# WASI-II FS-2 Composite
stats.ttest_ind(corr_data.wasi_fs2, corr_data_cntrl.wasi_fs2)
# CTOPP-2 Phonological Awareness composite
stats.ttest_ind(corr_data.ctopp_pa, corr_data_cntrl.ctopp_pa)
# CTOPP-2 Rapid Naming composite
stats.ttest_ind(corr_data.ctopp_rapid, corr_data_cntrl.ctopp_rapid)<jupyter_output><empty_output><jupyter_text>Correlation Analysis<jupyter_code># look at difference scores and practice metrics
data_sifted = data[['record_id','int_session', 'gender', 'pigs_casecontrol', 'word_acc_diff', 
                  'pseudo_acc_diff', 'first_acc_diff', 'second_rate_diff', 'pigs_practice_numstories', 
                    'visit_age', 'wj_brs', 'twre_index', 'ctopp_rapid', 'wasi_fs2', 'ctopp_pa', 'ctopp_pm']]
# look just at intervention participants
corr_data = data_sifted[data_sifted['pigs_casecontrol'] == 1]
corr_data_cntrl = data_sifted[data_sifted['pigs_casecontrol'] == 0]
# Look just at session 2 for data clarity
corr_data = corr_data[corr_data['int_session'] == 2]
corr_data_cntrl = corr_data_cntrl[corr_data_cntrl['int_session'] == 2]<jupyter_output><empty_output><jupyter_text>Growth and Practice - Intervention Group<jupyter_code>stats.pearsonr(corr_data['word_acc_diff'], corr_data['pigs_practice_numstories'])
stats.pearsonr(corr_data['pseudo_acc_diff'], corr_data['pigs_practice_numstories'])<jupyter_output><empty_output><jupyter_text>Growth and Practice - Control Group<jupyter_code>stats.pearsonr(corr_data_cntrl['word_acc_diff'], corr_data_cntrl['pigs_practice_numstories'])
stats.pearsonr(corr_data_cntrl['pseudo_acc_diff'], corr_data_cntrl['pigs_practice_numstories'])<jupyter_output><empty_output><jupyter_text>Real Word Decoding & Predictors<jupyter_code>stats.pearsonr(corr_data['word_acc_diff'], corr_data['visit_age'])
stats.pearsonr(corr_data['word_acc_diff'], corr_data['wasi_fs2'])
stats.pearsonr(corr_data['word_acc_diff'], corr_data['ctopp_pa'])
stats.pearsonr(corr_data['word_acc_diff'], corr_data['ctopp_pm'])<jupyter_output><empty_output><jupyter_text>Pseudo Word Decoding & Predictors<jupyter_code>stats.pearsonr(corr_data['pseudo_acc_diff'], corr_data['visit_age'])
stats.pearsonr(corr_data['pseudo_acc_diff'], corr_data['wasi_fs2'])
stats.pearsonr(corr_data['pseudo_acc_diff'], corr_data['ctopp_pa'])
stats.pearsonr(corr_data['pseudo_acc_diff'], corr_data['ctopp_pm'])<jupyter_output><empty_output><jupyter_text>Passage Reading Accuracy & Predictors<jupyter_code># resift data so that nan-removal is only affected by nans in accuracy
data_accuracy = data[['record_id','int_session', 'pigs_casecontrol', 'word_acc_diff', 
                  'pseudo_acc_diff', 'first_acc_diff', 'pigs_practice_numstories', 
                    'visit_age', 'wj_brs', 'twre_index', 'ctopp_rapid', 'wasi_fs2', 'ctopp_pa', 'ctopp_pm']]
# look just at intervention participants
corr_accuracy = data_accuracy[data_accuracy['pigs_casecontrol'] == 1]
corr_accuracy_cntrl = data_accuracy[data_accuracy['pigs_casecontrol'] == 0]
corr_accuracy = corr_accuracy[corr_accuracy['int_session'] == 2].dropna()
corr_accuracy_cntrl = corr_accuracy_cntrl[corr_accuracy_cntrl['int_session'] == 2].dropna()
stats.pearsonr(corr_accuracy['first_acc_diff'], corr_accuracy['visit_age'])
stats.pearsonr(corr_accuracy['first_acc_diff'], corr_accuracy['wasi_fs2'])
stats.pearsonr(corr_accuracy['first_acc_diff'], corr_accuracy['ctopp_pa'])
stats.pearsonr(corr_accuracy['first_acc_diff'], corr_accuracy['ctopp_pm'])<jupyter_output><empty_output><jupyter_text>Passage Reading Rate & Predictors<jupyter_code># resift data so that nan-removal is only affected by nans in rate
data_rate = data[['record_id','int_session', 'pigs_casecontrol', 'word_acc_diff', 
                  'pseudo_acc_diff', 'second_rate_diff', 'pigs_practice_numstories', 
                    'visit_age', 'wj_brs', 'twre_index', 'ctopp_rapid', 'wasi_fs2', 'ctopp_pa', 'ctopp_pm']]
# look just at intervention participants
corr_rate = data_rate[data_rate['pigs_casecontrol'] == 1]
corr_rate_cntrl = data_rate[data_rate['pigs_casecontrol'] == 0]
corr_rate = corr_rate[corr_rate['int_session'] == 2].dropna()
corr_rate_cntrl = corr_rate_cntrl[corr_rate_cntrl['int_session'] == 2].dropna()
stats.pearsonr(corr_rate['second_rate_diff'], corr_rate['visit_age'])
stats.pearsonr(corr_rate['second_rate_diff'], corr_rate['wasi_fs2'])
stats.pearsonr(corr_rate['second_rate_diff'], corr_rate['ctopp_pa'])
stats.pearsonr(corr_rate['second_rate_diff'], corr_rate['ctopp_pm'])<jupyter_output><empty_output><jupyter_text>Effect Size Analyses  Real Word  data structure most relevant is corr_data for intervention group and corr_data_cntrl for control group<jupyter_code>x = corr_data.word_acc_diff
y = corr_data_cntrl.word_acc_diff
d = (np.mean(x) - np.mean(y)) / np.sqrt((np.std(x, ddof=1) ** 2 + np.std(y, ddof=1) ** 2) / 2.0)
print("Cohen's d: ",d)<jupyter_output>Cohen's d:  0.5686864296949145<jupyter_text>Pseudo Word<jupyter_code>x = corr_data.pseudo_acc_diff
y = corr_data_cntrl.pseudo_acc_diff
d = (np.mean(x) - np.mean(y)) / np.sqrt((np.std(x, ddof=1) ** 2 + np.std(y, ddof=1) ** 2) / 2.0)
print("Cohen's d: ",d)<jupyter_output>Cohen's d:  0.7429769651763583<jupyter_text>Passage Accuracy<jupyter_code>x = corr_accuracy.first_acc_diff
y = corr_accuracy_cntrl.first_acc_diff
d = (np.mean(x) - np.mean(y)) / np.sqrt((np.std(x, ddof=1) ** 2 + np.std(y, ddof=1) ** 2) / 2.0)
print("Cohen's d: ",d)<jupyter_output>Cohen's d:  0.3635296154143578<jupyter_text>Passage Rate<jupyter_code>x = corr_rate.second_rate_diff
y = corr_rate_cntrl.second_rate_diff
d = (np.mean(x) - np.mean(y)) / np.sqrt((np.std(x, ddof=1) ** 2 + np.std(y, ddof=1) ** 2) / 2.0)
print("Cohen's d: ",d)<jupyter_output>Cohen's d:  0.1270477151527451
{'fraction_non_alphanumeric': 0.13488089819450766, 'fraction_numerical': 0.01957214383249886, 'mean_word_length': 8.651537335285505, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 58, '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': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '416017', 'license': 'MIT', 'n_tokens_mistral': 2794, 'n_tokens_neox': 2577, 'n_words': 365, 'path': 'analysis.ipynb', 'repo_name': 'patdonnelly/Donnelly_2019_PLOSONE', 'size': '6604'}