Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- YEAR <- 1:29
- ROLL <- c( 5501, 5945, 6629 ,7556 ,8716 ,9369 ,9920,10167,11084,12504,13746, 13656, 13850,14145,14888,14991,14836,14478,14539,14395,14599,14969,15107,14831, 15081,15127,15856,15938,16081)
- UNEM <- c(8.1,7.0, 7.3, 7.5, 7.0, 6.4, 6.5,6.4,6.3,7.7,8.2,7.5,7.4,8.2, 10.1,9.2,7.7,5.7,6.5,7.5,7.3,9.2,10.1,7.5,8.8,9.1,8.8,7.8,7.0)
- datavar <- data.frame(YEAR=YEAR,ROLL=ROLL,UNEM=UNEM)
- res.lm <- lm(ROLL ~ UNEM, datavar)
- library(lattice)
- x11()
- xyplot(ROLL~UNEM, data=datavar)
- summary(res.lm)
- names(res.lm)
- x11()
- xyplot(ROLL~YEAR, data=datavar)
- cat("The TRUE value of Intercept and Slope are : ", res.lm$coefficients , "n")
- n <- nrow(datavar)
- intercept <- NULL
- slope <- NULL
- sigma <- summary(res.lm)$sigma
- set.seed(36)
- for(i in 1:1000){
- n.error <- rnorm(n,mean=0,sd=sigma)
- nROLL <- res.lm$coefficients[1] + res.lm$coefficients[2]*datavar$UNEM + n.error
- ndatavar <- data.frame(datavar,nROLL=nROLL)
- nres.lm <- lm(nROLL ~ UNEM, ndatavar)
- intercept[i] <- nres.lm$coefficients[1]
- slope[i] <- nres.lm$coefficients[2]
- }
- par(mfrow=c(1,2))
- hist(intercept,freq=FALSE)
- abline(v=res.lm$coefficients[1],col=2)
- hist(intercept,freq=FALSE)
- abline(v=res.lm$coefficients[2],col=2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement