Week 2
Group work

PSYC 70510 · Statistical Methods in Psych Lab I · Section 53950
Lab Instructor: Kaile Smith

Work through the tasks in order with your group. Write and run the code in the supplied StatsLab_Week2_GroupWork.R script. Keep the Week 2 lesson open in another tab so you can return to the worked examples.

1 Prepare the packages and data

If datarium is not installed, install it once from the Console.

At the top of the assignment script:

  1. Load psych.
  2. Load tidyverse.
  3. Load datarium.
  4. Assign the jobsatisfaction dataset from datarium to an object named df.
  5. Inspect the column names and structure.

The dataset should contain id, gender, education_level, and score.

Review package installation and loading

Review the jobsatisfaction setup

2 Describe the satisfaction scores

Use psych::describe() to calculate summary statistics for score.

Record the mean and standard deviation in a comment beneath the code that produced them.

Review describe()

3 Describe scores by gender

Use psych::describeBy() to calculate the score descriptives separately for each level of gender.

Use mat = TRUE so the result prints as one rectangular table.

Review one grouping variable

4 Describe scores by education level

Use psych::describeBy() again. This time, calculate the score descriptives separately for each level of education_level.

Check the exact variable name before running the code. It contains an underscore.

Review the jobsatisfaction variable names

5 Challenge: describe scores by two groups

Calculate the score descriptives for every combination of gender and education_level.

Supply both grouping variables inside list(), and use mat = TRUE.

Review two grouping variables

6 Filter for university education

Create a data frame named university_df that contains only participants whose education_level is "university".

Print the new object and check its number of rows.

Review equality filtering

7 Filter for scores of 6 or higher

Create a data frame named score_6_or_more that contains participants with a job-satisfaction score greater than or equal to 6.

Print the range of score in the filtered data to check that the condition worked.

Review the comparison operators

8 Combine three filtering requirements

Create a data frame named male_unsatisfied containing participants who meet all three requirements:

  1. gender is "male";
  2. score is below 5; and
  3. education_level is either "college" or "school".

Use commas or & for the requirements that must all be true. Use %in% for the two accepted education levels.

Review multiple conditions

Review %in%

9 Describe the filtered group

Check how many rows remain in male_unsatisfied. Remove its unused factor levels with droplevels(), then use psych::describeBy() to describe score by education_level.

This filter produces a very small group. In a comment, note the remaining sample size and whether a standard deviation can be calculated.

Review unused factor levels

10 Create a transmission factor

Assign the built-in mtcars data to an object named cars.

The am column uses 0 for automatic and 1 for manual transmission. Create a new column named am_factor:

Use table() to check the completed factor.

Review factors with numeric codes and labels

11 Filter the manual cars

Create a data frame named manual_over_18 that contains cars with:

  1. am_factor equal to "manual"; and
  2. mpg greater than 18.

Both requirements must be true.

Review multiple filtering requirements

12 Compare average horsepower

Calculate:

  1. the mean hp of the cars in manual_over_18; and
  2. the mean hp of all cars in cars.

Write a comment stating which mean is greater.

Review selecting a column for a calculation

13 Before you finish

Save the script and compare results with another group member.

Be ready to show:

Return to the Week 2 lesson