* QUADREG: * Syntax That Computes Simple Quadratic Regression Statistics & Plots The Pattern. * Two variables are read by the program, an IDV and a DV; the program computes the quadratic term ( IDV * IDV ), followed by a regression test of the degree to which the quadratic term adds to the prediction of the DV beyond the effect for the IDV alone. * The resulting regression equation is then used to produce data points for a plot of the quadratic association; data points are obtained for the following 13 values, which are deviations from the IDV mean in standard deviation units: -3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3. * Program Source: O'Connor, B. P. (2006). QUADREG: Syntax that computes simple quadratic regression statistics and plots the pattern. Retrieved from https://people.ok.ubc.ca/brioconn/quadreg.html. **************** START OF TRIAL-RUN DATA ************************** The following commands generate artificial data that can be used for a trial-run of the program. Just run this whole file. new file. input program. loop #a=1 to 200. compute idv = normal (1). compute e = uniform (1). end case. end loop. end file. end input program. compute dv = 6.7*idv + 6.23*(idv*idv) + e*5 . descriptives var = all. **************** END OF TRIAL-RUN DATA *****************************. * quadratic regression on the artificial data. compute x2 = idv * idv. regression /var= idv x2 dv /statistics=defaults zpp bcov /dependent=dv /enter idv /test (x2) . set mxloops=999999 printback = off length=none width=100. matrix. * The GET command below reads the data file & creates a data matrix ("datamat"). Enter the name of the dataset (and the file path) on the GET command after "file=". Using a "*" instead of a file name & path causes the program to use the currently active SPSS data set. * Then enter the names of the variables after "variables =" on the GET command. Only two variables names are permitted, and they must appear in the following order: idv, dv. * If the name of the idv in your dataset is something other than "idv", then enter the correct name in the place of "idv" after "variables =". * If the name of the dv in your dataset is something other than "dv", then enter the correct name in the place of "dv" after "variables =". get datamat / file=* / variables = idv, dv / missing=omit. * The program automatically computes the quadratic term. ****************** End of User Specifications *********************. * creating the data matrix & product term. compute datam={datamat(:,1),(datamat(:,1)&**2),datamat(:,2)}. * n, mean, sd, & correlation matrix (Bernstein, p. 77-79). compute n = nrow(datam). compute rawsp = t(datam) * datam . compute rsums = t(csum(datam)). compute mn = t(rsums) / n. compute corsp = rawsp - (1/n) * (rsums) * t(rsums) . compute vcv = corsp * (1/(n-1)). compute sd = t(sqrt(diag(vcv))). compute d = inv(mdiag(sqrt(diag(vcv)))). compute cr = d * vcv * d. * Overall regression coeffs. compute beta = inv(cr(1:2,1:2)) * cr(1:2,3) . compute b = (sd(1,3) &/ sd(1,1:2)) &* t(beta) . compute a = mn(1,3) - ( rsum ( mn(1,1:2) &* b ) ) . compute r2all = t(beta) * cr(1:2,3) . compute r2main = t(inv(cr(1:1,1:1))*cr(1:1,3))*cr(1:1,3). compute r2chX2 = r2all - r2main. compute fsquare = (r2all - r2main) / (1 - r2all) . compute F = (r2all-r2main) / ((1-r2all)/(n-2-1)). compute dferror = n - 2 - 1. compute pF = 1 - fcdf(F,1,dferror) . print {r2chX2,F,{1},dferror,fsquare,pF} /title="Coefficients for the Quadratic Term" /clabels="Rsq. ch." "F" "df num." "df denom." "f-squared" "Sig. F". print {t(b),beta} /title="Beta weights for the full equation:" /rlabels="idv" "mod" "X2" /clabels="raw b" "std.beta" . print a /title="The intercept is:" . * data for plot. compute idv = { mn(1,1) + 3 *sd(1,1); mn(1,1) + 2.5 *sd(1,1); mn(1,1) + 2 *sd(1,1); mn(1,1) + 1.5 *sd(1,1); mn(1,1) + 1 *sd(1,1); mn(1,1) + 0.5 *sd(1,1); mn(1,1); mn(1,1) - 0.5 *sd(1,1); mn(1,1) - 1 *sd(1,1); mn(1,1) - 1.5 *sd(1,1); mn(1,1) - 2 *sd(1,1); mn(1,1) - 2.5 *sd(1,1); mn(1,1) - 3 *sd(1,1) } . compute dv = (b(1,1)&*idv) + (b(1,2)&*idv&**2) + a. compute data = { idv , dv }. print data. save data /outfile=* / var=idv dv . end matrix. GRAPH title= 'Data Points Derived From The Quadratic Equation' /SCATTERPLOT(BIVAR)=idv WITH dv .