> toluca <- read.table("F:\\sta4210\\CH01TA01.txt",header=F,col.names=c("X","Y")) Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'F:\sta4210\CH01TA01.txt': No such file or directory > > attach(toluca) > > toluca X Y 1 80 399 2 30 121 3 50 221 4 90 376 5 70 361 6 60 224 7 120 546 8 80 352 9 100 353 10 50 157 11 40 160 12 70 252 13 90 389 14 20 113 15 110 435 16 100 420 17 30 212 18 50 268 19 90 377 20 110 421 21 30 273 22 90 468 23 40 244 24 80 342 25 70 323 > > > n <- length(Y) > > mean_x <- mean(X); mean_y <- mean(Y) > var_x <- var(X); var_y <- var(Y); cov_xy <- cov(X,Y) > > SS_xx <- (n-1)*var_x > SS_xy <- (n-1)*cov_xy > SS_yy <- (n-1)*var_y > > b1 <- SS_xy/SS_xx > b0 <- mean_y - b1*mean_x > > yhat <- b0 + b1*X > e <- Y-yhat > > SSE <- sum(e^2) > MSE <- SSE/(n-2) > s <- sqrt(MSE) > > s_b1 <- s/sqrt(SS_xx) > s_b0 <- s*sqrt((1/n)+(mean_x^2/SS_xx)) > > t_b1 <- b1/s_b1 > t_b0 <- b0/s_b0 > > p_b1 <- 2*(1-pt(abs(t_b1),n-2)) > p_b0 <- 2*(1-pt(abs(t_b0),n-2)) > > lb_b1_95 <- b1 - qt(.975,n-2)*s_b1; ub_b1_95 <- b1 + qt(.975,n-2)*s_b1; > lb_b0_95 <- b0 - qt(.975,n-2)*s_b0; ub_b0_95 <- b0 + qt(.975,n-2)*s_b0; > > print(cbind(b0,s_b0,t_b0,p_b0,lb_b0_95,ub_b0_95)) b0 s_b0 t_b0 p_b0 lb_b0_95 ub_b0_95 [1,] 62.36586 26.17743 2.382428 0.02585094 8.213711 116.518 > print(cbind(b1,s_b1,t_b1,p_b1,lb_b1_95,ub_b1_95)) b1 s_b1 t_b1 p_b1 lb_b1_95 ub_b1_95 [1,] 3.570202 0.3469722 10.28959 4.448828e-10 2.852435 4.287969 > > toluca.reg1 <- lm(Y ~ X) > > summary(toluca.reg1) Call: lm(formula = Y ~ X) Residuals: Min 1Q Median 3Q Max -83.876 -34.088 -5.982 38.826 103.528 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 62.366 26.177 2.382 0.0259 * X 3.570 0.347 10.290 4.45e-10 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 48.82 on 23 degrees of freedom Multiple R-squared: 0.8215, Adjusted R-squared: 0.8138 F-statistic: 105.9 on 1 and 23 DF, p-value: 4.449e-10 > anova(toluca.reg1) Analysis of Variance Table Response: Y Df Sum Sq Mean Sq F value Pr(>F) X 1 252378 252378 105.88 4.449e-10 *** Residuals 23 54825 2384 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > > > pdf("F:\\sta4210\\KLLN_TA2_1.pdf") > plot(X,Y,xlim=c(0,125),ylim=c(0,600),main="Toluca Data - Confidence Bands and Loess") > #abline(a=b0,b=b1) > lines(lowess(X,Y)) > > Xh <- 0:125 > lines(Xh,b0+b1*Xh - sqrt(2*qf(.95,2,n-2))*s*sqrt((1/n)+((Xh-mean_x)^2/SS_xx))) > lines(Xh,b0+b1*Xh + sqrt(2*qf(.95,2,n-2))*s*sqrt((1/n)+((Xh-mean_x)^2/SS_xx))) > dev.off() null device 1 > > SSTO <- SS_yy; df_TO <- n-1 > SSR <- SSTO - SSE; df_R <- 1; MSR <- SSR/df_R > df_E <- n-2 > > F_stat <- MSR/MSE > F_05 <- qf(.95,1,n-2) > p_F <- 1-pf(F_stat,1,n-2) > > print(cbind(SSR,df_R,MSR,F_stat,F_05,p_F)) SSR df_R MSR F_stat F_05 p_F [1,] 252377.6 1 252377.6 105.8757 4.279344 4.448828e-10 > print(cbind(SSE,df_E,MSE)) SSE df_E MSE [1,] 54825.46 23 2383.716 > print(cbind(SSTO,df_TO)) SSTO df_TO [1,] 307203 24 > > >