R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out" Copyright (C) 2020 The R Foundation for Statistical Computing Platform: i386-w64-mingw32/i386 (32-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. > data1<-read.csv("F:/Data Project Analysis/R-code example/data1.csv",header = TRUE) > data1 Y x1 x2 x3 x4 1 0.01 16952.54 2.40 5.55 3.02 2 0.02 16853.53 2.35 5.27 2.91 3 0.04 17836.29 2.41 5.10 2.95 4 0.07 18393.67 2.49 5.09 2.96 5 0.12 18606.36 2.53 5.14 3.00 6 0.16 19644.12 2.60 5.46 3.10 7 0.20 19438.77 2.53 4.83 2.92 8 0.21 18841.05 2.48 4.39 2.79 9 0.22 18679.70 2.50 4.20 2.77 10 0.21 18610.03 2.51 3.88 2.73 11 0.21 19281.09 2.35 3.73 2.68 12 0.22 19864.14 2.52 3.75 2.77 13 0.24 20472.86 2.62 3.90 2.86 14 0.27 20993.58 2.68 3.88 2.92 15 0.31 21767.31 2.75 3.82 3.00 16 0.33 22244.02 2.79 3.71 3.05 17 0.33 22273.36 2.86 3.77 3.05 18 0.33 22522.71 2.80 3.61 2.95 19 0.33 22229.35 2.71 3.54 2.89 20 0.33 22434.71 2.56 3.20 2.72 21 0.34 22603.39 2.43 2.74 2.62 22 0.37 23109.43 2.26 2.45 2.49 23 0.40 23692.49 2.19 2.10 2.38 24 0.42 23952.84 2.09 1.73 2.19 25 0.44 23938.18 1.93 1.70 2.14 26 0.47 24282.87 1.75 1.32 2.02 27 0.05 24935.60 1.60 1.29 1.95 28 0.52 25085.95 1.53 1.20 1.91 29 0.55 25694.67 1.44 1.08 1.81 30 0.59 27113.80 1.33 1.05 1.78 31 0.61 28356.91 1.25 0.89 1.73 32 0.62 29508.35 1.17 0.77 1.72 33 0.63 30513.11 1.12 0.73 1.66 34 0.64 31033.82 1.09 0.63 1.59 35 0.64 32119.25 1.01 0.53 1.43 36 0.64 31272.18 0.92 0.43 1.25 37 0.65 33443.04 0.90 0.45 1.22 38 0.66 34539.47 0.89 0.41 1.14 39 0.70 35305.88 0.88 0.46 1.16 40 0.74 35745.92 0.85 0.40 1.10 41 0.78 35841.26 0.84 0.32 1.03 42 0.83 35976.94 0.84 0.25 0.99 43 0.87 35998.94 0.82 0.18 0.89 > summary(data1) Y x1 x2 x3 Min. :0.0100 Min. :16854 Min. :0.820 Min. :0.180 1st Qu.:0.2150 1st Qu.:19754 1st Qu.:1.145 1st Qu.:0.750 Median :0.3400 Median :23109 Median :2.260 Median :2.450 Mean :0.4028 Mean :24930 Mean :1.920 Mean :2.533 3rd Qu.:0.6250 3rd Qu.:30011 3rd Qu.:2.525 3rd Qu.:3.880 Max. :0.8700 Max. :35999 Max. :2.860 Max. :5.550 x4 Min. :0.890 1st Qu.:1.690 Median :2.490 Mean :2.238 3rd Qu.:2.915 Max. :3.100 > sapply(data1[,1:5], sd) Y x1 x2 x3 x4 0.2375402 6048.8261217 0.7288853 1.8082084 0.7306040 > model1=lm(Y~x1 +x2 +x3 + x4,data=data1) > model1 Call: lm(formula = Y ~ x1 + x2 + x3 + x4, data = data1) Coefficients: (Intercept) x1 x2 x3 x4 -3.758e-01 3.115e-05 9.547e-02 -4.895e-02 -2.561e-02 > summary(model1) Call: lm(formula = Y ~ x1 + x2 + x3 + x4, data = data1) Residuals: Min 1Q Median 3Q Max -0.39062 -0.01486 0.00192 0.03265 0.09121 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -3.758e-01 3.029e-01 -1.241 0.2224 x1 3.115e-05 6.832e-06 4.559 5.2e-05 *** x2 9.547e-02 9.302e-02 1.026 0.3112 x3 -4.895e-02 2.026e-02 -2.416 0.0206 * x4 -2.561e-02 1.362e-01 -0.188 0.8518 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.07583 on 38 degrees of freedom Multiple R-squared: 0.9078, Adjusted R-squared: 0.8981 F-statistic: 93.52 on 4 and 38 DF, p-value: < 2.2e-16 > sapply(data1[,1:5], sd) Y x1 x2 x3 x4 0.2375402 6048.8261217 0.7288853 1.8082084 0.7306040 > library(lmtest) Loading required package: zoo Attaching package: ‘zoo’ The following objects are masked from ‘package:base’: as.Date, as.Date.numeric > dwtest(model1) Durbin-Watson test data: model1 DW = 1.9266, p-value = 0.1838 alternative hypothesis: true autocorrelation is greater than 0 > cor(data1$x1,data1$x3) [1] -0.9163144 > cor(data1$x1,data1$x4) [1] -0.9536833 > cor(data1$x2,data1$x3) [1] 0.9005592 > cor(data1$x2,data1$x1) [1] -0.9173192 > cor(data1$x2,data1$x4) [1] 0.9815393 > cor(data1$x2,data1$x2) [1] 1 > r2=resid(model1)^2 > model2 = lm(r2~x1 + x1^2 + x2 + x2^2 + x3 + x3^2 +x4+ x3^2 + x1*x2 + x1*x3 +x1*x4+ x2*x3+x2*x4, data = data1) > model2 Call: lm(formula = r2 ~ x1 + x1^2 + x2 + x2^2 + x3 + x3^2 + x4 + x3^2 + x1 * x2 + x1 * x3 + x1 * x4 + x2 * x3 + x2 * x4, data = data1) Coefficients: (Intercept) x1 x2 x3 x4 x1:x2 -7.137e-02 4.057e-06 -2.688e-01 -1.594e-01 4.882e-01 8.597e-06 x1:x3 x1:x4 x2:x3 x2:x4 5.205e-06 -1.631e-05 1.609e-02 -2.227e-02 > summary(model2) Call: lm(formula = r2 ~ x1 + x1^2 + x2 + x2^2 + x3 + x3^2 + x4 + x3^2 + x1 * x2 + x1 * x3 + x1 * x4 + x2 * x3 + x2 * x4, data = data1) Residuals: Min 1Q Median 3Q Max -0.024453 -0.005708 -0.001411 0.003178 0.125147 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -7.137e-02 7.348e-01 -0.097 0.923 x1 4.057e-06 1.776e-05 0.228 0.821 x2 -2.688e-01 2.195e-01 -1.225 0.229 x3 -1.594e-01 1.662e-01 -0.959 0.345 x4 4.882e-01 5.600e-01 0.872 0.390 x1:x2 8.597e-06 8.376e-06 1.026 0.312 x1:x3 5.205e-06 4.613e-06 1.128 0.267 x1:x4 -1.631e-05 1.410e-05 -1.157 0.256 x2:x3 1.609e-02 4.716e-02 0.341 0.735 x2:x4 -2.227e-02 9.688e-02 -0.230 0.820 Residual standard error: 0.02375 on 33 degrees of freedom Multiple R-squared: 0.172, Adjusted R-squared: -0.0538 F-statistic: 0.7617 on 9 and 33 DF, p-value: 0.6514 > save.image("F:\\Data Project Analysis\\R-code example\\.RData") >