Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Rstudio, how do I calculate 2 new variables (1.homeruns per at bat before

ID: 3048958 • Letter: U

Question

Using Rstudio, how do I calculate 2 new variables (1.homeruns per at bat before steroids 2. homeruns per at bat with steroids) and use a paired t-test to determine to determine if there was a difference between steroid and non steroid homerun hitting?

Player

HomeRunsBefore

AtBatsBefore

HomeRunsAfter

AtBatsAfter

J. Bagwell

140

3095

306

4602

B. Bonds

504

7725

258

2122

J. Canseco

90

1815

551

8553

M. Maguire

338

4194

245

1993

D. Ortiz

141

2952

279

3878

R. Palmeiro

196

5222

373

1410

A. Rodriguez

193

3696

545

5966

I. Rodriguez

149

6162

162

3430

S. Sosa

107

2563

502

6250

Player

HomeRunsBefore

AtBatsBefore

HomeRunsAfter

AtBatsAfter

J. Bagwell

140

3095

306

4602

B. Bonds

504

7725

258

2122

J. Canseco

90

1815

551

8553

M. Maguire

338

4194

245

1993

D. Ortiz

141

2952

279

3878

R. Palmeiro

196

5222

373

1410

A. Rodriguez

193

3696

545

5966

I. Rodriguez

149

6162

162

3430

S. Sosa

107

2563

502

6250

Explanation / Answer

Save the data as player.csv and load the file in RStudio with the below commands.

> player = read.csv("player.csv", header = TRUE)
> player

Player HomeRunsBefore AtBatsBefore HomeRunsAfter AtBatsAfter
1 J.Bagwell 140 3095 306 4602
2 B.Bonds 504 7725 258 2122
3 J.Canseco 90 1815 551 8553
4 M.Maguire 338 4194 245 1993
5 D.Ortiz 141 2952 279 3878
6 R.Palmeiro 196 5222 373 1410
7 A.Rodriguez 193 3696 545 5966
8 I.Rodriguez 149 6162 162 3430
9 S.Sosa 107 2563 502 6250

1. homeruns per at bat before steroids is calculated as

> HomeRunsPerAtbat.Before = player$HomeRunsBefore / player$AtBatsBefore
> HomeRunsPerAtbat.After = player$HomeRunsAfter / player$AtBatsAfter
> HomeRunsPerAtbat.Before

[1] 0.04523425 0.06524272 0.04958678 0.08059132 0.04776423 0.03753351 0.05221861 0.02418046 0.04174795
> HomeRunsPerAtbat.After
[1] 0.06649283 0.12158341 0.06442184 0.12293026 0.07194430 0.26453901 0.09135099 0.04723032 0.08032000

Paired t-test to determine if there was a difference between steroid and non steroid homerun hitting is done by the below command.

> t.test(HomeRunsPerAtbat.Before,HomeRunsPerAtbat.After)

   Welch Two Sample t-test

data: HomeRunsPerAtbat.Before and HomeRunsPerAtbat.After
t = -2.4029, df = 8.9678, p-value = 0.0398
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.105018871 -0.003139601
sample estimates:
mean of x mean of y
0.04934443 0.10342366

The p-value of the test is 0.0398 which is less than the significance level of 0.05. So, we reject the null hypothesis and conclude that there was significant difference between steroid and non steroid homerun hitting

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote