73 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| 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 PAT import pat_val
 | |
| RT_PAT = pat_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()
 | |
| 
 | |
| 
 | |
| print('on-dn:', differences_ppg['on-dn'])
 | |
| print('R-T',intervals_ecg['R-T_offset'])
 | |
| print('RT - PAT :', RT_PAT)
 | |
| 
 | |
| n = len(RT_PAT)
 | |
| pearsonr_corr_1, p_1 = pearsonr(RT_PAT, differences_ppg['on-dn'])
 | |
| print("RT - PAT 与 on-dn 的皮尔逊相关系数:", pearsonr_corr_1)
 | |
| print('p_1:', p_1)
 | |
| 
 | |
| pearsonr_corr_2, p_2 = pearsonr(intervals_ecg['R-T_offset'], differences_ppg['on-dn'])
 | |
| print("RT 与 on-dn 的皮尔逊相关系数:", pearsonr_corr_2)
 | |
| print('p_2:', p_2)
 | |
| 
 | |
| 
 | |
| # 创建上下两个子图
 | |
| fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(5, 8))
 | |
| 
 | |
| # —— 图1 ——
 | |
| sns.regplot(x=intervals_ecg['R-T_offset'], y=differences_ppg['on-dn'],
 | |
|             scatter_kws={'alpha': 0.7, 'color': 'dodgerblue'},
 | |
|             line_kws={'color': 'red',
 | |
|                       'label': f'r={pearsonr_corr_2:.3f}, n={n}, p={p_2:.3f}'},
 | |
|             ax=ax1)
 | |
| ax1.set_xlabel('RT')
 | |
| ax1.set_ylabel('on-dn')
 | |
| ax1.set_title(rf'$\it r$={pearsonr_corr_2:.3f}, $\it p$={p_2:.3g}, $\it n$={n}')
 | |
| ax1.legend()
 | |
| ax1.grid(True, linestyle='--', alpha=0.4)
 | |
| 
 | |
| # —— 图2 ——
 | |
| sns.regplot(x=RT_PAT, y=differences_ppg['on-dn'],
 | |
|             scatter_kws={'alpha': 0.7, 'color': 'dodgerblue'},
 | |
|             line_kws={'color': 'red',
 | |
|                       'label': f'r={pearsonr_corr_1:.3f}, n={n}, p={p_1:.3f}'},
 | |
|             ax=ax2)
 | |
| ax2.set_xlabel('RT-PAT')
 | |
| ax2.set_ylabel('on-dn')
 | |
| ax2.set_title(rf'$\it r$={pearsonr_corr_1:.3f}, $\it p$={p_1:.3g}, $\it n$={n}')
 | |
| ax2.legend()
 | |
| ax2.grid(True, linestyle='--', alpha=0.4)
 | |
| 
 | |
| plt.tight_layout()
 | |
| plt.show()
 |