109 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			109 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import numpy as np
 | |
| from scipy.stats import pearsonr
 | |
| 
 | |
| import matplotlib.pyplot as plt
 | |
| import seaborn as sns
 | |
| 
 | |
| from ecg_peaks_val import ecg_peaks_val
 | |
| (P_peaks, Q_peaks, R_peaks, S_peaks, T_peaks,
 | |
| P_onsets, P_offsets, T_onsets, T_offsets,
 | |
| P_peaks_values, Q_peaks_values, R_peaks_values, S_peaks_values, T_peaks_values, 
 | |
| P_onsets_values, P_offsets_values, T_onsets_values, T_offsets_values,
 | |
| PQ_baseline) = ecg_peaks_val()
 | |
| 
 | |
| from ppg_peaks_val import ppg_peaks_val
 | |
| (on, on_toArea, sp, dn, dp,
 | |
| on_values, on_toArea_values, sp_values, dn_values, dp_values,
 | |
| u, u_toArea, v, w,
 | |
| u_values, u_toArea_values, v_values, w_values,
 | |
| a, a_toArea, b, c, e, f,
 | |
| a_values, a_toArea_values, b_values, c_values, e_values, f_values) = ppg_peaks_val()
 | |
| 
 | |
| from ecg_time_interval import compute_interval
 | |
| intervals_ecg, ratio_pp_tt = compute_interval()
 | |
| 
 | |
| from ppg_time_interval import ppg_time_interval
 | |
| differences_ppg = ppg_time_interval()
 | |
| 
 | |
| 
 | |
| # 读取文件中的数值
 | |
| def read_values_from_file(file_path):
 | |
|     with open(file_path, 'r') as file:
 | |
|         values = file.readlines()
 | |
|     # 将字符串转换为浮点数
 | |
|     values = [float(value.strip()) for value in values]
 | |
|     return values
 | |
| 
 | |
| # 文件路径
 | |
| file1_path = "D://python_study//big_boss//doc//output//data1.txt"  # 第一个文件路径
 | |
| file2_path = "D://python_study//big_boss//doc//output//data2.txt"  # 第二个文件路径
 | |
| 
 | |
| # 读取文件中的数值
 | |
| data1 = read_values_from_file(file1_path)
 | |
| data2 = read_values_from_file(file2_path)
 | |
| 
 | |
| # 计算皮尔逊相关系数和 p 值
 | |
| correlation, p_value = pearsonr(data1, data2)
 | |
| 
 | |
| # 输出结果
 | |
| print(f"Pearson correlation coefficient: {correlation:.4f}")
 | |
| print(f"P-value: {p_value:.4f}")
 | |
| 
 | |
| # 判断显著性
 | |
| alpha = 0.05  # 显著性水平
 | |
| if p_value < alpha:
 | |
|     print("The correlation is statistically significant.")
 | |
| else:
 | |
|     print("The correlation is not statistically significant.")
 | |
| 
 | |
| # 使用 seaborn 绘制散点图并显示回归线
 | |
| plt.figure(figsize=(8, 6))
 | |
| sns.regplot(x=data1, y=data2, scatter_kws={'alpha': 0.7, 'color': 'blue'}, line_kws={'color': 'red'})
 | |
| plt.title('Scatter Plot with Regression Line')
 | |
| plt.xlabel('data1 (on-dp)')
 | |
| plt.ylabel('data2 (R-T)')
 | |
| plt.show()
 | |
| 
 | |
| 
 | |
| # # data1 = np.diff(P_onsets)
 | |
| # # data2 = np.diff(on)
 | |
| # data1 = differences_ppg['on-dn']
 | |
| # print(data1)
 | |
| 
 | |
| 
 | |
| # # 将 data1 的值保存到文件中
 | |
| # file_path_1 = "D://python_study//big_boss//doc//output//data1.txt"  # 定义文件路径
 | |
| # with open(file_path_1, 'a') as file:  # 打开文件
 | |
| #     for value in data1:
 | |
| #         file.write(f"{value}\n")  # 将每个值写入文件,每个值占一行
 | |
| 
 | |
| # print(f"data1 的值已保存到文件 {file_path_1}")
 | |
| 
 | |
| # # 将 data2 的值保存到文件中
 | |
| # file_path_2 = "D://python_study//big_boss//doc//output//data2.txt"  # 定义文件路径
 | |
| 
 | |
| # # 读取文件中的数值
 | |
| # data1 = read_values_from_file(file_path_1)
 | |
| # data2 = read_values_from_file(file_path_2)
 | |
| 
 | |
| # # 计算皮尔逊相关系数和 p 值
 | |
| # correlation, p_value = pearsonr(data1, data2)
 | |
| 
 | |
| # # 输出结果
 | |
| # print(f"Pearson correlation coefficient: {correlation:.4f}")
 | |
| # print(f"P-value: {p_value:.4f}")
 | |
| 
 | |
| # # 判断显著性
 | |
| # alpha = 0.05  # 显著性水平
 | |
| # if p_value < alpha:
 | |
| #     print("The correlation is statistically significant.")
 | |
| # else:
 | |
| #     print("The correlation is not statistically significant.")
 | |
| 
 | |
| # # 使用 seaborn 绘制散点图并显示回归线
 | |
| # plt.figure(figsize=(8, 6))
 | |
| # sns.regplot(x=data1, y=data2, scatter_kws={'alpha': 0.7, 'color': 'blue'}, line_kws={'color': 'red'})
 | |
| # plt.title('Scatter Plot with Regression Line')
 | |
| # plt.xlabel('data1 (on-dn)')
 | |
| # plt.ylabel('data2 (R-T)')
 | |
| # plt.show() |