From: Leitch, Matthew C.
Sent: Monday, January 24, 2011 6:53 PM
To: 'i...@network-theory.co.uk'
Subject: question about the pt() calculation

Hello

Thank you for your time. I am a graduate student at the University of Texas 
Medical Branch, and I was wondering if you could help me with a R program I am 
writing. I have some data that is stored a file that has 1733 rows and 4 
columns. Each row is independent, so I have a loop system so I don't have to 
manually perform 1733 t-tests. However I got most of it to work, thanks to the 
"An Introduction to R" book and a helpful colleague. But I am having some 
difficulty with getting my t-test scores converted to p-values. The pt() test 
won't take the t object, but I am unsure how to make it create a p-value for 
each row. If you have any suggestions they would be greatly appreciated.

Best Wishes
Matt
cancer<-read.table("group2.txt", header=TRUE)
noncancer<-read.table("group1.txt", header=TRUE)

#meanc<-mean(cancer)
#meannc<-mean(noncancer)
#varc<-var(cancer)
#varnc<-var(noncancer)
#Sx1x2<-sqrt((varc+varnc)/2)
#n<-4
#t<-(noncancer-cancer)/(Sx1x2*(sqrt(2/n)))
#df<-(2*n)-2
#pt(t,df)*2


answer = matrix(,1733,1);
alpha = 0.05;


#for(i=1:1733)
#{
#  meanc = mean(cancer[i,]);
#  meannc = mean(noncancer[i,]);
#  
#  varc = var(cancer[i,]);
#  varnc = var(noncancer[i,]); 
#
#  Sx1x2 = sqrt((varc+varnc)/2);
#  n = 4;
#  t = (noncancer-cancer)/(Sx1x2*(sqrt(2/n)));
#  df = 2*n - 2;
#
#
#  answer[i,1] = pt(t,df)*2;
#
#  if (answer[i,1] = alpha)
#  {
#    sing.
#  }
#  else
#  {
#    nonsing.
#  }
#}

for(i in 1:1733)
{
  meanc = mean(cancer[i,]);
  meannc = mean(noncancer[i,]);
  
  varc = var(cancer[i,]);
  varnc = var(noncancer[i,]); 

  Sx1x2 = sqrt((varc+varnc)/2);
  n = 4;
  t = (noncancer-cancer)/(Sx1x2*(sqrt(2/n)));
  df = 2*n - 2;

  answer[i,1] = pt(t,df)*2 ;

  if (answer[i,1] < alpha)
  {
    banswer[i,1] = 1;
  }
  else
  {
    banswer[i,1] = 0;
  }

  #ifelse(answer[i,1] < alpha, banswer[i,1] = 1, banswer[i,1] = 0);



}
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to