12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import os
- import pandas as pd
- import seaborn as sns
- import matplotlib.pyplot as plt
- import statsmodels.api as sm
- from statsmodels.formula.api import mixedlm
- from scikit_posthocs import posthoc_dunnett
- from scipy.stats import dunnett
- import statsmodels.formula.api as smf
- import nipype as nip
- import numpy as np
- # Get the directory where the code file is located
- code_dir = os.path.dirname(os.path.abspath(__file__))
- # Get the parent directory of the code directory
- parent_dir = os.path.dirname(code_dir)
- # Specify the input file path relative to the code file
- input_file_path = os.path.join(parent_dir, 'output', 'behavior_data_processed.csv')
- # Read the CSV file into a Pandas DataFrame
- df = pd.read_csv(input_file_path)
- # Create an empty dictionary to store Dunnett's test results
- dunnett_results = {}
- tests = ["averageScore"]
- import pandas as pd
- import statsmodels.api as sm
- from statsmodels.regression.mixed_linear_model import MixedLM
- # Define the model formula
- formula = "averageScore ~ TimePoint_merged"
- filtered_df = df[df["Group"]=="Stroke"]
- # Apply log transformation to the 'averageScore' variable
- filtered_df["log_averageScore"] = np.log(filtered_df['averageScore'])
- # Fit the mixed model
- mixed_model = mixedlm(formula, filtered_df, groups='TimePoint_merged')
- mixed_model_results = mixed_model.fit()
- # Plot Q-Q plot of residuals
- sm.qqplot(mixed_model_results.resid, line ='q')
- plt.title('Q-Q Plot of Residuals')
- plt.show()
- # Print model summary
- print(mixed_model_results.summary())
|