r - trying to perform a paired t.test for each row and count all rows where p-value is less than 0.05 -


i've been wrecking head past 4 hours trying find solution r problem, driving me nuts. i've searching everywhere decent answer (including stackoverflow.com) far i've been hitting wall after wall. appealing of fine community :)

consider following dataset:

set.seed(2112) datasample <- matrix(rnorm(24000),nrow=1000) colnames(datasample) <- c(paste("trial",1:12,sep=""),paste("control",13:24,sep="")) 

i need perform t-test every row in datasample in order find out if groups trial , control differ (equal variance applies).

then need count number of rows p-value equal to, or lower 0.05.

so here code tried, know wrong:

set.seed(2112) datasample <- matrix(rnorm(24000),nrow=1000) colnames(datasample) <- c(paste("trial",1:12,sep=""),paste("control",13:24,sep=""))  pvalresults <- apply(   datasample[,1:12],1,function(x) t.test(x,datasample[,13:24], var.equal=t)$p.value   )  sum(pvalresults < 0.05) # returns wrong answer (so told) 

i did try looking @ many similar questions around stackoverflow, end-up syntax errors or dimensional mismatch. code above best without returning me r error -- since code returning wrong answer have nothing feel proud of.

any advice appreciated! in advance time.

regards, p.

one option loop on data set calculating t test each row, not elegant.

set.seed(2112) datasample <- matrix(rnorm(24000),nrow=1000) colnames(datasample) <- c(paste("trial",1:12,sep=""),paste("control",13:24,sep=""))  # initialize vector of stored p-values pvalue <- rep(0,nrow(datasample))  (i in 1:nrow(datasample)){    pvalue[i] <- t.test(datasample[i,1:12],datasample[i,13:24])$p.value } # finding number significant sum(pvalue < 0.05) 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -