Question: The following R code is for a simulation study. You are asked to explain what is illustrated. What can you learn from it in terms

 

The following R code is for a simulation study. You are asked to explain what is illustrated. What can you learn from it in terms of good or bad statistical practice?

Some information that may help you:

t he error term of the linear regression model is based on a t - distribution with  3  degrees of freedom, which has mean zero and variance  3  and which has heavy tails  ( i . e .  simulations from this t - distribution show more outliers as compared to a normal distribution).

the I QR is the inter - quartile range, which is the difference between the third and the first quartile

set.seed(156918)

beta.hat.complete<-c()

var.beta.hat.complete<-c()

beta.hat.reduced<-c()

var.beta.hat.reduced<-c()

x<-1:200

db<-data.frame(x=x,y=NA)

for(i in 1:10000) {

db$y<-10+.3*x+7*rt(200, df=3)

m.complete<-lm(y~x,data=db)

e<-residuals(m.complete)

iqr<-IQR(e)

keep<-abs(e)<2.5*iqr

m.reduced<-lm(y~x, data=db, subset=(keep))

beta.hat.complete<-c(beta.hat.complete,coef(m.complete)[2])

var.beta.hat.complete<-c(var.beta.hat.complete,summary(m.complete)$coef[2,2]^2)

beta.hat.reduced<-c(beta.hat.reduced,coef(m.reduced)[2])

var.beta.hat.reduced<-c(var.beta.hat.reduced,summary(m.reduced)$coef[2,2]^2)

}

mean(beta.hat.complete)

## [1] 0.2997359

mean(var.beta.hat.complete)

## [1] 0.0002163193

10

mean(beta.hat.reduced)

## [1] 0.2998977

mean(var.beta.hat.reduced)

## [1] 0.000115903

X<-lm(y~x,data=db,x=T)$x

solve(t(X)%*%X)*49*3

## (Intercept) x

## (Intercept) 2.9621608 -0.0221608040

## x -0.0221608 0.0002205055

 
 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Network Questions!