Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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!:)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

Define Administration and Management

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago