ST512 Lab 2

# ST512 Lab 2 - ST512 Assignment 2 Due Date September 14...

This preview shows pages 1–3. Sign up to view the full content.

Page 1 of 9 ST512 Assignment 2 Due Date: September 14. Assignment Goal: Use R to conduct a computer experiment that investigates the consequences of violating an SLR assumption. We spend lots of time in statistics class emphasizing the assumptions on which different statistical methods are based. We spend less time thinking about how violations of those assumptions affect the behavior of the method. In this lab, you will conduct a computer experiment to investigate how statistical inference about the estimated slope in a SLR model is affected by a violation of the equal variance assumption. Computer experiments like the one that you will conduct here usually require enough fluency in a computer language to write a small program. The statistical software package R is particularly well suited to writing small programs. (This is one of the major selling points of R.) Because you are not expected to have this fluency with R right away, for now the programs will be provided for you. If you are interested in using R for your own research, study these programs to see how they work. First, let's work through some of the commands that you'll need to conduct the computer experiment. We are going to suppose that we are studying some relationship between a predictor x and response y where there is no linear relationship between predictor and response. That is to say, the true model is 0 0 y x β ε = + × + or more simply 0 y β ε = + To be concrete, let's assume that the intercept β o =1. For the time being, let's assume that the standard regression assumptions hold, and the errors are independent and identically distributed random variables with mean 0 and variance 2 1 ε σ = . Now let's construct a simulated data set from this model and fit a SLR to it. First, we need values of the predictor. Let's suppose that our data set will consist of 20 data points. To make life easy on ourselves, we'll generate values of the predictor by using one of R's built-in functions. Let's distribute our values of the predictor evenly between a minimum value x =0 and maximum value x =1. If you haven't done so already, launch R and type in the following command: > x.values <- seq(from=0,to=1,length=20) Now, let's generate values for the errors by randomly sampling from a normal distribution with mean 0 and variance 1:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Page 2 of 9 > errors <- rnorm(n=20,mean=0,sd=1) (Note that the 'rnorm' function is parameterized in terms of the [s]tandard [d]eviation, not the variance. However, when the variance = 1, the standard deviation is = 1 also.) Finally, let's create values for the response by adding the errors to the intercept of 1: > y.values = 1 + errors (Note that this has the same effect as > y.values = 1 + 0 * x.values + errors ).
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern