Breaking News

Tuesday, January 2, 2018

One Sample T Test in R

[WELCOME TO INFO STATISTICS]
Let's start this year by sharing knowledge about Statistics. 

I would like to share about, how to use one sample t-test  in an inferensia statistical analisys and apply in R software. Did you know about one sample t-test before ?,  following that statement below :

One sample t test is analytical technique to compare one independent variable. This technique is used to test whether a particular value differs significantly or not with the average of a sample. In t-test, there is an assumption that must be fulfilled is normal distributed sample data. 

There are two kinds of hypothesis in t-test :
  1. One Tailed
    One tailed is usually used to see if the average of the sample is more than or less than the reference average.

    a. The Right Hypothesis
    H0 :  µ ≤ µ0 ( Average Sample ≤ Reference Average )
    H1 :  
    µ > µ( Average Sample > Reference Average )

    b. The left Hypothesis
    H0 :  µ ≥ µ0 ( Average Sample ≥ Reference Average )
    H1 :  
    µ < µ( Average Sample < Reference Average )
  2. Two Tailed
    Two tailed is is used to see if the average value of a single sample equals (=) the reference value or not
    H0 :  µ = µ0 ( Average Sample ≥ Reference Average )
    H1 :  µ ≠ µ0 ( Average Sample < Reference Average )
In testing the hypothesis, the criterion of rejection or acceptance of H0 is based on the value of P-Value or T-table value.
  • use p-value

    If the value of P-value (Sig.) < a = 5%, then H0 is rejected,
    If the value of P-value (Sig.) > a = 5%, then H0 is accepted.
  • Use T-table
    If the value of t-count > t-table, then H0 is rejected,

    If the value of t-count < t-table then H0 is accepted
Case study :
Question :
Based on data from a company A about the number of bicycle sales for a month, it turns out that in a month the average sales is 70 peaces of laptops, test the hypothesis of whether the statement is true !. the data can be download in ( Data trainning )



Based on the above data, we will try to how to apply this analisys in R software. let's do it.

  • open R or R studio in your PC 
  • if it's opened, Klik file >> new file >> R script 
  • write your script in R script, you can copy this script below in your worksheet :
#using read.delim function
##you have to copy the data first in your file have been downloaded, 
##then write the following script

data=read.delim("clipboard")
data
  • If you want to see the data, you can write the script below :  
#to see the data in R   
View(data)
  • Now we start to analisys. R provide a function to perform T-test. The function is "T.test". we will use this function to finishing the case. 
 t.test(data1$Sales,mu=70)

Following the result of one sample t-test analisys  :


Based on the above output, we can see that the mean sales of laptops for the sample is 61. The two-sided 95% confidence interval tells us that mean sum of sales between 53,19 and 68,80. The p-value of 0.0255 tells us that the p-value (0.0255 ) < a (0,05)  which mean H0 is rejected. So that,the conculsion is the average sales of Laptops not equal to 70 peaces. 

if you wanna get more information you can choose this link below :

Thanks for attention and see you next post :)

No comments:

Post a Comment

Copyright by INFO STATISTICS