/
Data Analysis Module: Bivariate Testing Data Analysis Module: Bivariate Testing

Data Analysis Module: Bivariate Testing - PowerPoint Presentation

lindy-dunigan
lindy-dunigan . @lindy-dunigan
Follow
343 views
Uploaded On 2019-11-24

Data Analysis Module: Bivariate Testing - PPT Presentation

Data Analysis Module Bivariate Testing Programming in R Data Analysis Module Basic Descriptive Statistics and Confidence Intervals Basic Visualizations Histograms Pie Charts Bar Charts Scatterplots Ttests ID: 767806

analysis data module testing data analysis testing module bivariate sample test hypothesis psu proportion number table type vector paired

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Data Analysis Module: Bivariate Testing" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Data Analysis Module: Bivariate Testing Programming in R

Data Analysis Module Basic Descriptive Statistics and Confidence Intervals Basic Visualizations HistogramsPie ChartsBar ChartsScatterplotsTtests/Bivariate testingOne SamplePairedIndependent Two SampleANOVAChi Square and OddsRegression Basics 2

The first part of these notes will address ttesting basics. The second part of these notes will address z test (or proportion testing) basics. Data Analysis Module:Bivariate Testing

The term “Ttest ” comes from the application of the t-distribution to evaluate a hypothesis. The t-distribution is used when the sample size is too small (less than 30) to use s/SQRT(n) as a substitute for the population std. In practice, even hypothesis tests with sample sizes greater than 30, which utilize the normal distribution, are commonly referred to as “ ttests”.Note: a “t-statistic” and a “z-score” are conceptually similar – both convert measurements into standardized scores which follow a roughly normal distribution.Data Analysis Module:Bivariate Testing

A side note of interest from Wikipedia: The t-statistic was introduced in 1908 by William Sealy Gosset , a chemist working for the Guiness Brewery in Dublin, Ireland. Gosset had been hired due to Claude Guinness's innovative policy of recruiting the best graduates from Oxford and Cambridge to apply biochemistry and statistics to Guinness' industrial processes. Gosset devised the t-test as a way to cheaply monitor the quality of beer. He published the test in Biometrika in 1908, but was forced to use a pen name by his employer, who regarded the fact that they were using statistics as a trade secret. Data Analysis Module:Bivariate Testing

Ttests take three forms: One Sample Ttest - compares the mean of the sample to a given number. e.g. Is average monthly revenue per customer who switches >$50 ?Formal Hypothesis Statement examples: H0:   $50 H1:  > $50 H 0 :  = $50 H 1 :   $50 Data Analysis Module: Bivariate Testing

Example: After a massive outbreak of salmonella, the CDC determined that the source was from a particular manufacturer of ice cream. The CDC sampled 9 production runs if the manufacturer, with the following results (all in MPN/g): .593 .142 .329 .691 .231 .793 .519 .392 .418 Use this data to determine if the avg level of salmonella is greater than .3 MPN/g, which is considered to be dangerous. Data Analysis Module: Bivariate Testing

First, Identify the Hypothesis Statements, including the Type I and Type II errors…and your assignment of alpha. Then, do the computation by hand… Data Analysis Module: Bivariate Testing

#here, the syntax is: t.test (vector to be analyzed, vector to be analyzed, * alternative hypothesis) * paired = TRUE for a paired ttestOne sample t test is the default Data Analysis Module: Bivariate Testing

Two Sample Ttest - compares the mean of the first sample minus the mean of the second sample to a given number. e.g. Is there a difference in the production output of two facilities? Formal Hypothesis Statement examples: H 0 :  a -  b =0 H 1: a - b  0 Data Analysis Module: Bivariate Testing

When dealing with two sample or paired ttests , it is important to check the following assumptions: The samples are independentThe samples have approximately equal varianceThe distribution of each sample is approximately normalNote – if the assumptions are violated and/or if the sample sizes are very small, we first try a transformation (e.g., take the log or the square root). If this does not work, then we engage in non-parametric analysis: Wilcoxan Rank Sum or Wilcoxan Signed Rank tests. Data Analysis Module: Bivariate Testing

# here the syntax is: t.test (vector to be tested~two level factor, data = data, var.equal=FALSE*)plot(t.test(vector to be tested~two level factor, data = data)*If the variances are similar, this would be set to TRUEData Analysis Module: Bivariate Testing

Paired Sample Ttest - compares the mean of the differences in the observations to a given number. e.g. Is there a difference in the production output of a facility after the implementation of new procedures? Formal Hypothesis Statement example: H 0 :  diff =0 H 1 :  diff  0Data Analysis Module: Bivariate Testing

#here, the syntax is: t.test (vector to be analyzed, vector to be analyzed, paired = TRUE for a paired ttest, alternative = “greater”*) *the alternative hypothesis could also be “less than”. The default is not equal.Data Analysis Module: Bivariate Testing

Z testing…or proportion based testing… Data Analysis Module: Bivariate Testing

The testing formula for a one sample proportion is a simple z calculation: Z = (sample estimate – Null value)/Null Standard Error For a proportion, this would be: Z=(p-po)/SQRT((po(1-po)/n) Data Analysis Module: Bivariate Testing

Example of a one sample proportion test: If 30% of cars on a street are found to be speeding, the city will install “traffic calming” devices. John used his radar gun to measure the speeds of 400 cars on his street. He found that 32% were speeding. Will John get “traffic calming” devices on his street? Data Analysis Module: Bivariate Testing

Table object1<-table(factor)Sum(object1) Prop.test (object1[factor level], totaln, correct=FALSE, p= null hypothesis)Example:loveatfirst.count <- table(PSU$atfirst)prop.test(loveatfirst.count[3],227, correct=FALSE, p=0.45)Note that the “3” indicates the third level of the factor – which is “Yes”.Data Analysis Module: Bivariate Testing

Answer the following: Identify the Null and Alternative Hypotheses Identify the Type I and Type II errors, including the implications What is an appropriate alpha value?What is the associated p-value?What is your conclusion?Data Analysis Module: Bivariate Testing

2. Two Sample Test - compares the proportion of the first sample minus the proportion of the second sample to a given number. It is of common interest to test of two population proportions are equal. e.g. Is there a difference in the percentage of students who pass a standardized test between those who took a prep course and those who did not? Formal Hypothesis Statement examples: H 0 : p a - p b =0 H 0: pa - pb <0 H1: pa - pb  0 H1: p a - p b > 0 Data Analysis Module: Bivariate Testing

Before you undertake a two sample test, there are few things to be determined: The two samples must be independent The number of individuals with each trait of interest and the number without the trait of interest must be at least 10 in each sample. Data Analysis Module: Bivariate Testing

#here, the code is pretty easy…just make the 2x2 table and then apply the prop.test function: FactorVar1.by.FactorVar2<-table(FactorVar1,FactorVar2)prop.test(FactorVar1.by.FactorVar2, correct=FALSE)Example: PSU$Wt <- ifelse(PSU$WtFeel=="RightWt","Right", ifelse(PSU$WtFeel=="OverWt"|PSU$WtFeel=="UnderWt", "Wrong","" ,))PSU <- PSU[-which(PSU$Wt==""),]sex.by.wt <- table(PSU$Sex, PSU$Wt) prop.test ( sex.by.wt , correct=FALSE) Data Analysis Module: Bivariate Testing

Answer the following: Identify the Null and Alternative Hypotheses Identify the Type I and Type II errors, including the implications What is an appropriate alpha value?Using the formula, determine the test statistic. What is the associated p-value?What is your conclusion? Data Analysis Module: Bivariate Testing