Open In App

Inverse t-distribution in R

Last Updated : 06 Jun, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In probability and statistics, Student’s t-distribution (or simply the t-distribution) is any member of a family of continuous probability distributions. It comes to the picture when estimating the mean of a normally distributed population, where the sample size is small and the standard deviation (S.D) is undefined and unknown. The t distribution with df = n degrees of freedom has density

f(x) = \gamma(\frac{n+1}{2}) / (\sqrt(n pi) \gamma(n/2)) (1 + x^2/n)^-((n+1)/2)

If a random variable X has a T-distribution with ν degrees of freedom, then Pr (X ≤ x) = P. Suppose that Z and Y are independent random variables. Let Z be a standard normal random variable (mean of 0, the variance of 1). And Y a chi-square variable with m degrees of freedom. Now, we have, 

T = \frac{Z}{\sqrt{\frac{Y}{m}}}

The variable T has the t distribution with m degrees of freedom.

Method 1: Using tinv() method

PEIP is a package in R which is used to apply many MATLAB translations and computations in R. It is useful for data statistics and mathematical operations. This method is more precise in comparison to the qt() method. The package can be installed into the working space using the following command : 

install.packages("PEIP")

tinv() method of this package is based on the betaincinv function. It is used to compute inverse t-distribution. It returns the quintile for T-distribution. A p-value is a probability that the results from your sample data occurred by chance.

Syntax: tinv(p, nu)

Arguments : 

  • p : P-value
  • nu : degrees of freedom

The following code snippet illustrates the calculation of inverse t-distribution considering the random probability of a number 0.4 (p -value) with 2 degrees of freedom : 

R

# loading the required library
library("PEIP")
  
# defining p-value
p <- 0.4
nu <- 2
print ("Inverse t-distribution")
tinv(p, nu)

                    

Output:

[1] "Inverse t-distribution" 
[1] -0.2887

Method 2: Using qt() method

qt() method in base R is used to return the inverse probability cumulative density of the Student t-distribution, also known as the T-distribution. It is basically a quantile function. 

Syntax: qt(p, nu )

Arguments :

  • p : vector of probabilities.
  • nu : degrees of freedom

The following code snippet illustrates the calculation of inverse t-distribution considering the random probability of an tiny exponential number 1e-20 (p -value) with 2 degrees of freedom. The negative sign illustrates that it is declining in nature much towards the -ve NaN : 

R

# defining p-value
p <- 1e-20
nu <- 2
  
print ("Inverse t-distribution")
qt(p, nu)

                    

Output:

[1] "Inverse t-distribution" 
[1] -7071067812

A vector of x values is taken in the form of a sequence, considering the number of degrees of freedom to be 15. The corresponding y values can be computed by using qt() method in R. The following code snippet illustrates the usage of this method over a vector of values : 

R

# creating a vec
x <- seq(.1, .9, by = .1)
  
# Calling qt() Function
y <- qt(x, 15)
print ("inverse t-distribution")
print (y)
  
# plotting data
plot (x, y, type = "o")

                    

Output:

[1] “inverse t-distribution” 

[1] -1.3406056 -0.8662450 -0.5357291 -0.2578853  0.0000000  0.2578853  0.5357291  0.8662450  1.3406056



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads