t-Distribution

Class Example

# Read Data File
bigCity <- read.csv("C:\\Users\\samy_\\Desktop\\R_Python_Machine Learning DataSets\\bigcity.csv")
attach(bigCity)

# plot Histogram and Density Function
hist(log(u), probability = TRUE)
xx <- seq(min(log(u)), max(log(u)), length = 100)
lines(xx, dt(xx, df = 99, ncp = mean(log(u))))

Function to check whether data follows t-distribution or not (Using library: lmenssp)

library(lmenssp)
## Loading required package: MASS
## Loading required package: nlme
## Loading required package: mvtnorm
## Loading required package: geoR
## --------------------------------------------------------------
##  Analysis of Geostatistical Data
##  For an Introduction to geoR go to http://www.leg.ufpr.br/geoR
##  geoR version 1.7-5.2.1 (built on 2016-05-02) is now loaded
## --------------------------------------------------------------
# Normalize the data to mean=0 sd=1
log_u_norm <- (log(u)-mean(log(u)))/(sd(log(u)))

qqplot.t(log_u_norm, length(u)-1)

Function to check whether data follows t-distribution or not (using library: Dowd)

library(Dowd)
## Loading required package: bootstrap
## Loading required package: forecast
## 
## Attaching package: 'forecast'
## The following object is masked from 'package:nlme':
## 
##     getResponse
TQQPlot(log(u), df = length(u)-1)

Function to check whether data follows t-distribution or not (using library: car)

library(car)
## Loading required package: carData
qqPlot(log(u), distribution = "t", df = length(u)-1)

## [1] 10 23

t-score calculations

qt(0.975, df = 199) # 95% Confidence Interval
## [1] 1.971957
qt(0.95, df = 199) # 90% Confidence Interval
## [1] 1.652547
qt(0.995, df = 199) # 99% Confidence Interval
## [1] 2.60076

Probability Calculations

pt(1.984, df = 199)
## [1] 0.9756848
pt(2.626, df = 199)
## [1] 0.9953444
pt(1.66, df = 199)
## [1] 0.9507553

Students t-distribution

x <- rt(1000, df = 199)
hist(x, probability = TRUE)
xx <- seq(min(x), max(x), length = 100)
lines(xx, dt(xx, df = 199))