R version 4.2.3 (2023-03-15 ucrt) -- "Shortstop Beagle" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > x <- rnorm(30) > y <- 2*x + 2 + rnorm(30) > plot(x,y) > reg1 <- lm(y ~ x) > reg1 Call: lm(formula = y ~ x) Coefficients: (Intercept) x 2.186 1.942 > reg1$coef (Intercept) x 2.186230 1.942455 > plot(x,y) > abline(reg1$coef) > reg1$fitted 1 2 3 4 4.987609604 2.383225814 1.379510989 2.239219222 5 6 7 8 0.355967141 -0.149095495 2.226568336 0.912464173 9 10 11 12 2.776026092 2.595265846 1.440255578 1.711169443 13 14 15 16 1.775584263 3.805795867 5.281148794 -0.757477689 17 18 19 20 3.615879316 2.268084760 2.517131893 3.990917735 21 22 23 24 3.975109529 2.656381054 4.530169950 2.858917955 25 26 27 28 3.055818103 -0.004905427 4.441757325 2.966845300 29 30 4.500214285 -1.123420590 > fitted(reg1) 1 2 3 4 4.987609604 2.383225814 1.379510989 2.239219222 5 6 7 8 0.355967141 -0.149095495 2.226568336 0.912464173 9 10 11 12 2.776026092 2.595265846 1.440255578 1.711169443 13 14 15 16 1.775584263 3.805795867 5.281148794 -0.757477689 17 18 19 20 3.615879316 2.268084760 2.517131893 3.990917735 21 22 23 24 3.975109529 2.656381054 4.530169950 2.858917955 25 26 27 28 3.055818103 -0.004905427 4.441757325 2.966845300 29 30 4.500214285 -1.123420590 > points(x,reg1$fitted,pch=1) > y - reg1$fitted == rg1$resid Error: object 'rg1' not found > y - reg1$fitted == reg1$resid 1 2 3 4 5 6 7 8 9 10 FALSE TRUE FALSE FALSE TRUE TRUE FALSE TRUE FALSE FALSE 11 12 13 14 15 16 17 18 19 20 TRUE TRUE FALSE TRUE FALSE TRUE TRUE FALSE FALSE FALSE 21 22 23 24 25 26 27 28 29 30 FALSE FALSE FALSE TRUE FALSE TRUE FALSE FALSE FALSE FALSE > y - reg1$fitted 1 2 3 4 5 -0.39035014 -0.40611607 -0.69720104 -1.84859114 0.54155350 6 7 8 9 10 0.90040618 -0.92206680 -0.32254533 -0.29498295 1.54490541 11 12 13 14 15 1.22771154 -1.21102668 0.32810150 -1.13557996 1.32537079 16 17 18 19 20 0.19080439 1.02654137 1.25032092 0.78931169 -0.04125182 21 22 23 24 25 -0.96360838 -0.65702578 1.13604615 -0.82861150 0.34430106 26 27 28 29 30 -0.62684520 0.69621253 -0.54651390 -0.75663606 0.34736573 > reg1$fitted + reg1$resid - y 1 2 3 4 0.000000e+00 0.000000e+00 -1.110223e-16 2.220446e-16 5 6 7 8 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 9 10 11 12 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 13 14 15 16 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 17 18 19 20 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 21 22 23 24 0.000000e+00 2.220446e-16 0.000000e+00 0.000000e+00 25 26 27 28 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 29 30 0.000000e+00 1.110223e-16 > plot(x,reg1$resid) > plot(reg1$fitted,reg1$resid) > plot(reg1) Waiting to confirm page change... Waiting to confirm page change... Waiting to confirm page change... Waiting to confirm page change... > x <- rnorm(30) > z <- x^2 + rnorm(30) > reg1 <- lm(z ~ x) > reg1 Call: lm(formula = z ~ x) Coefficients: (Intercept) x 0.6939 1.4011 > plot(x,z) > abline(reg1$coef) > x <- 2*rnorm(30) > z <- x^2 + rnorm(30) > reg1 <- lm(z ~ x) > plot(x,z) > abline(reg1$coef) > plot(x,reg1$resid) > plot(reg1$fitted,reg1$resid) > reg2 <- lm(z ~ x + I(x^2)) > reg2 Call: lm(formula = z ~ x + I(x^2)) Coefficients: (Intercept) x 0.2656 -0.1168 I(x^2) 0.9261 > reg2 Call: lm(formula = z ~ x + I(x^2)) Coefficients: (Intercept) x I(x^2) 0.2656 -0.1168 0.9261 > reg2$coef (Intercept) x I(x^2) 0.2655843 -0.1167795 0.9260564 > plot(x,reg2$fitted) > plot(x,reg2$fitted,type="l") > order(x) [1] 7 21 24 16 26 3 5 23 14 28 17 11 29 19 8 9 20 2 1 12 [21] 18 30 10 13 22 6 4 25 27 15 > x[order(x)] [1] -3.527432387 -2.838976036 -2.715293252 -2.558518246 [5] -2.436570716 -2.427374546 -2.358593811 -1.743837307 [9] -1.370632691 -0.807107359 -0.642812489 -0.635836205 [13] -0.537378645 -0.526647148 -0.457851848 -0.261885046 [17] -0.059334835 -0.002440419 0.293105233 0.303106293 [21] 0.433199078 0.540062129 0.735753474 0.826144904 [25] 1.176569617 1.938999389 2.128136090 2.314781411 [29] 2.372044724 2.768072444 > sort(x) [1] -3.527432387 -2.838976036 -2.715293252 -2.558518246 [5] -2.436570716 -2.427374546 -2.358593811 -1.743837307 [9] -1.370632691 -0.807107359 -0.642812489 -0.635836205 [13] -0.537378645 -0.526647148 -0.457851848 -0.261885046 [17] -0.059334835 -0.002440419 0.293105233 0.303106293 [21] 0.433199078 0.540062129 0.735753474 0.826144904 [25] 1.176569617 1.938999389 2.128136090 2.314781411 [29] 2.372044724 2.768072444 > plot(x,z) > points(x[order(x)],z[order(x)],pch=2,col=2) > lines(x[order(x)],reg2$fitted[order(x)]) > plot(x,z) > lines(x[order(x)],reg2$fitted[order(x)]) > plot(x,reg2$resid) > plot(reg2$fitted,reg2$resid) > plot(x,reg2$resid) > reg2$summary NULL > summary(reg2) Call: lm(formula = z ~ x + I(x^2)) Residuals: Min 1Q Median 3Q Max -2.3235 -0.7028 0.2194 0.5579 2.1969 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.26558 0.26161 1.015 0.319 x -0.11678 0.12167 -0.960 0.346 I(x^2) 0.92606 0.06276 14.754 1.92e-14 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 1.057 on 27 degrees of freedom Multiple R-squared: 0.906, Adjusted R-squared: 0.899 F-statistic: 130 on 2 and 27 DF, p-value: 1.381e-14 > reg3 <- lm(z ~ I(x^2)) > reg3 Call: lm(formula = z ~ I(x^2)) Coefficients: (Intercept) I(x^2) 0.2423 0.9471 > reg4 <- lm(z ~ 0 + I(x^2)) > reg4 Call: lm(formula = z ~ 0 + I(x^2)) Coefficients: I(x^2) 0.9838 > plot(x,z) > lines(x[order(x)],fitted(reg4)[order(x)]) > plot(x,reg4$resid) > summary(reg4) Call: lm(formula = z ~ 0 + I(x^2)) Residuals: Min 1Q Median 3Q Max -2.0512 -0.5665 0.2870 0.7493 2.4218 Coefficients: Estimate Std. Error t value Pr(>|t|) I(x^2) 0.98383 0.04341 22.66 <2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 1.053 on 29 degrees of freedom Multiple R-squared: 0.9466, Adjusted R-squared: 0.9447 F-statistic: 513.6 on 1 and 29 DF, p-value: < 2.2e-16 > v <- rnorm(30) > reg5 <- lm(v ~ x) > reg5 Call: lm(formula = v ~ x) Coefficients: (Intercept) x 0.2648 0.1137 > plot(x,v) > abline(reg5$coef) > summary(reg5) Call: lm(formula = v ~ x) Residuals: Min 1Q Median 3Q Max -1.1773 -0.4707 -0.1473 0.4917 1.6687 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.26478 0.12603 2.101 0.0448 * x 0.11372 0.07307 1.556 0.1309 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.6771 on 28 degrees of freedom Multiple R-squared: 0.07962, Adjusted R-squared: 0.04675 F-statistic: 2.422 on 1 and 28 DF, p-value: 0.1309 > reg1 Call: lm(formula = z ~ x) Coefficients: (Intercept) x 2.8104 -0.7425 > reg2 Call: lm(formula = z ~ x + I(x^2)) Coefficients: (Intercept) x I(x^2) 0.2656 -0.1168 0.9261 > reg3 Call: lm(formula = z ~ I(x^2)) Coefficients: (Intercept) I(x^2) 0.2423 0.9471 > anova(reg1,reg2) Analysis of Variance Table Model 1: z ~ x Model 2: z ~ x + I(x^2) Res.Df RSS Df Sum of Sq F Pr(>F) 1 28 273.24 2 27 30.15 1 243.09 217.69 1.918e-14 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > reg4 Call: lm(formula = z ~ 0 + I(x^2)) Coefficients: I(x^2) 0.9838 > anova(reg2,reg4) Analysis of Variance Table Model 1: z ~ x + I(x^2) Model 2: z ~ 0 + I(x^2) Res.Df RSS Df Sum of Sq F Pr(>F) 1 27 30.150 2 29 32.145 -2 -1.9953 0.8934 0.421 > x <- rnorm(30) > y <- rnorm(30) > z <- 2*x - y + rnorm(30) > reg6 <- lm(z ~ x + y) > reg6 Call: lm(formula = z ~ x + y) Coefficients: (Intercept) x y 0.2536 2.0401 -0.8269 > reg6$fitted - z 1 2 3 4 5 0.92295479 1.27350251 2.81617967 -1.31760580 -0.95056387 6 7 8 9 10 -0.38864247 -0.74330608 -0.69441244 -1.40199374 0.03386435 11 12 13 14 15 0.62315166 -0.27920881 0.61279856 0.98832704 -1.87988930 16 17 18 19 20 0.12899533 -1.57318673 0.66521575 -1.30316731 1.36797107 21 22 23 24 25 -0.20360115 1.23907695 2.66615982 -0.92012639 -0.30141095 26 27 28 29 30 0.35899827 0.76111817 -0.90550087 -0.77960422 -0.81609382 > reg6$fitted 1 2 3 4 5 3.0070427 2.2383219 2.1858588 -2.0996815 -0.6390028 6 7 8 9 10 -1.5116332 0.6993741 1.6593800 -1.3578555 2.9123074 11 12 13 14 15 0.8163772 -2.5218188 2.5371062 -0.3136820 1.7973409 16 17 18 19 20 -1.0368689 4.0586213 0.4124129 0.2708563 0.5928931 21 22 23 24 25 1.4534547 0.6070951 -3.5098347 -0.4060879 3.8229252 26 27 28 29 30 2.4866089 0.5624110 4.0387344 -1.2530606 -2.0509626 > plot(reg6$fitted,z) > summary(reg6) Call: lm(formula = z ~ x + y) Residuals: Min 1Q Median 3Q Max -2.8162 -0.7371 0.2414 0.8831 1.8799 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.2536 0.2307 1.099 0.28131 x 2.0401 0.2658 7.674 2.97e-08 *** y -0.8269 0.2581 -3.204 0.00346 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 1.224 on 27 degrees of freedom Multiple R-squared: 0.7477, Adjusted R-squared: 0.7291 F-statistic: 40.02 on 2 and 27 DF, p-value: 8.414e-09 > adat <- read.table("adat3.txt",header=TRUE) > adat x y 1 0.00 2.10481941 2 0.05 1.97589012 3 0.10 1.67085237 4 0.15 2.40052955 5 0.20 2.61318158 6 0.25 1.78062133 7 0.30 2.04470006 8 0.35 2.44629402 9 0.40 2.02794944 10 0.45 1.40355147 11 0.50 1.10228174 12 0.55 2.92513672 13 0.60 2.13743137 14 0.65 2.90880586 15 0.70 1.58513650 16 0.75 1.16521291 17 0.80 2.78908969 18 0.85 2.74945424 19 0.90 1.92958087 20 0.95 1.96473149 21 1.00 1.60235815 22 1.05 2.13097306 23 1.10 2.34591959 24 1.15 1.56583532 25 1.20 1.20613778 26 1.25 2.13088653 27 1.30 2.03765433 28 1.35 1.48375760 29 1.40 1.68069427 30 1.45 0.69063542 31 1.50 0.86230343 32 1.55 1.03945360 33 1.60 -0.32198786 34 1.65 1.23873603 35 1.70 0.44096582 36 1.75 0.65232045 37 1.80 1.12994659 38 1.85 0.59827830 39 1.90 0.11218280 40 1.95 -0.10409246 41 2.00 0.70950965 42 2.05 0.53191355 43 2.10 -0.17935811 44 2.15 -0.11684341 45 2.20 -0.71423656 46 2.25 -0.38632049 47 2.30 -0.13082616 48 2.35 -0.91663374 49 2.40 -0.67204731 50 2.45 -0.89209219 51 2.50 -0.64327006 52 2.55 -2.25036730 53 2.60 -1.05526382 54 2.65 -1.53544400 55 2.70 -1.53056122 56 2.75 -0.60210586 57 2.80 -2.15289854 58 2.85 -1.22618254 59 2.90 -1.53309577 60 2.95 -1.55621086 61 3.00 -1.97173977 62 3.05 -1.22243596 63 3.10 -2.33713426 64 3.15 -1.65481583 65 3.20 -1.73478380 66 3.25 -1.87737161 67 3.30 -2.68380756 68 3.35 -2.18778981 69 3.40 -2.55393392 70 3.45 -1.45459200 71 3.50 -1.65860454 72 3.55 -2.14561216 73 3.60 -1.45292898 74 3.65 -1.70463595 75 3.70 -1.83326237 76 3.75 -2.38507286 77 3.80 -2.50834664 78 3.85 -2.56977557 79 3.90 -1.89238661 80 3.95 -2.24771418 81 4.00 -2.88219928 82 4.05 -2.36035045 83 4.10 -1.23362051 84 4.15 -2.15480214 85 4.20 -1.37007243 86 4.25 -1.27866627 87 4.30 -1.23972214 88 4.35 -1.00405156 89 4.40 -1.34725321 90 4.45 -1.24950466 91 4.50 -1.10607728 92 4.55 -1.38465205 93 4.60 -1.09670935 94 4.65 -0.35910830 95 4.70 -1.16437931 96 4.75 -1.46500411 97 4.80 -0.71182219 98 4.85 -0.14084280 99 4.90 0.06576587 100 4.95 -0.29390735 101 5.00 -0.33868124 102 5.05 0.55678014 103 5.10 -0.35207331 104 5.15 0.44829367 105 5.20 -0.40141550 106 5.25 -0.09698595 107 5.30 0.58197683 108 5.35 -0.02873023 109 5.40 -0.14810556 110 5.45 1.12979177 111 5.50 1.41379107 112 5.55 0.68178178 113 5.60 1.27183904 114 5.65 0.86861741 115 5.70 0.83498778 116 5.75 0.86123599 117 5.80 0.88113660 118 5.85 0.82143737 119 5.90 0.72897083 120 5.95 2.11660251 121 6.00 2.14863085 122 6.05 1.40638245 123 6.10 1.78119176 124 6.15 0.91602722 125 6.20 2.32407751 126 6.25 1.33191918 127 6.30 2.29154698 128 6.35 2.51594793 129 6.40 1.12755423 130 6.45 1.46726008 131 6.50 1.48120498 132 6.55 0.86985214 133 6.60 1.60204442 134 6.65 2.39793810 135 6.70 1.99399950 136 6.75 1.78914793 137 6.80 1.87695573 138 6.85 2.18177561 139 6.90 2.12908130 140 6.95 2.09528541 141 7.00 2.86739790 142 7.05 2.06278799 143 7.10 2.93440466 144 7.15 1.87098098 145 7.20 1.49410695 146 7.25 2.36911854 147 7.30 0.77799327 148 7.35 2.22967633 149 7.40 1.31247142 150 7.45 1.58789569 151 7.50 1.99368546 152 7.55 0.81208845 153 7.60 0.69175138 154 7.65 1.28849244 155 7.70 0.75862448 156 7.75 0.77127485 157 7.80 1.09585969 158 7.85 1.22080977 159 7.90 0.48199281 160 7.95 0.74894282 161 8.00 2.02066715 162 8.05 0.67028696 163 8.10 0.93636568 164 8.15 0.18564857 165 8.20 -1.17163394 166 8.25 1.21684162 167 8.30 1.02778371 168 8.35 -0.56091567 169 8.40 0.41845865 170 8.45 -0.36292743 171 8.50 0.41707656 172 8.55 -1.00166194 173 8.60 -0.22107589 174 8.65 -0.84212165 175 8.70 -0.49249851 176 8.75 -1.43064220 177 8.80 -1.22057689 178 8.85 -0.85769081 179 8.90 -0.55302840 180 8.95 -0.76775279 181 9.00 -1.40293450 182 9.05 -0.34833875 183 9.10 -1.97872918 184 9.15 -1.53638978 185 9.20 -1.52980247 186 9.25 -2.48373429 187 9.30 -1.71354429 188 9.35 -1.93102893 189 9.40 -1.41679351 190 9.45 -1.74341184 191 9.50 -1.43915700 192 9.55 -2.17682306 193 9.60 -1.48928546 194 9.65 -2.49827686 195 9.70 -1.54829993 196 9.75 -2.34788027 197 9.80 -1.90532868 198 9.85 -1.57661919 199 9.90 -2.35970092 200 9.95 -1.69938363 201 10.00 -2.45040120 > head(adat) x y 1 0.00 2.104819 2 0.05 1.975890 3 0.10 1.670852 4 0.15 2.400530 5 0.20 2.613182 6 0.25 1.780621 > adat <- read.table("adat3.txt",header=TRUE) > head(adat) x y 1 0.00 2.104819 2 0.05 1.975890 3 0.10 1.670852 4 0.15 2.400530 5 0.20 2.613182 6 0.25 1.780621 > ls() [1] "adat" "reg1" "reg2" "reg3" "reg4" "reg5" "reg6" "v" [9] "x" "y" "z" > rm(x,y,z,v) > attach(adat) > adat$x [1] 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 [10] 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 [19] 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 [28] 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 [37] 1.80 1.85 1.90 1.95 2.00 2.05 2.10 2.15 2.20 [46] 2.25 2.30 2.35 2.40 2.45 2.50 2.55 2.60 2.65 [55] 2.70 2.75 2.80 2.85 2.90 2.95 3.00 3.05 3.10 [64] 3.15 3.20 3.25 3.30 3.35 3.40 3.45 3.50 3.55 [73] 3.60 3.65 3.70 3.75 3.80 3.85 3.90 3.95 4.00 [82] 4.05 4.10 4.15 4.20 4.25 4.30 4.35 4.40 4.45 [91] 4.50 4.55 4.60 4.65 4.70 4.75 4.80 4.85 4.90 [100] 4.95 5.00 5.05 5.10 5.15 5.20 5.25 5.30 5.35 [109] 5.40 5.45 5.50 5.55 5.60 5.65 5.70 5.75 5.80 [118] 5.85 5.90 5.95 6.00 6.05 6.10 6.15 6.20 6.25 [127] 6.30 6.35 6.40 6.45 6.50 6.55 6.60 6.65 6.70 [136] 6.75 6.80 6.85 6.90 6.95 7.00 7.05 7.10 7.15 [145] 7.20 7.25 7.30 7.35 7.40 7.45 7.50 7.55 7.60 [154] 7.65 7.70 7.75 7.80 7.85 7.90 7.95 8.00 8.05 [163] 8.10 8.15 8.20 8.25 8.30 8.35 8.40 8.45 8.50 [172] 8.55 8.60 8.65 8.70 8.75 8.80 8.85 8.90 8.95 [181] 9.00 9.05 9.10 9.15 9.20 9.25 9.30 9.35 9.40 [190] 9.45 9.50 9.55 9.60 9.65 9.70 9.75 9.80 9.85 [199] 9.90 9.95 10.00 > x [1] 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 [10] 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 [19] 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 [28] 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 [37] 1.80 1.85 1.90 1.95 2.00 2.05 2.10 2.15 2.20 [46] 2.25 2.30 2.35 2.40 2.45 2.50 2.55 2.60 2.65 [55] 2.70 2.75 2.80 2.85 2.90 2.95 3.00 3.05 3.10 [64] 3.15 3.20 3.25 3.30 3.35 3.40 3.45 3.50 3.55 [73] 3.60 3.65 3.70 3.75 3.80 3.85 3.90 3.95 4.00 [82] 4.05 4.10 4.15 4.20 4.25 4.30 4.35 4.40 4.45 [91] 4.50 4.55 4.60 4.65 4.70 4.75 4.80 4.85 4.90 [100] 4.95 5.00 5.05 5.10 5.15 5.20 5.25 5.30 5.35 [109] 5.40 5.45 5.50 5.55 5.60 5.65 5.70 5.75 5.80 [118] 5.85 5.90 5.95 6.00 6.05 6.10 6.15 6.20 6.25 [127] 6.30 6.35 6.40 6.45 6.50 6.55 6.60 6.65 6.70 [136] 6.75 6.80 6.85 6.90 6.95 7.00 7.05 7.10 7.15 [145] 7.20 7.25 7.30 7.35 7.40 7.45 7.50 7.55 7.60 [154] 7.65 7.70 7.75 7.80 7.85 7.90 7.95 8.00 8.05 [163] 8.10 8.15 8.20 8.25 8.30 8.35 8.40 8.45 8.50 [172] 8.55 8.60 8.65 8.70 8.75 8.80 8.85 8.90 8.95 [181] 9.00 9.05 9.10 9.15 9.20 9.25 9.30 9.35 9.40 [190] 9.45 9.50 9.55 9.60 9.65 9.70 9.75 9.80 9.85 [199] 9.90 9.95 10.00 > ls() [1] "adat" "reg1" "reg2" "reg3" "reg4" "reg5" "reg6" > rm(reg1,reg2,reg3,reg4,reg5,reg6) > ls)( Error: unexpected ')' in "ls)" > ls() [1] "adat" > x [1] 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 [10] 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 [19] 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 [28] 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 [37] 1.80 1.85 1.90 1.95 2.00 2.05 2.10 2.15 2.20 [46] 2.25 2.30 2.35 2.40 2.45 2.50 2.55 2.60 2.65 [55] 2.70 2.75 2.80 2.85 2.90 2.95 3.00 3.05 3.10 [64] 3.15 3.20 3.25 3.30 3.35 3.40 3.45 3.50 3.55 [73] 3.60 3.65 3.70 3.75 3.80 3.85 3.90 3.95 4.00 [82] 4.05 4.10 4.15 4.20 4.25 4.30 4.35 4.40 4.45 [91] 4.50 4.55 4.60 4.65 4.70 4.75 4.80 4.85 4.90 [100] 4.95 5.00 5.05 5.10 5.15 5.20 5.25 5.30 5.35 [109] 5.40 5.45 5.50 5.55 5.60 5.65 5.70 5.75 5.80 [118] 5.85 5.90 5.95 6.00 6.05 6.10 6.15 6.20 6.25 [127] 6.30 6.35 6.40 6.45 6.50 6.55 6.60 6.65 6.70 [136] 6.75 6.80 6.85 6.90 6.95 7.00 7.05 7.10 7.15 [145] 7.20 7.25 7.30 7.35 7.40 7.45 7.50 7.55 7.60 [154] 7.65 7.70 7.75 7.80 7.85 7.90 7.95 8.00 8.05 [163] 8.10 8.15 8.20 8.25 8.30 8.35 8.40 8.45 8.50 [172] 8.55 8.60 8.65 8.70 8.75 8.80 8.85 8.90 8.95 [181] 9.00 9.05 9.10 9.15 9.20 9.25 9.30 9.35 9.40 [190] 9.45 9.50 9.55 9.60 9.65 9.70 9.75 9.80 9.85 [199] 9.90 9.95 10.00 > plot(x,y) > plot(x,y,type="l") > reg1 <- lm(y ~ sin(x) ) > reg1 Call: lm(formula = y ~ sin(x)) Coefficients: (Intercept) sin(x) -0.08869 1.04470 > plot(x,y) > lines(x,reg1$fitted,col="blue") > reg2 <- lm(y ~ sin(x) + cos(x)) > reg2 Call: lm(formula = y ~ sin(x) + cos(x)) Coefficients: (Intercept) sin(x) cos(x) 0.0298 0.9380 1.8449 > lines(x,reg2$fitted,col="red") > plot(x,reg2$resid) > summary(rg2) Error in summary(rg2) : object 'rg2' not found > summary(reg2) Call: lm(formula = y ~ sin(x) + cos(x)) Residuals: Min 1Q Median 3Q Max -1.45811 -0.32978 0.01823 0.40133 1.33131 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.02980 0.03660 0.814 0.416 sin(x) 0.93798 0.05295 17.715 <2e-16 *** cos(x) 1.84490 0.04877 37.825 <2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.4987 on 198 degrees of freedom Multiple R-squared: 0.9019, Adjusted R-squared: 0.9009 F-statistic: 910.6 on 2 and 198 DF, p-value: < 2.2e-16 > reg3 <- lm(y ~ sin(x) + cos(x) + 0) > plot(x,y) > plot(x,y) > lines(x,reg3$fitted) > anova(reg1,reg2) Analysis of Variance Table Model 1: y ~ sin(x) Model 2: y ~ sin(x) + cos(x) Res.Df RSS Df Sum of Sq F Pr(>F) 1 199 405.04 2 198 49.24 1 355.8 1430.7 < 2.2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > anova(reg2,reg3) Analysis of Variance Table Model 1: y ~ sin(x) + cos(x) Model 2: y ~ sin(x) + cos(x) + 0 Res.Df RSS Df Sum of Sq F Pr(>F) 1 198 49.240 2 199 49.405 -1 -0.16487 0.663 0.4165 >