 | :: Multiple Regression - Free Statistics Software (Calculator) :: | |
|
All rights reserved. The non-commercial (academic) use of this software is free of charge. The only thing that is asked in return is to cite this software when results are used in publications.
This free online software (calculator) computes the multiple regression model based on the Ordinary Least Squares method.
Click here to edit the underlying code of this R Module.Enter (or paste) a matrix (table) containing all data (time) series. Every column represents a different variable and must be delimited by a space or Tab. Every row represents a period in time (or category) and must be delimited by hard returns. The easiest way to enter data is to copy and paste a block of spreadsheet cells. Please, do not use commas or spaces to seperate groups of digits! Click here to edit the underlying code of this R Module.
| Source code of R module | | 1 | library(lattice) | | 2 | library(lmtest) | | 3 | n25 <- 25 #minimum number of obs. for Goldfeld-Quandt test | | 4 | par1 <- as.numeric(par1) | | 5 | x <- t(y) | | 6 | k <- length(x[1,]) | | 7 | n <- length(x[,1]) | | 8 | x1 <- cbind(x[,par1], x[,1:k!=par1]) | | 9 | mycolnames <- c(colnames(x)[par1], colnames(x)[1:k!=par1]) | | 10 | colnames(x1) <- mycolnames #colnames(x)[par1] | | 11 | x <- x1 | | 12 | if (par3 == "First Differences"){ | | 13 | x2 <- array(0, dim=c(n-1,k), dimnames=list(1:(n-1), paste("(1-B)",colnames(x),sep=""))) | | 14 | for (i in 1:n-1) { | | 15 | for (j in 1:k) { | | 16 | x2[i,j] <- x[i+1,j] - x[i,j] | | 17 | } | | 18 | } | | 19 | x <- x2 | | 20 | } | | 21 | if (par2 == "Include Monthly Dummies"){ | | 22 | x2 <- array(0, dim=c(n,11), dimnames=list(1:n, paste("M", seq(1:11), sep =""))) | | 23 | for (i in 1:11){ | | 24 | x2[seq(i,n,12),i] <- 1 | | 25 | } | | 26 | x <- cbind(x, x2) | | 27 | } | | 28 | if (par2 == "Include Quarterly Dummies"){ | | 29 | x2 <- array(0, dim=c(n,3), dimnames=list(1:n, paste("Q", seq(1:3), sep =""))) | | 30 | for (i in 1:3){ | | 31 | x2[seq(i,n,4),i] <- 1 | | 32 | } | | 33 | x <- cbind(x, x2) | | 34 | } | | 35 | k <- length(x[1,]) | | 36 | if (par3 == "Linear Trend"){ | | 37 | x <- cbind(x, c(1:n)) | | 38 | colnames(x)[k+1] <- "t" | | 39 | } | | 40 | x | | 41 | k <- length(x[1,]) | | 42 | df <- as.data.frame(x) | | 43 | (mylm <- lm(df)) | | 44 | (mysum <- summary(mylm)) | | 45 | if (n > n25) { | | 46 | kp3 <- k + 3 | | 47 | nmkm3 <- n - k - 3 | | 48 | gqarr <- array(NA, dim=c(nmkm3-kp3+1,3)) | | 49 | numgqtests <- 0 | | 50 | numsignificant1 <- 0 | | 51 | numsignificant5 <- 0 | | 52 | numsignificant10 <- 0 | | 53 | for (mypoint in kp3:nmkm3) { | | 54 | j <- 0 | | 55 | numgqtests <- numgqtests + 1 | | 56 | for (myalt in c("greater", "two.sided", "less")) { | | 57 | j <- j + 1 | | 58 | gqarr[mypoint-kp3+1,j] <- gqtest(mylm, point=mypoint, alternative=myalt)$p.value | | 59 | } | | 60 | if (gqarr[mypoint-kp3+1,2] < 0.01) numsignificant1 <- numsignificant1 + 1 | | 61 | if (gqarr[mypoint-kp3+1,2] < 0.05) numsignificant5 <- numsignificant5 + 1 | | 62 | if (gqarr[mypoint-kp3+1,2] < 0.10) numsignificant10 <- numsignificant10 + 1 | | 63 | } | | 64 | gqarr | | 65 | } | | 66 | bitmap(file="test0.png") | | 67 | plot(x[,1], type="l", main="Actuals and Interpolation", ylab="value of Actuals and Interpolation (dots)", xlab="time or index") | | 68 | points(x[,1]-mysum$resid) | | 69 | grid() | | 70 | dev.off() | | 71 | bitmap(file="test1.png") | | 72 | plot(mysum$resid, type="b", pch=19, main="Residuals", ylab="value of Residuals", xlab="time or index") | | 73 | grid() | | 74 | dev.off() | | 75 | bitmap(file="test2.png") | | 76 | hist(mysum$resid, main="Residual Histogram", xlab="values of Residuals") | | 77 | grid() | | 78 | dev.off() | | 79 | bitmap(file="test3.png") | | 80 | densityplot(~mysum$resid,col="black",main="Residual Density Plot", xlab="values of Residuals") | | 81 | dev.off() | | 82 | bitmap(file="test4.png") | | 83 | qqnorm(mysum$resid, main="Residual Normal Q-Q Plot") | | 84 | qqline(mysum$resid) | | 85 | grid() | | 86 | dev.off() | | 87 | (myerror <- as.ts(mysum$resid)) | | 88 | bitmap(file='test5.png') | | 89 | dum <- cbind(lag(myerror,k=1),myerror) | | 90 | dum | | 91 | dum1 <- dum[2:length(myerror),] | | 92 | dum1 | | 93 | z <- as.data.frame(dum1) | | 94 | z | | 95 | plot(z,main=paste("Residual Lag plot, lowess, and regression line"), ylab="values of Residuals", xlab="lagged values of Residuals") | | 96 | lines(lowess(z)) | | 97 | abline(lm(z)) | | 98 | grid() | | 99 | dev.off() | | 100 | bitmap(file="test6.png") | | 101 | acf(mysum$resid, lag.max=length(mysum$resid)/2, main="Residual Autocorrelation Function") | | 102 | grid() | | 103 | dev.off() | | 104 | bitmap(file="test7.png") | | 105 | pacf(mysum$resid, lag.max=length(mysum$resid)/2, main="Residual Partial Autocorrelation Function") | | 106 | grid() | | 107 | dev.off() | | 108 | bitmap(file="test8.png") | | 109 | opar <- par(mfrow = c(2,2), oma = c(0, 0, 1.1, 0)) | | 110 | plot(mylm, las = 1, sub="Residual Diagnostics") | | 111 | par(opar) | | 112 | dev.off() | | 113 | if (n > n25) { | | 114 | bitmap(file="test9.png") | | 115 | plot(kp3:nmkm3,gqarr[,2], main="Goldfeld-Quandt test",ylab="2-sided p-value",xlab="breakpoint") | | 116 | grid() | | 117 | dev.off() | | 118 | } | | 119 | load(file="createtable") | | 120 | a<-table.start() | | 121 | a<-table.row.start(a) | | 122 | a<-table.element(a, "Multiple Linear Regression - Estimated Regression Equation", 1, TRUE) | | 123 | a<-table.row.end(a) | | 124 | myeq <- colnames(x)[1] | | 125 | myeq <- paste(myeq, "[t] = ", sep="") | | 126 | for (i in 1:k){ | | 127 | if (mysum$coefficients[i,1] > 0) myeq <- paste(myeq, "+", "") | | 128 | myeq <- paste(myeq, mysum$coefficients[i,1], sep=" ") | | 129 | if (rownames(mysum$coefficients)[i] != "(Intercept)") { | | 130 | myeq <- paste(myeq, rownames(mysum$coefficients)[i], sep="") | | 131 | if (rownames(mysum$coefficients)[i] != "t") myeq <- paste(myeq, "[t]", sep="") | | 132 | } | | 133 | } | | 134 | myeq <- paste(myeq, " + e[t]") | | 135 | a<-table.row.start(a) | | 136 | a<-table.element(a, myeq) | | 137 | a<-table.row.end(a) | | 138 | a<-table.end(a) | | 139 | table.save(a,file="mytable1.tab") | | 140 | a<-table.start() | | 141 | a<-table.row.start(a) | | 142 | a<-table.element(a,hyperlink("http://www.xycoon.com/ols1.htm","Multiple Linear Regression - Ordinary Least Squares",""), 6, TRUE) | | 143 | a<-table.row.end(a) | | 144 | a<-table.row.start(a) | | 145 | a<-table.element(a,"Variable",header=TRUE) | | 146 | a<-table.element(a,"Parameter",header=TRUE) | | 147 | a<-table.element(a,"S.D.",header=TRUE) | | 148 | a<-table.element(a,"T-STAT H0: parameter = 0",header=TRUE) | | 149 | a<-table.element(a,"2-tail p-value",header=TRUE) | | 150 | a<-table.element(a,"1-tail p-value",header=TRUE) | | 151 | a<-table.row.end(a) | | 152 | for (i in 1:k){ | | 153 | a<-table.row.start(a) | | 154 | a<-table.element(a,rownames(mysum$coefficients)[i],header=TRUE) | | 155 | a<-table.element(a,mysum$coefficients[i,1]) | | 156 | a<-table.element(a, round(mysum$coefficients[i,2],6)) | | 157 | a<-table.element(a, round(mysum$coefficients[i,3],4)) | | 158 | a<-table.element(a, round(mysum$coefficients[i,4],6)) | | 159 | a<-table.element(a, round(mysum$coefficients[i,4]/2,6)) | | 160 | a<-table.row.end(a) | | 161 | } | | 162 | a<-table.end(a) | | 163 | table.save(a,file="mytable2.tab") | | 164 | a<-table.start() | | 165 | a<-table.row.start(a) | | 166 | a<-table.element(a, "Multiple Linear Regression - Regression Statistics", 2, TRUE) | | 167 | a<-table.row.end(a) | | 168 | a<-table.row.start(a) | | 169 | a<-table.element(a, "Multiple R",1,TRUE) | | 170 | a<-table.element(a, sqrt(mysum$r.squared)) | | 171 | a<-table.row.end(a) | | 172 | a<-table.row.start(a) | | 173 | a<-table.element(a, "R-squared",1,TRUE) | | 174 | a<-table.element(a, mysum$r.squared) | | 175 | a<-table.row.end(a) | | 176 | a<-table.row.start(a) | | 177 | a<-table.element(a, "Adjusted R-squared",1,TRUE) | | 178 | a<-table.element(a, mysum$adj.r.squared) | | 179 | a<-table.row.end(a) | | 180 | a<-table.row.start(a) | | 181 | a<-table.element(a, "F-TEST (value)",1,TRUE) | | 182 | a<-table.element(a, mysum$fstatistic[1]) | | 183 | a<-table.row.end(a) | | 184 | a<-table.row.start(a) | | 185 | a<-table.element(a, "F-TEST (DF numerator)",1,TRUE) | | 186 | a<-table.element(a, mysum$fstatistic[2]) | | 187 | a<-table.row.end(a) | | 188 | a<-table.row.start(a) | | 189 | a<-table.element(a, "F-TEST (DF denominator)",1,TRUE) | | 190 | a<-table.element(a, mysum$fstatistic[3]) | | 191 | a<-table.row.end(a) | | 192 | a<-table.row.start(a) | | 193 | a<-table.element(a, "p-value",1,TRUE) | | 194 | a<-table.element(a, 1-pf(mysum$fstatistic[1],mysum$fstatistic[2],mysum$fstatistic[3])) | | 195 | a<-table.row.end(a) | | 196 | a<-table.row.start(a) | | 197 | a<-table.element(a, "Multiple Linear Regression - Residual Statistics", 2, TRUE) | | 198 | a<-table.row.end(a) | | 199 | a<-table.row.start(a) | | 200 | a<-table.element(a, "Residual Standard Deviation",1,TRUE) | | 201 | a<-table.element(a, mysum$sigma) | | 202 | a<-table.row.end(a) | | 203 | a<-table.row.start(a) | | 204 | a<-table.element(a, "Sum Squared Residuals",1,TRUE) | | 205 | a<-table.element(a, sum(myerror*myerror)) | | 206 | a<-table.row.end(a) | | 207 | a<-table.end(a) | | 208 | table.save(a,file="mytable3.tab") | | 209 | a<-table.start() | | 210 | a<-table.row.start(a) | | 211 | a<-table.element(a, "Multiple Linear Regression - Actuals, Interpolation, and Residuals", 4, TRUE) | | 212 | a<-table.row.end(a) | | 213 | a<-table.row.start(a) | | 214 | a<-table.element(a, "Time or Index", 1, TRUE) | | 215 | a<-table.element(a, "Actuals", 1, TRUE) | | 216 | a<-table.element(a, "Interpolation Forecast", 1, TRUE) | | 217 | a<-table.element(a, "Residuals Prediction Error", 1, TRUE) | | 218 | a<-table.row.end(a) | | 219 | for (i in 1:n) { | | 220 | a<-table.row.start(a) | | 221 | a<-table.element(a,i, 1, TRUE) | | 222 | a<-table.element(a,x[i]) | | 223 | a<-table.element(a,x[i]-mysum$resid[i]) | | 224 | a<-table.element(a,mysum$resid[i]) | | 225 | a<-table.row.end(a) | | 226 | } | | 227 | a<-table.end(a) | | 228 | table.save(a,file="mytable4.tab") | | 229 | if (n > n25) { | | 230 | a<-table.start() | | 231 | a<-table.row.start(a) | | 232 | a<-table.element(a,"Goldfeld-Quandt test for Heteroskedasticity",4,TRUE) | | 233 | a<-table.row.end(a) | | 234 | a<-table.row.start(a) | | 235 | a<-table.element(a,"p-values",header=TRUE) | | 236 | a<-table.element(a,"Alternative Hypothesis",3,header=TRUE) | | 237 | a<-table.row.end(a) | | 238 | a<-table.row.start(a) | | 239 | a<-table.element(a,"breakpoint index",header=TRUE) | | 240 | a<-table.element(a,"greater",header=TRUE) | | 241 | a<-table.element(a,"2-sided",header=TRUE) | | 242 | a<-table.element(a,"less",header=TRUE) | | 243 | a<-table.row.end(a) | | 244 | for (mypoint in kp3:nmkm3) { | | 245 | a<-table.row.start(a) | | 246 | a<-table.element(a,mypoint,header=TRUE) | | 247 | a<-table.element(a,gqarr[mypoint-kp3+1,1]) | | 248 | a<-table.element(a,gqarr[mypoint-kp3+1,2]) | | 249 | a<-table.element(a,gqarr[mypoint-kp3+1,3]) | | 250 | a<-table.row.end(a) | | 251 | } | | 252 | a<-table.end(a) | | 253 | table.save(a,file="mytable5.tab") | | 254 | a<-table.start() | | 255 | a<-table.row.start(a) | | 256 | a<-table.element(a,"Meta Analysis of Goldfeld-Quandt test for Heteroskedasticity",4,TRUE) | | 257 | a<-table.row.end(a) | | 258 | a<-table.row.start(a) | | 259 | a<-table.element(a,"Description",header=TRUE) | | 260 | a<-table.element(a,"# significant tests",header=TRUE) | | 261 | a<-table.element(a,"% significant tests",header=TRUE) | | 262 | a<-table.element(a,"OK/NOK",header=TRUE) | | 263 | a<-table.row.end(a) | | 264 | a<-table.row.start(a) | | 265 | a<-table.element(a,"1% type I error level",header=TRUE) | | 266 | a<-table.element(a,numsignificant1) | | 267 | a<-table.element(a,numsignificant1/numgqtests) | | 268 | if (numsignificant1/numgqtests < 0.01) dum <- "OK" else dum <- "NOK" | | 269 | a<-table.element(a,dum) | | 270 | a<-table.row.end(a) | | 271 | a<-table.row.start(a) | | 272 | a<-table.element(a,"5% type I error level",header=TRUE) | | 273 | a<-table.element(a,numsignificant5) | | 274 | a<-table.element(a,numsignificant5/numgqtests) | | 275 | if (numsignificant5/numgqtests < 0.05) dum <- "OK" else dum <- "NOK" | | 276 | a<-table.element(a,dum) | | 277 | a<-table.row.end(a) | | 278 | a<-table.row.start(a) | | 279 | a<-table.element(a,"10% type I error level",header=TRUE) | | 280 | a<-table.element(a,numsignificant10) | | 281 | a<-table.element(a,numsignificant10/numgqtests) | | 282 | if (numsignificant10/numgqtests < 0.1) dum <- "OK" else dum <- "NOK" | | 283 | a<-table.element(a,dum) | | 284 | a<-table.row.end(a) | | 285 | a<-table.end(a) | | 286 | table.save(a,file="mytable6.tab") | | 287 | } |
|
| Cite this software as: | | Wessa P., (2008), Multiple Regression (v1.0.26) in Free Statistics Software (v1.1.23-r6), Office for Research Development and Education, URL http://www.wessa.net/rwasp_multipleregression.wasp/ | | | The R code is based on : | | | Chambers, J. M. (1992), Linear models. (Chapter 4 of Statistical Models in S), eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole. | | | Borghers, E, and P. Wessa, Statistics - Econometrics - Forecasting, Office for Research Development and Education, http://www.xycoon.com/ | | | | | | | | | | | |
|
To cite Wessa.net in publications use: Wessa, P. (2010), Free Statistics Software, Office for Research Development and Education, version 1.1.23-r6, URL http://www.wessa.net/
© Resa
R&D, and the 'Office for Research, Development, and Education' - All rights reserved. Academic license for non-commercial use only.
This website is an intellectual
and physical property of Resa R&D. This includes: html content,
graphical illustrations (gif files), computer software, online or electronic
documentation, associated media, and printed materials. The free use of the scientific content, services, and applications in this website is
granted for non commercial use only. In any case,
the source (url) should always be clearly displayed. Under no circumstances are
you allowed to reproduce, copy or redistribute the design, layout, or any
content of this website (for commercial use) including any materials contained
herein without the express written permission of Resa R&D or the Office for Research, Development, and Education.
Information provided
on this web site is provided "AS IS" without warranty of any kind, either
express or implied, including, without limitation, warranties of
merchantability, fitness for a particular purpose, and noninfringement. We use reasonable efforts to include accurate and timely information
and periodically update the information, and software without notice. However, Resa
R&D makes no warranties or representations
as to the accuracy or completeness of such information (or software), and it assumes no
liability or responsibility for errors or omissions in the content of this web
site, or any software bugs in online applications. Your use of this web site is AT YOUR OWN RISK. Under no circumstances and
under no legal theory shall Resa R&D be liable to you or any other
person for any direct, indirect, special, incidental, exemplary, or
consequential damages arising from your access to, or use of, this web site.
Software Version : 1.1.23-r6 Algorithms & Software : Prof. dr. P. Wessa Facilities : Resa R&D - Office for Research, Development, and Education Server : patrick.wessa.net
Comments, Feedback & Errors | Privacy Policy | Statistics Resources | Wessa.net Home
|
|
|