I imported a dataset named "multiple.txt" into R using the read.table function. The table contains 50 variables and 100 observations per variable. Each variable is named V1, V2, V3,...,V50.
The goal is to implement multiple testing across all 50 variables using the t-stat equation T = (x-bar - 0)/(Sx/sqrt(n). I was wondering if you could post sample code to run the t-statistic equation comparing each variable sample mean to 0, making a vector with all 50 of the t-stats, and then making a vector with each p-value.
The following R code can be used to solve the required solution:-
------------------------------------------------------------------------------------------------------------------------------------
d=read.table()
T=array(dim=1)
pvalue=array(dim=1)
for(i in 1:ncol(d))
{
T[i]=(mean(d[,i])-0)/sqrt(var(d[,i])/100)
pvalue[i]=1-pt(T,99)
}
result = cbind(T,pvalue)
print(result)
------------------------------------------------------------------------------------------------------------------------------------
Get Answers For Free
Most questions answered within 1 hours.