#Lowri Jones
#1801539

# 1. Load the data into a new dataframe keeping the headings.

        kickData<-read.csv("Kicks.csv", header=TRUE)
        
# 2. Create a new data frame that shows descriptive statistics
# for the air-filled and water-filled balls. Containing the following
# measures: mean, SD, median, max, min and range.
        
        # Individually creating vectors that contain the required
        # descriptive measures.
        
        airMean<- mean(kickData$Air, na.rm=TRUE)
        heliumMean<- mean(kickData$Helium, na.rm=TRUE)
        airSD <- sd(kickData$Air, na.rm=TRUE)
        heliumSD <- sd(kickData$Helium, na.rm=TRUE)
        airMedian<- median(kickData$Air, na.rm=TRUE)
        heliumMedian <- median(kickData$Helium, na.rm=TRUE)
        airMax <- max(kickData$Air, na.rm=TRUE)
        heliumMax <-max(kickData$Helium, na.rm=TRUE)
        airMin <- min(kickData$Air, na.rm=TRUE)
        heliumMin <- min(kickData$Helium, na.rm=TRUE)
        airRange <- range(kickData$Air, na.rm=TRUE)
        heliumRange <- range(kickData$Helium, na.rm=TRUE)
        
        # Creating the data frame.
        
        kickSummary <- data.frame(kickData$Air, airMean, airSD, airMedian, 
                                   airMax, airMin, airRange,
                                   kickData$Helium, heliumMean, heliumSD, heliumMedian,
                                   heliumMax, heliumMin, heliumRange)
        
        # Displaying the data frame.
        
        kickSummary

# 3. Use the Shapiro test for normality and the box plot to find any
# outliners, clean your data to remove any outliners and show that the 
# resulting data is normal.
        
        shapiro.test(kickData$Air)
        shapiro.test(kickData$Helium)
        
        # As you can see from the results above, the p-number of air
        # shows that the data set is normally distributed however,
        # the p-number of helium suggests that this data set isn't
        # normally distributed.
        
        #Checking the box plot for air.
        
        boxplot(kickData$Air)
        
        #Checking the box plot for helium.
        
        boxplot(kickData$Helium)
        
              #While checking for outliners in Helium, I realised there were some above 36.
              #Below I have filtered the helium kicks into a new vector.
        
              neilHelium<-kickData$Helium[kickData$Helium<36]
               
              #Displaying the new vector in a box plot to see the changes.
        
              boxplot(neilHelium)
              
              #There were still some outliners which were less than 20. Below I have filtered
              #the new vector.
        
              neilHelium<-neilHelium[neilHelium>20]
              
              #Displaying the new vector in a box plot to see the changes.
        
              boxplot(neilHelium)
        
  
# 4. Perform a T-test on the data to see if there is a 
# big difference in differences travelled between the two types
# of balls. State the experimental hypothesis, result of the test
# and wehter i accept or reject the null hypothesis.
        
        # NULL HYPOTHESIS - There won't be a big difference in the distances travelled and 
        # the helium-filled ball will travel futher than the air-filled ball.
        
        # EXPERIMENTAL HYPOTHESIS - There will be a big difference in the distances travelled
        # and the air-filled ball will travel further than the helium-filled ball.
       
        t.test(kickData$Air, kickData$Helium)
        
        # RESULTS - When the T-Test above was run, it gave me a low P-value and
        # T-Value which means I am able to reject my Null-Hypothesis. The air-filled
        # ball travels further than the helium-filled ball.
        
        
# 5. All odd-numbered kicks were kicked by Neil and all even numbers were kicked by Jonny,
# See if there is a significant difference between the two. 
  
        # Creating a new vector which contains ALL even kick numbers for Johnny.
        johnny <- c(kickData$Air[kickData$Air%%2==0], kickData$Helium[kickData$Helium%%2==0])
        
        # Creating another new vector which contains ALL odd kick numbers for Neil.
        neil <- c(kickData$Air[kickData$Air%%2!=0], kickData$Helium[kickData$Helium%%2!=0])
        
        
        # Conducting a T-Test to figure out if there is a significent difference between the two.
        t.test(johnny, neil)