A psychologist has a theory that some of the negative cognitive effects of alcohol are the result of psychological rather than physiological processes. To test this, she has 16 participants perform a cognitive test before and after drinking non-alcoholic beer which was labelled to contain 5% alcohol. Results from the study, including some demographic data, are presented in the following table. Note that higher scores on the test indicate better performance.
| participant | before drink | after drink | age | sex | eyecolor |
|---|---|---|---|---|---|
| 1 | 45 | 43 | 20 | male | blue |
| 2 | 49 | 50 | 19 | female | blue |
| 3 | 40 | 61 | 22 | male | brown |
| 4 | 48 | 44 | 20 | female | brown |
| 5 | 44 | 45 | 27 | male | blue |
| 6 | 41 | 38 | 28 | female | blue |
| 7 | 52 | 45 | male | brown | |
| 8 | 52 | 40 | 19 | female | brown |
| 9 | 56 | 41 | 26 | male | blue |
| 10 | 52 | 48 | 23 | female | blue |
Create a vector of the participant data but don’t use c(), use another vector creation function.
Create a vector of the before drink data
Create a vector of the after drink data
Create a vector of the age data. Set missing value to NA.
Create a vector of the sex data but don’t use c(), use another vector creation function.
Create a vector of the eyecolor data but don’t use c(), use another vector creation function.
Create a new vector that shows the participants’ average score across both tests. (Hint: Don’t use the mean() function! Use basic math operations).
Create a new vector that shows the change from before to after.
Create a new vector that shows people’s age in months instead of years.
It turns out that the watch used to measure time was off. All the before times are 1 second too fast, and all the after times are 1 second too slow. Correct them!
What is the length of the before vector? Use the appropriate function!
What was the mean before time? Assign the result to a scaler object with an appropriate name.
What was the mean after time? Assign the result to a scaler object with an appropriate name.
What was the mean difference in times? Assign the result to a scaler object with an appropriate name.
What was the maximum and minimum change?
What was the standard deviation of ages? Assign the result to a scaler object with an appropriate name.
How many people are there of each sex?
How many people are there with each eye color?
What percent of people have each eye color?
How many people had each age?
What percent of people had each age?
Pirates love putting their parrots into competitions. The following data represent results from two separate performance tasks given to five different parrots. In the first task, we measured how high the parrots could jump in centimeters (HIGHER scores are better). In the second task, we measured how many seconds it took for the parrots to fly around the ship 10 times (LOWER scores are better).
| parrot | jump | fly |
|---|---|---|
| Sebastiaan | 6.7 | 1085 |
| Thekla | 10.6 | 1081 |
| Sarina | 10.3 | 875 |
| Gavin | 13.7 | 725 |
| Kuebra | 8.9 | 1034 |
Assign the data to appropriately named objects.
Oops! We forgot to add the data for Seamus. Seamus jumped 11.2 centimeters and took 920 seconds to fly around the ship 10 times. Add Seamus’ data to the vectors.
Which parrot did the best in the jumping task? To answer this, just calculate the appropriate summary statistic and visually look at which parrot had this score.
Which parrot did the best in the flying task? Don’t forget that lower scores are better!
Without standardizing the variables, which parrot did the best on average across both tasks?
After standardizing the variables, which parrot did the best on average across both tasks?
What is the sum of the square root of every third integer between 1 and 578?
What will the following code return after the third line?
a <- 50
a + 100
a