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.
If datarium is not installed, install it once from the Console.
At the top of the assignment script:
psych.tidyverse.datarium.jobsatisfaction dataset from datarium to an object named df.The dataset should contain id, gender, education_level, and score.
Review package installation and loading
Review the jobsatisfaction setup
Use psych::describe() to calculate summary statistics for score.
Record the mean and standard deviation in a comment beneath the code that produced them.
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.
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
Calculate the score descriptives for every combination of gender and education_level.
Supply both grouping variables inside list(), and use mat = TRUE.
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.
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
Create a data frame named male_unsatisfied containing participants who meet all three requirements:
gender is "male";score is below 5; andeducation_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.
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.
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:
am as the input;0 and 1, in that order; and"automatic" and "manual".Use table() to check the completed factor.
Review factors with numeric codes and labels
Create a data frame named manual_over_18 that contains cars with:
am_factor equal to "manual"; andmpg greater than 18.Both requirements must be true.
Review multiple filtering requirements
Calculate:
hp of the cars in manual_over_18; andhp of all cars in cars.Write a comment stating which mean is greater.
Review selecting a column for a calculation
Save the script and compare results with another group member.
Be ready to show:
levels and labels;