Inverse t-distribution in R - GeeksforGeeks

06 Jun, 2021
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
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, 
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 librarylibrary("PEIP")  # defining p-valuep <- 0.4nu <- 2print ("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-valuep <- 1e-20nu <- 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 vecx <- seq(.1, .9, by = .1)  # Calling qt() Functiony <- qt(x, 15)print ("inverse t-distribution")print (y)  # plotting dataplot (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
Picked
R-Statistics
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Control Statements in R Programming
Change Color of Bars in Barchart using ggplot2 in R
Data Visualization in R
Group by function in R using Dplyr
How to Change Axis Scales in R Plots?
Logistic Regression in R Programming
Linear Discriminant Analysis in R Programming
How to filter R DataFrame by values in a column?
How to change Colors in ggplot2 Line Plot in R ?
How to import an Excel File into R ?