Question

STATS Use the R function rnorm() to simulate selecting a random sample of size 25 from...

STATS

Use the R function rnorm() to simulate selecting a random sample of size 25 from a population with mean 80 and s.d. 20. The goal here is to show how contamination affects the mean, s.d., and z-scores.

(a) Obtain the sample mean and sample sd of the simulated sample and use them to obtain the z-score for 100.

(b) Create the vector contam = c(0,seq(1000,10000,length=21)) To show the effects of contamination, separately add each value of contam to the largest value in the simulated data set, and then recompute the sample mean, sd, and z-score of 100 for each of these contaminated samples. This will result in vectors of length 22 that contain the recomputed means, sd's, and z-scores. Note that the first element of each of these vectors will be the corresponding mean, sd, and z-score of the original simulated data. For the following plots use type = "b" so that the points are connected by lines.

(c) Plot the recomputed means versus the values of contam.

(d) Plot the recomputed s.d.'s versus the values of contam.

(e) Plot the recomputed z-scores versus the values of contam.

Note: the sorted data can be obtained by

xs = sort(x,decreasing=TRUE)

You need to add each value of contam to the largest value in the sample which is xs[1]. So you will end up with 22 recomputed means, 22 recomputed s.d.'s, and 22 recomputed z-scores. An efficient way to setup this problem is to create a matrix that contains 22 columns each of which is the sorted vector xs.

nc = length(contam)

xmat = matrix(rep(xs,nc),ncol=nc)

Then add contam to the first row of that matrix to obtain the contaminated samples (the first column will be unchanged since the first element of contam is 0). Next use the apply function to obtain column means and sd's.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution v-rnorm (25, 80,20) >v-rnorm (25, 80,20) [1 60.99525 63.22160 104.05939 68.3377378.09106 72.82478 121.10129 [8] 131.

val t111 11 88.2580575 19.7266752 0.5952317 t211 [1] 128.2580575 209.8382485 -0.1346659 t1311 11 146.2580575 299.6187870 -0.1t1181 1 416.2580575 1649.2002068 -0.1917645 t t1911 1 434.2580575 1739.1954028 -0.1921912 t [20] [1] 452.2580575 1829.1910715R Graphics: Device 2 (ACTIVE) 200 300 400 100 xcord d) xcord- lapply (val, [,2) plot (xcord, ycord, typeb)R R Graphics: Device 2 (ACTIVE) 1000 1500 2000 xcord xcord- lapply (val, ,3) plot (xcord, ycord, type-b).0 0 o-o-o-o-o-o-o-o-o.0.0.0.0.0.0.0.0.0 8 8 0009 8 000, 8

Executable R Code:

v=rnorm(25,80,20)

a)

m=mean(v)

s=sd(v)

z=(100-m)/s

b)

contam=c(0,seq(1000,10000,length=21))

v1=v

val=list()

for(i in 1:22)

{

k=which.max(v)

v[k]=v[k]+contam[i]

vec=c(mean(v),sd(v),(100-mean(v))/sd(v))

val[[i]]=vec

v=v1

}

xcord= lapply(val, '[[', 1)

ycord=contam

plot(xcord,ycord,type="b")

d)

xcord= lapply(val, '[[', 2)

plot(xcord,ycord,type="b")

e)

xcord= lapply(val, '[[', 3)

plot(xcord,ycord,type="b")

Add a comment
Know the answer?
Add Answer to:
STATS Use the R function rnorm() to simulate selecting a random sample of size 25 from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • i need help on question 3 to 22 please. Midterm ex review. MATH 101 Use the...

    i need help on question 3 to 22 please. Midterm ex review. MATH 101 Use the following information to answer the next four exercises. The midterm grades on a chemistry exam, graded on a scale of 0 to 100, were: 62, 64, 65, 65, 68, 70, 72, 72, 74, 75, 75, 75, 76,78, 78, 81, 82, 83, 84, 85, 87, 88, 92, 95, 98, 98, 100, 100,740 1. Do you see any outliers in this data? If so, how would...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT