Psy148a Homework


Psy148a Homework #9
your name

due by 23:50 Sunday, 8/4/2019

Note (HW#9 total points 137 points):
Make sure to update homework #9 .Rmd file name with ‘yourInitials’ replaced by your own initials.
Remember to change author ‘your name’ in this file (see line 3 above) to your own name.
This assignment is due by 11:50pm of Sunday 8/4, see course syllabus for late policy.
[4 points] You should submit four documents: (1) your R Markdown (.Rmd) file; (2) the HTML file based on your .Rmd file, (3) the ‘hw09_yourInitial.txt’ file (make sure to change ‘yourInitial’ in the file name to your own initials), and (4) the ‘BRTmeans_yourInitial.pdf’ file (make sure to change ‘yourInitial’ in the file name to your own initials).

The following chunk within the three back-ticks is called R code chunk, they are R codes and will be executed when knitting this file. Do not change the scripts in this code chunk.

Your work:
You should review all the materials in course webpage before attempting this homework assignment.

Before sumbitting this homework assignment:
Remember to comment on your R codes in details.
Remember, if you get any help, whether it’s from your colleagues or from online resources, you should acknowledge the help and/or cite the resource appropriately.

Psy148a作业代做、代做R编程设计作业、代写R程序语言作业、代写HTML file课程作业
We encourage you to talk with each other about the course work and assignment, but, again, remember to acknowldge the contribution of others or collaboration parties, if any, in your submitted work.
Also keep in mind that everything you submit to us for grading MUST be your own work.
[1 point] Acknowledge: (write any help you got for doing this assignment here or any additional refernces)

[1 point] Write R codes in the R code chunk below to do the following:
set your working directory to ‘Psy148a_Summer2019’;
use function ls() to list the contents/objects in your R workspace. The output should be ‘character(0)’. If the output is not ’character(0), use function rm(list=ls()) to remove any objects in your R workspace
###code for question 2.

[total 66 points] Write R codes in the R code chunk below to do the following:
Backgroud: Strayer, Drews, and Couch (2006) ran a study in which they compared the driving behavior of a control group (driving under a normal condition), a group that was at the legal limit for alcohol (driving while at the legal limit for alcohol, 0.08%), and a group that was driving while speaking on a cell phone. Their hypothesis, based on the research of others, was that driving while speaking on a cell phone would have as much of an effect as driving while intoxicated.
In the study, 90 participants recruited from a college (thus potential age differences were controlled) were randomly assigned into three driving conditions of 30 participants each: control group (normal condition), driving while speaking on cell phone group (cellphone), and driving while under alcohol influence (alcohol).
The dependent measure is ‘braking reaction time [BRT]’ (in mini-seconds), the time it takes the driver to apply brakes at the sight of red light signal.
It is further hypothesized that:
in the population of ‘control’ condition, the distribution of BRT: N~(μ=800,σ=100);
in the population of ‘cellphone’ condition, the distribution of BRT: N~(μ=886,σ=95);
while in the population of ‘alcohol’ condition, the distribution of BRT: N~(μ=965,σ=115).
Suppose the data in object ‘strayer’ (which is generated by the R codes below) are the sample data from Strayer et al.’s study.
[6 points] Add comments to the R codes, explain in detail what each function and each argument, respectively, does in the code. Be specific. Based upon the codes, explain how many observations/rows and how many variables that the data frame ‘strayer’ will have.
set.seed(1097)
strayer<-data.frame(condition=rep(c('normal', 'cellphone', 'alcohol'),
each=30),
BRT=c(rnorm(30, 800, 100),
rnorm(30, 886, 95),
rnorm(30, 965, 115)))

[10 points]Write R codes to generate descriptive statistics (including mean, sd, and se of the mean, with 3 digits after decimal points) of BRT by the three conditions. Save the descriptive statistics into an external file named ‘hw09_yourInitial.txt’ (make sure to change ‘yourInitial’ to your own initial).
[10 points] Using function ggplot() and geom_errorbar() to draw a graph showing the means of BRT by condition, with ±2?se error bar, and appropriate title and labels for x and y axises (a sample graph is shown below, make sure to update ‘yourInitial’ in the title with your own).

[5 points] Save this graph into an external PDF file named ‘BRTmeans_yourInitial.pdf’ (make sure to change ‘yourInitial’ to your own initial).

[5 points] Describe briefly what this graph tells about the relationship between braking reaction time (BRT) and driving condition. In particular, does this graph suggest that there is significant difference in ‘BRT’ between ‘cellphone’ condition and ‘alcohol’ condition in this sample data? Why or why not? [Now write your descriptions and answer below, right after ‘my description and answer:’]

扫描二维码关注公众号,回复: 7009204 查看本文章

my description and answer:

Research question: Is there significant difference in ‘BRT’ between ‘cellphone’ condition and ‘alcohol’ condition in the population? for this question, ignore the ‘normal’ condition in the data. To address this question, do the following:
[5 points]Specify statistical null hypothesis and alternative hypothesis; Be clear whether it is a directional or non-directional test, specify the level of significance of this test. [write your answers below, right after ‘my description and answer:’]
my answers:

[5 points] Now run a t-test to answer the research question “Is there significant difference in ‘BRT’ between ‘cellphone’ condition and ‘alcohol’ condition in the population?” [Note: we reviewed hypothesis testing and t-test last week (week 8). Make sure that you are familiar with the concepts before trying this question].
[5 points] Cite statistics to support your answer. In particular, cite the point estimate of the means difference, observed t-statistic, its degrees of freedom (df), and the corresponding p-value.
[5 points] Comment on whether you may make a mistake while drawing such a conclusion/answer to the research question and if so, which kind of mistake you may have here.
[5 points] Report the 95% confidence interval of the means difference and the effect size of Cohen’s d.
[5 points] r2 or η2 is another type of effect size (r-family effect size). It can be estiamted by using the observed t-statistic (tobs) and its degrees of freedom (df): 
. Compute and report η2 corresponding to the difference between ‘cellphone’ condition and ‘alcohol’ condition.
[Now write your answers to the above research question below, right after ‘my answer to the research question:’]
my answer to the research question:

##Codes for question 3

[total 25 points] This continues from data/analyses of question 3.
The η2 you just reported above is a sample statistic. As sample statistic, it may vary from sample to sample. Based upon the sample data from question 3, you just had a point estimate of the sample η2. If you draw another random sample with the same sample size from the corresponding population (the population of each condition is defined in question 3), most likely that the sample η2 will be different.
Design and run a simulation study to estimate the range of plausible values of sample η2 which will cover the middle 95% of the samples’ η2s[(Hint: the middle 95% of the data will be between the 2.5 percentile and 97.5 percentile, i.e. conceptually, this is to estimate the 95% CI for sample η2 through simulation). Make sure that
[5 points] you present a clear ‘analytic plan’ to lay out the steps of how to estimate the 95% CI of the η2;
[5 points]your R scripts are well-documented and show the clear steps of how to estimate the range;
[2 points] use function set.seed() so that we can replicate your study; and
[8 points] show your results both numerically and graphically.
[5 points] Does your estimated range of the plausible values of η2 include the sample η2 from question 3? Show it in your graph.

###code for question 4

[total 30 points] Write R codes to do the following.
Data CPI2012_2016.csv contain Corruption Perceptions Index (CPI) in recent several years. [5 points] Read the data directly from the website and store it as a data.frame in an object named ‘cpi’. Notice that in the data, missing value is represented by ‘N/A’.
[5 points] Using function apply() to generate the valid sample size (n), mean, sd, and cv (coefficient of variation) for cpi of each year in the data.
[5 points] Collect these descriptive statistics in an object and append the results to the end of the external file ‘hw09_yourInitial.txt’ (which you already generated earlier in question 3). That is, the file ‘hw09_yourInitial.txt’ now should include the descriptive stats for both BRT (from question 3) and cpi of years 2012 to 2016 (from question 5).
[5 points] You should make sure that appropriate title/label is present in the file so that it is easy to see which statistics are for what.
[5 points] Using function apply() to generate the valid sample size (n), mean, sd, and cv for cpi of each country in the data.
[5 points] Using ggplot to generate the following graph [hint: consider to reshape the data first]:

[5 points] export the data source you used to draw the above graph out into a data file named ‘hw09_q5_yourInitial.csv’ (the data file should be in .csv format, and remember to replace ‘youInitial’ in the file name as your own initials). This file should be in your working directory.

###code for question #5

[total 10 points]
Data: ‘happyIQ.txt’ contains information on happiness feeling (measured by the Subjective Happiniess Scale), life satisfaction (measured by the Satisfaction with Life Scale), and IQ (measured by the Standford-Binet Intelligence Scale.
in the dataset, data values are separated by ‘/’
‘happy’ is an index of happiness feeling of a person in general,
‘life’ is the measure of life satisfaction ,
‘IQ’ is an index of how ‘smart’ a person is,
‘male’ is a dummy coding index of sex, 1: male, 0: female.
[5 points] Write R codes to generate an object ‘my.descriptive’ which should content statistics as shown below (with the row names and column names as shown also):

[5 points] Write R codes to generate a scatterplot to show the relationship between ‘Happiness’ and ‘Life satisfaction’, by ‘sex’, as shown in the graph below. Comment on the relationship between ‘Happiness’ and ‘Life satisfaction’ revealed by the scatter plot. Based upon the scatterplot, is the relationship between ‘Happiness’ and ‘Life satisfaction’ the same between males and females?

###code for question #6

Click the Knit button and click Knit to HTLM

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:[email protected]

微信:codehelp

猜你喜欢

转载自www.cnblogs.com/clearc/p/11336282.html