I have a vector of correlation coefficients (r) and a vector containing numbers of observations (n), and I want to test each of them to see whether they significantly differ from 0.
r = c(.69,.32,.75,.69,.42,.53,.25,.27,.1,-.15,.48,.39)
n = c(41,233,44,44,44,44,217,217,217,217,217,217)
##### t-values
rt <- function(r,n){
cbind(r/(sqrt((1-r^2)/(n-2))),
n)
}
rt(r,n)
Calaculating the t-values is easy, but is there a way to test them using R, rather than resorting to tables in the back of your stats book?
As to not letting my question stay unanswered, this is how i finally solved it. Thanks to @user20650 for providing the solution!
r = c(.69,.32,.75,.69,.42,.53,.25,.27,.1,-.15,.48,.39)
n = c(41,233,44,44,44,44,217,217,217,217,217,217)
rPV = function(r,n,dec = 8){
# calculate t-values
rt <- function(r,n){
t.value = abs(r/(sqrt((1-r^2)/(n-2))))
return(t.value)
}
t.value = rt(r,n)
df = n-2
CDF = round(pt(t.value,df = df),dec) # find location of t-values on the student t-distribution (quantiles).
p.value = round(1-pt(t.value, df = df),dec)
return(cbind(r,n,df,t.value,CDF,p.value))
}
rPV(r,n)
Having this solution, I'd rather recommend calculating confidence intervals than p-values in the end -- they do require some transformation, but allow you to set the confidence level in advance, as well as being ultimately easier to interpret.