behavior_time_statistics.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import os
  2. import pandas as pd
  3. import seaborn as sns
  4. import matplotlib.pyplot as plt
  5. import statsmodels.api as sm
  6. from statsmodels.formula.api import mixedlm
  7. from scikit_posthocs import posthoc_dunnett
  8. from scipy.stats import dunnett
  9. import statsmodels.formula.api as smf
  10. import nipype as nip
  11. import numpy as np
  12. # Get the directory where the code file is located
  13. code_dir = os.path.dirname(os.path.abspath(__file__))
  14. # Get the parent directory of the code directory
  15. parent_dir = os.path.dirname(code_dir)
  16. # Specify the input file path relative to the code file
  17. input_file_path = os.path.join(parent_dir, 'output', 'behavior_data_processed.csv')
  18. # Read the CSV file into a Pandas DataFrame
  19. df = pd.read_csv(input_file_path)
  20. # Create an empty dictionary to store Dunnett's test results
  21. dunnett_results = {}
  22. tests = ["averageScore"]
  23. import pandas as pd
  24. import statsmodels.api as sm
  25. from statsmodels.regression.mixed_linear_model import MixedLM
  26. # Define the model formula
  27. formula = "averageScore ~ TimePoint_merged"
  28. filtered_df = df[df["Group"]=="Stroke"]
  29. # Apply log transformation to the 'averageScore' variable
  30. filtered_df["log_averageScore"] = np.log(filtered_df['averageScore'])
  31. # Fit the mixed model
  32. mixed_model = mixedlm(formula, filtered_df, groups='TimePoint_merged')
  33. mixed_model_results = mixed_model.fit()
  34. # Plot Q-Q plot of residuals
  35. sm.qqplot(mixed_model_results.resid, line ='q')
  36. plt.title('Q-Q Plot of Residuals')
  37. plt.show()
  38. # Print model summary
  39. print(mixed_model_results.summary())