Question: For this question, considering multivariate case, we run the code: # import package import pandas as pd import numpy as np from scipy import stats

For this question, considering "multivariate case", we run the code:
# import package
import pandas as pd
import numpy as np
from scipy import stats
# read data
Female_data = pd.read_csv(r"C:\Users\female.csv",header=None)
Male_data = pd.read_csv(r"c:\Users\male.csv",header=None)
N = len(Female_data)
# log transformation
Female_data_log = np.log1p(Female_data)
Male_data_log = np.log1p(Male_data)
# covariance matrices
cov_matrix_female = Female_data_log.cov()
cov_matrix_male = Male_data_log.cov()
# number of samples in each group
n_female = len(Female_data)
n_male = len(Male_data)
# pooled covariance matrix
pooled_cov_matrix =((n_female -1)* cov_matrix_female +(n_male -1)* cov_matrix_male)/(n_female + n_male -2)
# mean difference
mean_diff = Female_data_log.mean()- Male_data_log.mean()
# Hotelling's T-squared statistic
t_squared = np.dot(mean_diff.T, np.dot(np.linalg.inv(pooled_cov_matrix), mean_diff))*(n_female * n_male)/(n_female + n_male)
# degrees of freedom
df_t_squared = len(Female_data.columns)
df = n_female + n_male -2
# calculate p-value after comparison with the F-distribution
p_t_squared =1- stats.f.cdf(t_squared, dfn=df_t_squared, dfd=df)
print("Hotelling's T-squared ="+ str(t_squared))
print("p ="+ str(p_t_squared))
# t-test for each variable
t2, p2= stats.ttest_ind(Female_data_log, Male_data_log)
print("p(t)="+ str(2* p2))
for i in range(0, len(p)):
if 2* p[i] p2[i]:
print(Female_data.columns[i]+" is significantly different")
else:
print(Female_data.columns[i]+" is not significantly different")
And we get the result:
Hotelling's T-squared =84.74826838379414
p =1.1102230246251565e-16
p(t)=[1.13631611e-044.24778379e-059.55243601e-08]
which is wrong. Can you help me to correct the code and help me to explain the result? Thank you!:)
 For this question, considering "multivariate case", we run the code: #

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!