Luthfiano Alzaky
2024-09-17
x1<- matrix(c(12,14,16,18,20,22),,1) x <- cbind(1,x1) y <- matrix(c(2.5,3,3.5,4.5,5,5.5),,1) xtx <- t(x)%*%x xtxinv <- solve(xtx) xty <- t(x)%*%y b <- xtxinv%*%xty b
## [,1] ## [1,] -1.3428571 ## [2,] 0.3142857
model <- lm(y~x1) confint(model,level=0.95)
## 2.5 % 97.5 % ## (Intercept) -2.185181 -0.5005329 ## x1 0.265708 0.3628634
x2<- matrix(c(100,150,200,250,300),,1) x <- cbind(1,x2) y <- matrix(c(3.2,4.1,5,5.8,6.5),,1) xtx <- t(x)%*%x xtxinv <- solve(xtx) xty <- t(x)%*%y b <- xtxinv%*%xty b
## [,1] ## [1,] 1.6000 ## [2,] 0.0166
model <- lm(y~x2) confint(model,level=0.95)
## 2.5 % 97.5 % ## (Intercept) 1.2602077 1.9397923 ## x2 0.0149982 0.0182018
x3<- matrix(c(5,10,15,20,25,30),,1) x <- cbind(1,x3) y <- matrix(c(20,25,30,35,40,45),,1) xtx <- t(x)%*%x xtxinv <- solve(xtx) xty <- t(x)%*%y b <- xtxinv%*%xty b
## [,1] ## [1,] 15 ## [2,] 1
model <- lm(y~x3) confint(model,level=0.95)
## Warning in summary.lm(object, ...): essentially perfect fit: summary may be ## unreliable
## 2.5 % 97.5 % ## (Intercept) 15 15 ## x3 1 1
x4<- matrix(c(20,25,30,35,40,45,50),,1) x <- cbind(1,x4) y <- matrix(c(1.5,2,2.5,3,3.5,4,4.5),,1) xtx <- t(x)%*%x xtxinv <- solve(xtx) xty <- t(x)%*%y b <- xtxinv%*%xty b
## [,1] ## [1,] -0.5 ## [2,] 0.1
model <- lm(y~x4) confint(model,level=0.95)
## 2.5 % 97.5 % ## (Intercept) -0.5 -0.5 ## x4 0.1 0.1
x5<- matrix(c(3:8),,1) x <- cbind(1,x5) y <- matrix(c(10,12,15,18,20,22),,1) xtx <- t(x)%*%x xtxinv <- solve(xtx) xty <- t(x)%*%y b <- xtxinv%*%xty b
## [,1] ## [1,] 2.495238 ## [2,] 2.485714
model <- lm(y~x5) confint(model,level=0.95)
## 2.5 % 97.5 % ## (Intercept) 0.8908398 4.099636 ## x5 2.2071270 2.764302
x6<- matrix(c(50,75,100,125,150,175),,1) x <- cbind(1,x6) y <- matrix(c(4.5,5,5.5,6,6.5,7),,1) xtx <- t(x)%*%x xtxinv <- solve(xtx) xty <- t(x)%*%y b <- xtxinv%*%xty b
## [,1] ## [1,] 3.50 ## [2,] 0.02
model <- lm(y~x6) confint(model,level=0.95)
## 2.5 % 97.5 % ## (Intercept) 3.50 3.50 ## x6 0.02 0.02
x7<- matrix(c(200,250,300,350,400),,1) x <- cbind(1,x7) y <- matrix(c(150,175,200,225,250),,1) xtx <- t(x)%*%x xtxinv <- solve(xtx) xty <- t(x)%*%y b <- xtxinv%*%xty b
## [,1] ## [1,] 50.0 ## [2,] 0.5
model <- lm(y~x7) confint(model,level=0.95)
## 2.5 % 97.5 % ## (Intercept) 50.0 50.0 ## x7 0.5 0.5
x8<- matrix(c(5,10,15,20,25,30),,1) x <- cbind(1,x8) y <- matrix(c(60,70,75,85,90,95),,1) xtx <- t(x)%*%x xtxinv <- solve(xtx) xty <- t(x)%*%y b <- xtxinv%*%xty b
## [,1] ## [1,] 54.66667 ## [2,] 1.40000
model <- lm(y~x8) confint(model,level=0.95)
## 2.5 % 97.5 % ## (Intercept) 49.947617 59.385716 ## x8 1.157652 1.642348
x9<- matrix(c(50,100,150,200,250),,1) x <- cbind(1,x9) y <- matrix(c(1.5,2,2.5,3,3.5),,1) xtx <- t(x)%*%x xtxinv <- solve(xtx) xty <- t(x)%*%y b <- xtxinv%*%xty b
## [,1] ## [1,] 1.00 ## [2,] 0.01
model <- lm(y~x9) confint(model,level=0.95)
## 2.5 % 97.5 % ## (Intercept) 1.00 1.00 ## x9 0.01 0.01
x10<- matrix(c(100,150,200,250,300,350),,1) x <- cbind(1,x10) y <- matrix(c(2,2.5,3,3.5,4,4.5),,1) xtx <- t(x)%*%x xtxinv <- solve(xtx) xty <- t(x)%*%y b <- xtxinv%*%xty b
model <- lm(y~x10) confint(model,level=0.95)
## 2.5 % 97.5 % ## (Intercept) 1.00 1.00 ## x10 0.01 0.01