Need Helpance with R assignment
Your task is to respond to the short answer questions listed below, using the template provided. For each question, you must also provide the R code used to arrive at your answer.
Outcomes
This assessment maps to the following course learning outcomes:
• Adapt quantitative analysis and data management skills to different software packages.
Requirements
• You must submit your assessment using the relevant portal in MyUni.
• Your assessment must be submitted as a text document (e.g., doc, docx, pdf) via the link at the top of the page.
• Prepare and submit your assessment using the template provided.
• Consult the assessment rubric when preparing your submission.
• Questions can be posted to the relevant assessment discussion board.
For this assessment, it is not mandatory to include references. However, any in-text citations included should adhere to APA 7th edition style. You must also adhere to APA 7th edition guidelines for the presentation of statistical information.
Academic Honesty
Please ensure that you have read the Academic Integrity Policy.
Grading Criteria
This assessment is worth 20% of your overall grade. Refer to the attached rubric for detailed information on the grading criteria for this assessment.
The Study and Data
The data for this assessment is a subset of the data from Brandt et al. (2021). Brandt et al.
studied the political opinions of 552 people from the United States, surveying them every two weeks over the course of a year.
The dataset for this assessment contains the following select variables from the first two waves of this study:
• id: an identifier unique to each participant.
• age: The participant’s age in years.
• gender: the participant’s gender identity. Coded as 1 = “Female”, 2 = “Male”, 3 = “Not listed”.
• votereport: who the participant voted for in the 2016 U.S. election. Coded as 1 = “Donald Trump”, 2 = “Hillary Clinton”, 3 = “A different candidate”, 4 = “I did not vote”, 5 = “I planned to vote, but I forgot”, 6 = “I do not remember who I voted for”.
• state: which state participants currently live in.
• edu: The participant’s highest level of education. Coded as 1 = “No schooling completed”, 2 = “Nursery school to 8th grade”, 3 = “Some high school, no diploma”, 4 = “High school graduate, diploma or the equivalent (for example: GED)”, 5 = “Some college credit, no degree”, 6 = “Trade/technical/vocational training”, 7 = “Associate degree”, 8 = “Bachelor’s degree”, 9 = “Master’s degree”, 10 = “Professional degree”, 11 = “Doctorate degree”.
• inc: The participant’s household income. Coded as 1 = “Less than $20,000”, 2 = “20,000 to $34,999”, 3 = “35,000 to $49,999”, 4 = “$50,000 to $74,999”, 5 = “$75,000 to $99,999”, 6 = “Over $100,000”.
• wave: which data collection wave the observation is from. Only ResponseId, Duration, interest, and def were measured across multiple waves. All other variables were measured at wave 1, and contain duplicate values for wave 2 in the dataset.
• ResponseId: a unique identifier for each observation.
• Duration: how long the participant took to complete each survey, in seconds.
• interest: how interested the participant is in politics. Ranged from 1 = “Very uninterested” to 7 = “Very interested”.
• def: Whether the participant felt federal spending on defense should be increased, decreased, or kept the same. Ranged from 1 = “Greatly decrease defense spending” to
4 = “Keep defense spending about the same” to 7 = “Greatly increase defense spending”. Other response options were 8 = “Don’t Know” and 9 = “I haven’t thought much about it”.
For the purposes of this assessment, you will perform one assumption check as instructed below. You can otherwise assume that the assumptions for all statistical tests are met.
It is not a requirement to read Brandt and colleagues’ paper to complete Assessment 1. However, it may be helpful if you want clarification on the study design or relevant theory. If you wish to view this paper, it can be accessed via the Course Readings tab.
Reference:
Brandt, M. J., Turner-Zwinkels, F. M., & Kubin, E. (2021). Political Psychology Data from a 26wave Yearlong Longitudinal Study (2019–2020). Journal of Open Psychology Data, 9(1), 2. DOI:
http://doi.org/10.5334/jopd.54
Questions
1. Describe three advantages of using R to perform data preparation and analysis for this study, compared to other software options. (3-5 sentences) [3 marks]
2. Import the PSYCHOL_6602OL_Assessment_1.csv dataset (available from MyUni) into R as a tibble. Then, convert the dataset from long to wide format. Hint: Only columns which were measured at both waves need to be specified in the relevant argument. [3 marks]
3. Complete the following steps to prepare the dataset:
a. Convert the gender and votereport variables to factors and add labels to them, using the labels from the list of variables in the assessment brief. [1 mark]
b. The Duration variables are measured in seconds. Convert these variables to be measured in minutes, rounded to two decimal places. Overwrite the existing variables in the data frame, rather than creating new variables. [1 mark]
c. Sort the data frame first by who participants voted for in the 2016 election
(votereport), then by state of residence. [1 mark]
4. Cross-tabulate votereport and gender. Include an APA-formatted frequency table. [2 marks]
5. Calculate and report the mean and standard deviation for age and interest in politics at wave 1 among Florida voters (coded as 10 in the state variable), split by gender. Include an APA-formatted table displaying this information separately for male and female participants. [4 marks]
6. Provide the code needed for a YAML header and setup chunk at the beginning of a markdown document. Include code loading the packages you used for this assessment as part of your setup chunk. Apply a global option to show the R code used for your analyses. [2 marks]
7. Calculate and report the correlation between age and interest in politics at wave 2. Include:
a. A sentence and stat block reporting the results of the main analysis. Use inline code and appropriate markdown to incorporate the output of the test directly into the sentence. (Hint: You learnt to save regression models as an object then extract only the residuals in Module 2 – you can do the same thing for cor.test(). The three elements you need to extract from cor.test() are named p.value, estimate, and parameter). (1 sentence) [4 marks]
b. A scatterplot visualising the relationship, produced using ggplot2. Include an appropriate title and axis labels. [1 marks]
c. The R code used to produce the analysis output and graph. [1 mark]
8. Conduct and report a multiple regression analysis predicting interest in politics at wave 1 from age, inc, and edu. You can treat inc and edu as continuous for this analysis. Include:
a. Sentences and a stat block reporting the results of the main analysis. (2-4 sentences) [2 marks]
b. A histogram of the regression residuals. Briefly describe whether they meet the assumption of homoscedasticity and why. (2-3 sentences) [2 marks]
c. The R code used to produce the analysis output and graph, formatted as a markdown code chunk. [1 mark]
9. Conduct and report the appropriate type of t-test comparing def scores between the first and second wave of the study. Include:
a. Sentences and a stat block reporting the results of the main analysis. Include the appropriate measure of effect size. (2 sentences) [2 marks]
b. A violin plot created using ggplot2. Overlay the data points onto this plot using jitter. Include an appropriate title and axis labels. Modify the graph by applying a theme of your choice. [2 marks]
c. The R code used to produce the analysis output and graph, formatted as a markdown code chunk. [2 marks]
10. Conduct and report a one-way ANOVA comparing def scores at wave 2 across votereport conditions. Include:
a. A sentence and stat block reporting the results of the main analysis. Include post-hoc tests and the appropriate measure of effect size. (3-5 sentences) [2 marks]
b. Facetted histograms and density plots displaying the distribution in each condition. Include an appropriate title and axis labels. Modify the graph by applying a colour scheme of your choice. [2 marks]
c. The R code used to produce the analysis output and graph, formatted as a markdown code chunk. [2 marks]
Rubric: Assessment 1: Working with R
Criteria Ratings Points
Question 1 Describe three advantages of R Points: 3.0
Name: Full points
Points: 2.0
Name: Partial points
Points: 1.0
Name: Partial points
Points: 0.0
Name: No points
3 pts
You have identified and clearly described three advantages of working in R. You have identified and described two or three advantages of working in R but lack some clarity. You have partially identified and described one or two advantages of working in R. Assessment requirements for this step have not been met.
Question 2
Import the dataset into R as a tibble. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have correctly used R code to import the dataset as a tibble. Assessment requirements for this step have not been met.
Question 2 Convert the data from long to wide format. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have used the correct function to convert the dataset from long to wide format.
Assessment requirements for this step have not been met.
Question 2
Variables for each argument within the function. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have used the correct variables for each argument when converting the dataset from long to wide format.
Assessment requirements for this step have not been met.
Question 3
Convert gender and votereport to factors and add labels, using the labels from the list of variables. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have provided the correct R code to convert gender and votereport to factors and added appropriate labels.
Assessment requirements for this step have not been met.
Question 3
Convert the Duration variables to time in minutes. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have provided the correct R code to convert Duration to time in minutes.
Assessment requirements for this step have not been met.
Question 3
Arrange the dataset by votereport then state. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have provided the correct R code to arrange the dataset by votereport then state.
Assessment requirements for this step have not been met.
Question 4 Cross-tabulate votereport and gender. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have provided the correct R code to cross-tabulate votereport and gender. Assessment requirements for this step have not been met.
Question 4 Include an APAformatted frequency table. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have provided a frequency table that is correct and adheres to the APA guidelines. Assessment requirements for this step have not been met.
Question 5
Calculate and report the mean and standard deviation for age and interest in politics at wave 1 among Florida voters, split by gender. Points: 3.0
Name: Full points
Points: 2.0
Name: Partial points
Points: 1.0
Name: Partial points
Points: 0.0
Name: No points
3 pts
You have successfully completed all of the following:
(i) included means and standard deviations for age and interest; (ii) R code to include only participants from Florida; and (iii) R code to calculate separate descriptive statistics based on gender. You have successfully completed most of the following:
(i) included means and standard deviations for age and interest; (ii) R code to include only participants from Florida; and (iii) R code to calculate separate descriptive statistics based on gender. You have partially completed some of the following: (i) included means and standard deviations for age and interest; (ii) R code to include only participants from Florida; and (iii) R code to calculate separate descriptive statistics based on gender. Assessment requirements for this step have not been met.
Question 5 Include an APAformatted frequency table displaying information separately for male and female participants. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have provided a frequency table that is correct and adheres to the APA guidelines.
Assessment requirements for this step have not been met.
Question 6 Provide the code needed for a YAML header and setup chunk at the beginning of the markdown document. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have provided the correct R code to create a YAML header and setup chunk. Assessment requirements for this step have not been met.
Question 6
Apply a global option to show the R code used for your analyses. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have successfully used the setup chunk to load the packages used and applied the correct global option. Assessment requirements for this step have not been met.
Question 7
Report the results of the main analysis. Use inline code and appropriate markdown to incorporate the output of the test directly into the sentence. Points: 4.0
Name: Full points Points: 3.0
Name: Partial points Points: 2.0
Name: Partial points Points: 1.0
Name: Partial points Points: 0.0
Name: No
points
Assessment requiremen
ts for this step have not been met. 4 pts
You have provided ALL of the following:
1. Statistical information including r, p and df is correct.
2. Inline code is used correctly to incorporate statistics directly into the sentence.
3. Markdown
formatting is applied appropriately to adhere to APA reporting guidelines.
4. The results of the analysis are described and interpreted appropriately.
You have correctly provided most of the following:
1. Statistical information including r, p and df is correct.
2. Inline code is used correctly to incorporate statistics directly into the sentence.
3. Markdown formatting is applied appropriately to adhere to APA reporting guidelines.
4. The results of the analysis are described and interpreted appropriately.
You have correctly provided some of the following:
1. Statistical information including r, p and df is correct.
2. Inline code is used correctly to incorporate statistics directly into the sentence.
3. Markdown
formatting is applied appropriately to adhere to APA reporting guidelines.
4. The results of the analysis are described and interpreted appropriately.
You have managed to provide a report in one sentence, however there are elements missing and/or incorrect.
Question 7 Provide a ggplot scatterplot visualising the relationship, including an appropriate title and axis labels. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have provided a ggplot scatterplot displaying the relationship with appropriate labels and title.
Assessment requirements for this step have not been met.
Question 7 Include the R code used to produce the analysis output and graph. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have provided the correct R code to run correlation analysis and produce the graph.
Assessment requirements for this step have not been met.
Question 8
Conduct and report a multiple regression analysis predicting interest in politics at wave 1 from age, inc, and edu. Points: 2.0
Name: Full points Points: 1.0
Name: Partial points Points: 0.0
Name: No points 2 pts
You have correctly provided:
1. statistical information including regression coefficients, pvalues and R2; and
2. the results of the analysis are described and interpreted appropriately.
The statistical information including regression coefficients, p-values and R2 are partially correct, and/or the results of the analysis are not correctly described and interpreted.
Assessment requirements for this step have not been met.
Question 8
Provide a histogram of the regression residuals. Briefly describe whether they meet the assumption of homoscedasticity and why. Points: 2.0
Name: Full points Points: 1.0
Name: Partial points Points: 0.0
Name: No points 2 pts
You have correctly provided:
1. a histogram of the regression residuals
2. a sensible justification for whether the assumption of homoscedasticity is met.
You have provided a histogram of the regression residuals with some errors, and/or your justification for whether the assumption of homoscedasticity is met is unclear.
Assessment requirements for this step have not been met.
Question 8 Include the R code used to produce the analysis output and graph, formatted as a markdown code chunk. Points: 1.0
Name: Full points Points: 0.0
Name: No points 1 pt
You have provided the correct R code to run regression analysis and produce the graph, formatted as a code chunk.
Assessment requirements for this step have not been met.
Question 9
Conduct and report the appropriate type of t-test comparing def scores between first and second wave of the study. Points: 2.0
Name: Full points Points: 1.0
Name: Partial points Points: 0.0
Name: No points 2 pts
You have correctly provided:
1. statistical information including t, p, df and d
2. the results of the analysis are described and interpreted appropriately.
The statistical information including t, p, df and d are partially correct, and/or the results of the analysis are not correctly described and interpreted.
Assessment requirements for this step have not been met.
Question 9
Provide a violin plot created using ggplot2. Overlay the data points onto this plot, using jitter. Include an appropriate title and axis labels. Modify the graph by applying the theme of your choice. Points: 2.0
Name: Full points Points: 1.0
Name: Partial points Points: 0.0
Name: No points 2 pts
You have correctly provided:
1. ggplot violin plots comparing the conditions with appropriate labels and title
2. points with jitter and a theme applied to the boxplots.
You have provided ggplot violin plots comparing the conditions with some errors, and/or you have not applied points with jitter correctly or applied a theme to the violin plots.
Assessment requirements for this step have not been met.
Question 9
Provide the R code used to produce the analysis output and graph, formatted as a markdown code chunk. Points: 2.0
Name: Full points Points: 1.0
Name: Partial points Points: 0.0
Name: No points 2 pts
You have correctly provided:
1. R code to run t-test and produce the graph, formatted as a code chunk
2. code to exclude scores of 8 or 9 on def variable.
You have provided R code to run t-test and produce the graph that is partially correct, and/or incorrectly
implemented code to exclude scores of 8 or 9 on def variable.
Assessment requirements for this step have not been met.
Question 10 Conduct and report a one-way ANOVA comparing def scores at wave 2 across votereport conditions. Points: 2.0
Name: Full points Points: 1.0
Name: Partial points Points: 0.0
Name: No points 2 pts
You have correctly provided:
1. statistical information including F, p-values, df and ?2
2. the results of the analysis and post-hoc tests are described and interpreted appropriately.
The statistical information including F, p-values, df and ?2 are partially correct, and/or the results of the analysis and post-hoc tests are not correctly described and interpreted.
Assessment requirements for this step have not been met.
Question 10 Provide facetted histograms and density plots displaying the distribution in each condition. Include an appropriate title and axis labels. Modify the graph by applying a colour scheme of your choice. Points: 2.0
Name: Full points Points: 1.0
Name: Partial points Points: 0.0
Name: No points 2 pts
You have correctly provided:
1. ggplot histograms and density plots comparing the conditions with appropriate labels and title
2. histograms and density plots correctly facetted with a colour scheme applied to the graph.
You have provided ggplot histograms and density plots comparing the conditions with some errors, and/or you have modified the graph incorrectly.
Assessment requirements for this step have not been met.
Question 10 Provide the R code used to produce the analysis output and graph, formatted as a markdown code chunk. Points: 2.0
Name: Full points Points: 1.0
Name: Partial points Points: 0.0
Name: No points 2 pts
You have correctly provided:
1. R code to run ANOVA and produce the graph, formatted as a code chunk
2. code to exclude scores of 8 or 9 on def variable.
You have provided R code to run ANOVA and produce the
graph that is partially correct,
and/or incorrectly
implemented code to exclude
scores of 8 or 9 on def variable.
Assessment requirements for this step have not been met.
Assessment total: 40 pts