PSYC274_Lab4

.docx

School

Temple University *

*We aren’t endorsed by this school

Course

2901

Subject

Psychology

Date

Apr 26, 2024

Type

docx

Pages

4

Uploaded by AgentFlag14011

Report
PSYC 274 Lab 4: Sampling Distributions First, make sure to run this following line to read the source code Rallfun-v41.txt . source ( file.choose ()) Sampling Distribution Let’s read in the lab_274_rat.data from Lab 1 and focus on column 2 ( rat[,2] ), and use it as an example to create a sampling distribution. rat = read.table ( file.choose ()) rat[, 2 ] ## [1] 10.1 6.1 20.4 7.3 14.3 15.5 -9.9 6.8 28.2 17.9 - 9.0 -12.9 ## [13] 14.0 6.6 12.1 15.7 39.9 -15.9 54.6 -14.7 44.1 -9.0 NA There’s a missing value in column 2. For convenience, we will first eliminate it and store the data in x . (Some functions will have errors if you do not eliminate missing values first.) x = elimna (rat[, 2 ]) x # to show you x ## [1] 10.1 6.1 20.4 7.3 14.3 15.5 -9.9 6.8 28.2 17.9 - 9.0 -12.9 ## [13] 14.0 6.6 12.1 15.7 39.9 -15.9 54.6 -14.7 44.1 -9.0 Now we can get the mean and standard deviation of our sample. mean (x) ## [1] 11.00909 sd (x) ## [1] 19.01711 length (x) ## [1] 22 Based on a sample of n = 22 observations, the central limit theorem suggests that the distribution of the sample mean will be approximately normal with mean 11 and standard deviation σ n = 19.017 22 = ¿ 4.05 (i.e., standard error of the means).
So the probability that the sample mean is less than or equal to 9 is estimated to be: pnorm ( 9 , 11 , 4.05 ) ## [1] 0.3107141 To illustrate the concept of a sampling distribution, let’s determine this probability using a simulation. We first initialize an R variable xbar where the sample means will be stored. xbar = NA Next, we use a for loop function to draw 22 observations from x 5000 times, and get the mean. This mimics the process of repeating the study 5000 times. set.seed ( 45 ) # This sets the seed of the random number generator so that the results can be duplicated for (i in 1 : 5000 ){ z = sample (x, 22 , replace= TRUE ) # sample 22 observations from x, with replacement (i.e., possible to draw one item more than once at a given sample) xbar[i] = mean (z) } Now we have 5000 sample means in xbar . The proportion of sample means less than or equal to 9 is mean (xbar <= 9 ) ## [1] 0.3076
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help