Language Models

Models investigating the effect of spoken frequency, and concretneess, controlling for using word norms, including orthographic frequency norms and prescence of speech.

from create import create_models
from pyns import Neuroscout
from matplotlib import pyplot as plt
from pathlib import Path
import sys
sys.path.append("..") 
from utils import dump_collection, load_collection

%matplotlib inline
/home/alejandro/anaconda3/lib/python3.7/site-packages/nilearn/datasets/__init__.py:89: FutureWarning: Fetchers from the nilearn.datasets module will be updated in version 0.9 to return python strings instead of bytes and Pandas dataframes instead of Numpy arrays.
  "Numpy arrays.", FutureWarning)
api = Neuroscout()

Define predictors and confounds

predictors = [
    'subtlexusfrequency_Lg10WF', 'speech', 'massiveauditorylexicaldecision_PhonLev', 'text_length', 
    'massiveauditorylexicaldecision_NumSylls', 'massiveauditorylexicaldecision_NumPhones', 
    'massiveauditorylexicaldecision_Duration', 'concreteness_Conc.M'
]
transform_variables = list(set(predictors) - set(['speech']))
datasets = api.datasets.get() # Get all Neuroscout datasets
confounds = ['a_comp_cor_00', 'a_comp_cor_01', 'a_comp_cor_02', 'a_comp_cor_03', 'a_comp_cor_04', 'a_comp_cor_05', 'trans_x', 'trans_y', 'trans_z', 'rot_x', 'rot_y', 'rot_z']
filename = Path('models') / 'lexical_variables.json'
language_models = load_collection(filename) # Load instead of re-running

Create models

transformations = [
    {"Name": "Scale", "Demean": True, "Rescale": True, "ReplaceNA": "after", "Input": [p],"Output": [p]} 
    for p in transform_variables
    ]
name = name = '+'.join(predictors)
language_models = {}
# language_models[name] = create_models(name=name,
#     predictors=predictors, confounds=confounds, datasets=datasets, transformations=transformations)
analysis = language_models[name][0]['analysis']
analysis.generate_report(run_id=analysis.runs[0]) 
analysis.plot_report(plot_type='design_matrix_plot')
# dump_collection(language_models, filename)

Compile models

# Compile analyses
# for analysis_dict in language_models[name]:
#     analysis = analysis_dict['analysis']
#     if analysis.get_status()['status'] in 'DRAFT':
#         analysis.compile()