LAB REPORT ( Self Design & Simulated Data Points ) 750 Words Only

profileUser_934652
ScripttoSimulateData.docx

#########################################

### Script for BSC302 Research Report ###

#########################################

# You will have to change 3 (three) values in this script. Only change the values where it indicates you should do so.

# Do not touch anything in this section!!!! You will see the "Do not touch!!!!" message a lot. Sorry for being repetitive, but this warning saves a lot of time.

# indicates comments; that is, it is not code

# Before Step 1, modify the 3 numbers in the code according to your measurements. See explanation of this in the video.

# Step 1: Copy and paste the whole code in RStudio Cloud or RStudio.

# Step 2: Run the code.

# Step 3: The code generates a cvs file, which is your dataset.

# Step 4: Save the file in your computer.

###########################################################

### Generate numbers from a standard normal distribution###

###########################################################

# Do not touch anything in this section!!!!

set.seed(343) # necessary step for the generation of random numbers

participants = c (1:100) # it generates a vector with numbers 1 to 100

gender = c(rep("female",25),rep("male",25), rep("female",25),rep("male",25)) # it generates a vector with 50 instances of female and 50 instances of male

age = round(rnorm(n=100,mean=35,sd=5)) # it generates a vector with 100 ages

set.seed(989) # necessary step for the generation of random numbers

iv1_norm = rnorm (n=100, mean=0, sd=1) # it generates a vector of 100 numbers coming from a normal distribution with mean=0 and sd=1

set.seed(454) # necessary step for the generation of random numbers

iv2_norm = rnorm (n=100, mean=0, sd=1) # it generates a vector of 100 numbers coming from a normal distribution with mean=0 and sd=1

set.seed(101) # necessary step for the generation of random numbers

error = rnorm (n =100, mean=0, sd=1) # it generates a vector of 100 numbers coming from a normal distribution with mean=0 and sd=1

dv_norm = iv1_norm * .35 + iv2_norm * .1 + error * .6 #it generates a vector of 100 numbers for the dependent variable based on a combination of the independent variables.

#########################################

##### transform normal to raw ##########

#########################################

# Only in this section you need to change values. Do not touch anything in the sections above.

# The values generated above come from a *standard* normal distribution; therefore, there are negative and positive numbers centred around zero.

# This section transforms those values into the scale of the measurements you chose for your study.

# Change this value!!! First value to change.

mean_iv1 = 30 # This is the mean of your independent variable 1. Change this value based on the appropriate value for the measurement you chose.

sd_iv1 = mean_iv1 * .1 # This generates the standard deviation of independent variable 1. Do not touch!!!!

# Change this value!!! Second value to change.

mean_iv2 = 50 # This is the mean of your independent variable 2. Change this value based on the appropriate value for the measurement you chose.

sd_iv2 = mean_iv2 * .1 # This generates the standard deviation of independent variable 2. Do not touch!!!!

# Change this value!!! Third value to change. This is the last value to change!!!

mean_dv = 120 # This is the mean of your dependent variable. Change this value based on the appropriate value for the measurement you chose.

sd_dv = mean_dv * .1 # This generates the standard deviation of independent dependent variable. Do not touch!!!!

iv1 = round(mean_iv1 + (iv1_norm * sd_iv1),0) # This creates raw values and rounds the values of your independent variable 1. Do not touch!!!!

iv2 = round(mean_iv2 + (iv2_norm * sd_iv2),0) # This creates raw values and rounds the values of your independent variable 2. Do not touch!!!!

dv = round(mean_dv + (dv_norm * sd_dv),0) # This creates raw values and round the values of your dependent variable. Do not touch!!!!

df = data.frame (participants,gender,age,iv1,iv2,dv) # This creates a data frame with all the vectors generated above. Do not touch!!!!

write.csv(df,"df.csv", row.names = FALSE) # This generates a csv file called df, and it saves it. Do not touch!!!!

iv1 # this shows you the 100 values of independent variable 1. Do not touch!!!!

iv2 # this shows you the 100 values of independent variable 2. Do not touch!!!!

dv # this shows you the 100 values of the dependent variable. Do not touch!!!!