LetX be a matrix of random normal values (mean =0; sd=1) having 10 columns andN=100 rows. Reset the values in the first row in the matrix to(1,1.5,1.4,3,1.9,4,4.9,2.6,3.2,2.4). Assume that the first 5 columns of datafor each row correspond to a group A, while the remaining 5 to another group B.
1.) For each row of the matrix X, compute:
a) the t-statistic comparing the groups A and B assuming equalvariance and the p-value
b) Compute theprobability to observe such a t-statistics only by chance, using a permutationanalysis. The following strategy will be used: the columns will be randomlypermuted nk=1000 times, and at each iteration the t-statistic will be computedagain and recorded in a vector. At the end, compute the p-value as the numberof times out of nk when the t-statistic with the permuted data was at least asor more extreme than the t-statistics obtained with the real (non-permuteddata).
Present the result as a data.frame with 4 columns: ID= Row number,t= t-score, p_theoretical=p-value assuming the asymptotic distribution;p_permutations=p-value from permutations;
Sort the data.frame in descending order of p-values.
2.) Plot the distribution (see hist)of the resulting vector of t-scores obtained at step 1a) after excluding the first element (correspondingto the first row) and on the same graph show a vertical line for the t-value ofthe first row.