12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- # -*- coding: utf-8 -*-
- """
- Created on Fri Sep 27 13:19:08 2024
- @author: arefks
- """
- import os
- import pandas as pd
- import seaborn as sns
- import matplotlib.pyplot as plt
- import statsmodels.formula.api as smf
- from statsmodels.stats.multicomp import MultiComparison
- from itertools import combinations
- import statsmodels
- import scipy
- from scipy.stats import dunnett
- # Set up warning suppression for convergence
- import warnings
- warnings.simplefilter(action='ignore')
- # 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)
- # Create a new folder for mixed model analysis
- mixed_model_dir = os.path.join(parent_dir, 'output', "Quantitative_outputs", 'normality')
- os.makedirs(mixed_model_dir, exist_ok=True)
- # Step 4: Save the resulting dataframe to a CSV file
- input_file_path = os.path.join(parent_dir, 'output', "Quantitative_outputs", 'Quantitative_results_from_dwi_processing.csv')
- df_init = pd.read_csv(input_file_path)
- # Filtering the dataframe based on conditions
- df = df_init[~df_init["merged_timepoint"].isin([42, 56])]
- # Iterate over unique values of "Qtype" and "mask_name"
- #for qq in df["Qtype"].unique():
- for qq in ["fa"]:
- for dd in df["dialation_amount"].unique():
- for mm in df["mask_name"].unique():
- # Filter the dataframe based on current "Qtype" and "mask_name"
- filtered_df = df[(df["Qtype"] == qq) & (df["mask_name"] == mm) & (df["dialation_amount"] == dd)]
- # Identify duplicates based on 'merged_timepoint' and 'subjectID'
- duplicates = filtered_df[filtered_df.duplicated(subset=['merged_timepoint', 'subjectID'], keep=False)]
- # Print the duplicates
- if not duplicates.empty:
- print("Duplicate subject ID and timepoint entries found:\n", duplicates)
- # Remove duplicates and store in a new DataFrame
- temp_df = filtered_df.drop_duplicates(subset=['merged_timepoint', 'subjectID'])
- # Create a DataFrame from results
- results_df = pd.DataFrame(results)
- # Save results_df as CSV in mixed_model_analysis folder
- output_file_path = os.path.join(mixed_model_dir, 'mixed_model_results.csv')
- results_df.to_csv(output_file_path, index=False)
- # Print the table
- print(results_df)
|