Created
January 3, 2019 16:34
-
-
Save antonio-catalano/cce56fa27dcb43abcb7b874e39b8c53e to your computer and use it in GitHub Desktop.
Taleb IQ quiz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
def IQ(IQ_mean, IQ_std): | |
IQ_value_low = [] | |
IQ_value_high = [] | |
IQ_all = [] | |
for i in range(10000): | |
IQ_value = np.random.normal(IQ_mean, IQ_std) | |
IQ_all.append(IQ_value) | |
if IQ_value < IQ_mean: | |
IQ_value_low.append(IQ_value) | |
else: | |
IQ_value_high.append(IQ_value) | |
return (np.array(IQ_value_low), np.array(IQ_value_high), np.array(IQ_all)) | |
Mean_IQ = float(input('Choose the IQ mean: ')) | |
IQ_standard_deviation = float(input('Choose the IQ standard deviation : ')) | |
print('\n') | |
Corr_low_choice = float(input('Choose the correlation IQ/performance for group with low IQ: ')) | |
Corr_high_choice = float(input('Choose the correlation IQ/performance for group with high IQ: ')) | |
IQ_low = IQ(Mean_IQ, IQ_standard_deviation)[0] | |
IQ_high = IQ(Mean_IQ, IQ_standard_deviation)[1] | |
IQ_all = IQ(Mean_IQ, IQ_standard_deviation)[2] | |
perf_low = np.random.normal(IQ_low.mean(), IQ_low.std(), size = len(IQ_low)) | |
perf_high = np.random.normal(IQ_high.mean(),IQ_high.std(), size = len(IQ_high)) | |
perf_all = np.random.normal(IQ_all.mean(), IQ_all.std(), size = len(IQ_all)) | |
def unconditional_correlation(correlation_lowIQ, correlation_highIQ): | |
vector_mean_low = [IQ_low.mean(), perf_low.mean()] | |
covariance_low = perf_low.std() * IQ_low.std() * correlation_lowIQ | |
matrix_cov_low = np.array([[IQ_low.var(), covariance_low], [covariance_low, perf_low.var()]]) | |
M1 = np.random.multivariate_normal(vector_mean_low, matrix_cov_low, size = 10000) | |
print('Matrix sampling correlation for IQ low group:\n', np.corrcoef(M1.T)) | |
print('\n') | |
vector_mean_highIQ = [IQ_high.mean(), perf_high.mean()] | |
covariance_highIQ = perf_high.std() * IQ_high.std() * correlation_highIQ | |
matrix_cov_highIQ = np.array([[IQ_high.var(), covariance_highIQ], [covariance_highIQ, perf_high.var()]]) | |
M2 = np.random.multivariate_normal(vector_mean_highIQ, matrix_cov_highIQ, size = 10000) | |
print('Matrix sampling correlation for IQ high group:\n', np.corrcoef(M2.T)) | |
print('\n') | |
matrix_all = np.concatenate((M1,M2)) | |
return(np.corrcoef(matrix_all.T)[0][1]) | |
print('\nUncondional sampling correlation', unconditional_correlation(Corr_low_choice, Corr_high_choice)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment