########## # SOlutions to hw 1 ########## # 1 #### The estimate of parameters are 6.7935(intercept) and -0.4133(slope). The standard errors are 1.2365 and 0.2863 respectively. The t-values are 5.494 and -1.444 respectively. The p-values are 0.00000175 and 0.156 respectively. The covariance matrix of the parameter estimates is (Intercept) temp (Intercept) 1.5289709 -0.35317581 temp -0.3531758 0.08194334 #### # 2 #### See output #### # 3 #### The percentages are 0.9785 0.9639 0.9521 0.9492 0.9507. Note, the student's answer should be close but not exactly equal to my answer. ######## # R output ######## # 1 ##### > star <- read.table("u:\\stat526\\dataset\\ascdata\\star.txt",h=T) > star > g <- lm(light~temp,data=star) > summary(g) Call: lm(formula = light ~ temp, data = star) Residuals: Min 1Q Median 3Q Max -1.1052 -0.5067 0.1327 0.4423 0.9390 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 6.7935 1.2365 5.494 1.75e-06 *** temp -0.4133 0.2863 -1.444 0.156 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.5646 on 45 degrees of freedom Multiple R-Squared: 0.04427, Adjusted R-squared: 0.02304 F-statistic: 2.085 on 1 and 45 DF, p-value: 0.1557 > (summary(g)$sigma^2)*(summary(g)$cov.unscaled) (Intercept) temp (Intercept) 1.5289709 -0.35317581 temp -0.3531758 0.08194334 ###### # 2 ###### > A <- cbind(c(5,-2,0),c(4,3,-1),c(0,7,1)) > A [,1] [,2] [,3] [1,] 5 4 0 [2,] -2 3 7 [3,] 0 -1 1 > > b <- c(1,2,-1) > b [1] 1 2 -1 > A.inverse <- solve(A) > A.inverse [,1] [,2] [,3] [1,] 0.17241379 -0.06896552 0.4827586 [2,] 0.03448276 0.08620690 -0.6034483 [3,] 0.03448276 0.08620690 0.3965517 > A.inverse%*%b [,1] [1,] -0.4482759 [2,] 0.8103448 [3,] -0.1896552 > t(A)%*%b [,1] [1,] 1 [2,] 11 [3,] 13 > A.inverse%*%b [,1] [1,] -0.4482759 [2,] 0.8103448 [3,] -0.1896552 ####### # 3 ####### > run <- 10000 > b <- matrix(0,run,5) > > for(i in 1:run){ + + x1 <- rt(10,1) + x2 <- rt(10,2) + x3 <- rt(10,5) + x4 <- rt(10,20) + x5 <- rt(10,50) + + lower1 <- mean(x1)-qt(0.975,9)*sqrt(var(x1))/sqrt(10) + upper1 <- mean(x1)+qt(0.975,9)*sqrt(var(x1))/sqrt(10) + + lower2 <- mean(x2)-qt(0.975,9)*sqrt(var(x2))/sqrt(10) + upper2 <- mean(x2)+qt(0.975,9)*sqrt(var(x2))/sqrt(10) + + lower3 <- mean(x3)-qt(0.975,9)*sqrt(var(x3))/sqrt(10) + upper3 <- mean(x3)+qt(0.975,9)*sqrt(var(x3))/sqrt(10) + + lower4 <- mean(x4)-qt(0.975,9)*sqrt(var(x4))/sqrt(10) + upper4 <- mean(x4)+qt(0.975,9)*sqrt(var(x4))/sqrt(10) + + lower5 <- mean(x5)-qt(0.975,9)*sqrt(var(x5))/sqrt(10) + upper5 <- mean(x5)+qt(0.975,9)*sqrt(var(x5))/sqrt(10) + + + b[i,1] <- (lower1<=0)*(upper1>=0) + b[i,2] <- (lower2<=0)*(upper2>=0) + b[i,3] <- (lower3<=0)*(upper3>=0) + b[i,4] <- (lower4<=0)*(upper4>=0) + b[i,5] <- (lower5<=0)*(upper5>=0) + + } > > > > apply(b,2,mean) [1] 0.9785 0.9639 0.9521 0.9492 0.9507