###################################
# PSYC 70510 - Statistical Methods in Psych Lab I
# Week 2 - Group work
# Lab Instructor: Kaile Smith
#
# Name(s):
# Date:
###################################


# Work through the questions in order.
# Keep the Week 2 lesson open so you can return to the worked examples.
# Write your code beneath each question, then run it from this script.


### 1. Prepare the packages and data

# If datarium is not installed, install it once from the Console.
# Do not include install.packages() in the submitted script.

# Load psych, tidyverse, and datarium with library().




# Assign datarium's jobsatisfaction dataset to an object named df.




# Print the column names and inspect the structure of df.




### 2. Describe the satisfaction scores

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




# Record the mean and standard deviation in a comment:
# Mean:
# Standard deviation:


### 3. Describe scores by gender

# Use psych::describeBy() to describe score separately by gender.
# Include mat = TRUE.




### 4. Describe scores by education level

# Use psych::describeBy() to describe score separately by education_level.
# Include mat = TRUE.




### 5. Challenge: describe scores by two groups

# Use psych::describeBy() to describe score for every combination of
# gender and education_level.
# Supply both grouping variables inside list().
# Include mat = TRUE.




### 6. Filter for university education

# Create an object named university_df containing only participants whose
# education_level is "university".
# Print university_df and check its number of rows.




### 7. Filter for scores of 6 or higher

# Create an object named score_6_or_more containing participants whose
# score is greater than or equal to 6.
# Print the range of score in the filtered data.




### 8. Combine three filtering requirements

# Create an object named male_unsatisfied containing participants who:
#   - are male,
#   - have a score below 5, and
#   - have either a college or school education.
# Use %in% for the two accepted education levels.




### 9. Describe the filtered group

# Check the number of rows in male_unsatisfied.
# Use droplevels() to remove unused factor levels.
# Use psych::describeBy() to describe score by education_level.




# In a comment, record:
# Remaining sample size:
# Can a standard deviation be calculated? Why or why not?


### 10. Create a transmission factor

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




# Create cars$am_factor from cars$am.
# Use levels 0 and 1, in that order.
# Use the labels "automatic" and "manual".
# Check the new factor with table().




### 11. Filter the manual cars

# Create an object named manual_over_18 containing cars that:
#   - have am_factor equal to "manual", and
#   - have mpg greater than 18.




### 12. Compare average horsepower

# Calculate the mean hp of the cars in manual_over_18.




# Calculate the mean hp of all cars in cars.




# State which mean is greater:


### Before you finish

# Save this script.
# Compare your results with another group member.
# Keep any code that produced an error so we can discuss what happened.
