Skip to content

calculating t-score/t-stats as my zscores

13 messages · Ana Marija, Patrick (Malone Quantitative), Rui Barradas

#
Hello,

Can I apply the quantile function qt() this way?
qt(pvals/2, 406-34, lower.tail = F)
to get the T-scores?

Thanks
Ama
#
Hello,

That gives the *absolute* t-scores. If it's all you need/want, then the 
answer is yes, you can.

Hope this helps,

Rui Barradas

?s 14:28 de 06/05/20, Ana Marija escreveu:
#
Hi Rui,

Thank you for getting back to me. Is there is a better way to
calculate Z scores if I have p values, SE and Beta?

Thanks
Ana
On Wed, May 6, 2020 at 9:27 AM Rui Barradas <ruipbarradas at sapo.pt> wrote:
#
Hello,

Sorry but after reading my answer I believe it's not completely clear.

I meant absolute values, the actual t-scores as computed from the data 
might be negative. Your code will always produce positive numbers.

Hope this helps,

Rui Barradas

?s 15:27 de 06/05/20, Rui Barradas escreveu:
#
thanks, can you please tell em what would be the way not to get the
absolute (always positive values)
On Wed, May 6, 2020 at 9:33 AM Rui Barradas <ruipbarradas at sapo.pt> wrote:
#
I guess I can have

z-score=Beta/StdErr
On Wed, May 6, 2020 at 9:37 AM Ana Marija <sokovic.anamarija at gmail.com> wrote:
#
Hello,

By z-scores do you mean function help('scale')?

Hope this helps,

Rui Barradas

?s 15:31 de 06/05/20, Ana Marija escreveu:
#
as defined here:
https://huwenboshi.github.io/data%20management/2017/11/23/tips-for-formatting-gwas-summary-stats.html

where Effect size is Beta
On Wed, May 6, 2020 at 9:41 AM Rui Barradas <ruipbarradas at sapo.pt> wrote:
#
Guessing for Ana, but no, that's a different meaning. Beta/StdErr is a
z statistic--a test statistic against (usually) the tails of the unit
normal distribution. So like a t-test with infinite df.
On Wed, May 6, 2020 at 10:41 AM Rui Barradas <ruipbarradas at sapo.pt> wrote:

  
    
#
Thanks Patrick, so in conclusion this is fine?
z-score=Beta/StdErr

On Wed, May 6, 2020 at 9:52 AM Patrick (Malone Quantitative)
<malone at malonequantitative.com> wrote:
#
Hello,

You can write a function to compute the scores:


z_score <- function(x, beta = mean, beta0 = 0){
   beta <- match.fun(beta)
   n <- length(x)
   score <- sqrt(n)*(beta(x) - beta0)/sd(x)
   names(score) <- if(n < 30) "t.score" else "z.score"
   score
}

# data example
x <- rt(20, df = 1)
tt <- t.test(x)

pvals <- tt$p.value

# Now compare these 3 results and see if it answers the question

qt(pvals/2, 19, lower.tail = F)
tt$statistic
z_score(x)


Hope this helps,

Rui Barradas

?s 15:40 de 06/05/20, Ana Marija escreveu:
#
Hello,

Another option is to use stats::t.test

t.test(x)$statistic

Or, if you want to test against a beta0 != 0,

t.test(x, mu = beta0)$statistic


But in this case the estimator is the estimator for the mean value.

Hope this helps,

Rui Barradas

?s 15:54 de 06/05/20, Ana Marija escreveu:
#
Thank you so much! I mostly worry which of those procedures is the
closest to the z-score
On Wed, May 6, 2020 at 10:05 AM Rui Barradas <ruipbarradas at sapo.pt> wrote: