/*
* chapter 1
* introduce the elemapi2 data file
* look at data view
* show means of variables
analyze -> descriptives -> desc api00 ell meals yr_rnd mobility acs_k3 acs_46 full emer enroll
* show freq tables for selected variables
analyze -> descriptives -> freq yr_rnd acs_k3 acs_46
* show historgram for enroll
graphs -> histogram enroll
* show means for each level of yr_rnd
analyze -> means -> compare means dv: api00 iv: yr_rnd
* a first simple regression
analyze -> regress
dv: api00 iv: yr_rnd
* simple regression with a continuous variable
analyze -> regress
dv: api00 iv: meals
* show a correlation
analyze -> correlation -> bivariate api00 meals
* a first multiple regression
analyze -> regress
dv: api00 iv: ell meals yr_rnd mobility acs_k3 acs_46 full emer enroll
* chapter 2
* unusual and influential data
* look at crime data file
* look at means of variables
descriptives -> desc crime murder pctmetro pctwhite pcths poverty single
* show scatterplot matrix
graphs -> scatter -> matrix -> crime pctmetro poverty single
* show crime by pctmetro
graphs -> interactive -> scatterplot
* show crime by poverty
dialogue recall
* show crime by single
dialogue recall
* show regression and save rstudent, lev, cooksd
analyze -> regression -> linear
dv: crime iv: pctmetro poverty single save: under residuals, standardized; under distances,
cooksd and leverage
* look at labels in variable view
* examine residuals for normality
* descriptive statistics part of output from above, which includes more than we requested
igraph boxplot resid
igraph p-p resid
********************************here we are going to start using syntax***********************.
*/
* show 10 smallest residuals.
sort cases by zre_1.
* look in data view at 10 smallest and 10 largest.
* show 10 largest leverage points.
sort cases by lev_1.
* look at 10 largest in data view.
* show residual squared by leverage.
compute r2 = zre_1*zre_1.
igraph
/x1 = var(lev_1)
/y= var(r2)
/pointlabel = var(state) all
/fitline method = regression linear line = total
/catorder var(state) (ascending values omitempty)
/scatter coincident = none.
* show cooksd that exceed criteria of (k/n).
compute cook_filter = 0.
if coo_1 > (4/51) cook_filter = 1.
filter by cook_filter.
exe.
* look at cases 9, 18, 25 and 51.
filter off.
* show dfbetas (rerun regression).
* dfbeta: change in regression coeff when the case is deleted.
* dffits: change in the predicted value when the case is deleted.
regression
/dep crime
/method = enter pctmetro poverty single
/save dfbeta.
* look at these in data view.
* dc seems to be a problem - let's try a regression w/ and w/o dc.
regression
/dep crime
/method = enter pctmetro poverty single.
* create a filter to filter out only dc.
compute filter_dc = 1.
if sid = 51 filter_dc = 0.
filter by filter_dc.
regression
/dep crime
/method = enter pctmetro poverty single.
filter off.
* tests for normality of residuals.
get file="g:\spss regression seminar\elemapi2.sav".
regression
/dependent api00
/method=enter meals ell emer
/save resid(apires).
examine
variables=apires
/plot boxplot stemleaf histogram npplot.
* understanding for coef - meals will have a negative coef.
regression
/dependent api00
/method=enter meals ell emer
/scatterplot(*pred meals).
* heteroscedasiticity.
regression
/dependent api00
/method=enter meals ell emer
/scatterplot(*zresid *pred).
regression
/dependent api00
/method=enter enroll
/scatterplot(*zresid *pred).
compute lenroll = ln(enroll).
regression
/dependent api00
/method=enter lenroll
/scatterplot(*zresid *pred).
*2.4 Collinearity.
* example 1 - vifs look fine.
regression
/statistics=defaults tol
/dependent api00
/method=enter meals ell emer .
* example 2 - more of a problem.
regression
/statistics=defaults tol collin
/dependent api00
/method=enter acs_k3 avg_ed grad_sch col_grad some_col.
* example 3 - omit avg_ed and vifs improve.
regression
/statistics=defaults tol collin
/dependent api00
/method=enter acs_k3 grad_sch col_grad some_col.
* chapter 3.
* regression with a 0/1 variable.
regression
/dep api00
/method = enter yr_rnd.
igraph
/x1 = var(yr_rnd) type = scale
/y = var (api00) type = scale
/fitline method = regression linear line = total meffect
/scatter coincident = none.
* regression with a 1/2 variable.
compute yr_rnd2 = yr_rnd.
recode yr_rnd2 (0=1) (1=2).
execute.
regression
/dependent api00
/method=enter yr_rnd2.
* the intercept is the mean for the non year-round schools minus the coef for yr_rnd2
* 684.539 - (-160.506) = 845.045.
* the coef for yr_rnd and yr_rnd2 is the same.
* regression with a 1/2/3 variable.
* manually creating dummy variables.
regression
/dependent api00
/method=enter mealcat.
compute mealcat1 = 0.
if mealcat = 1 mealcat1 = 1.
compute mealcat2 = 0.
if mealcat = 2 mealcat2 = 1.
compute mealcat3 = 0.
if mealcat = 3 mealcat3 = 1.
execute.
* verify dummy codes.
list mealcat mealcat1 mealcat2 mealcat3
/cases from 1 to 10.
regression
/dependent api00
/method = enter mealcat2 mealcat3.
means tables = api00 by mealcat.
* 3.5.1 manually coding an interaction.
compute yrmeal1 = mealcat1*yr_rnd.
compute yrmeal2 = mealcat2*yr_rnd.
execute.
regression
/dep api00
/method = enter yr_rnd mealcat1 mealcat2 yrmeal1 yrmeal2.
/*
Predicted values in terms of coefficients
mealcat=1 mealcat=2 mealcat=3
-------------------------------------------------
yr_rnd=0 constant constant constant
+Bmealcat1 +Bmealcat2
-------------------------------------------------
yr_rnd=1 constant constant constant
+Byr_rnd +Byr_rnd +Byr_rnd
+Bmealcat1 +Bmealcat2
+Bmealxynd1 +Bmealxynd2
*/
* 3.7 interactions of continuous by 0/1 categorical variables.
* First, we will look at the effect of some_col on api00 for each level of yr_rnd.
compute filt=(yr_rnd=0).
filter by filt.
regress
/dep = api00
/method = enter some_col.
igraph
/x1 = var(some_col)
/y = var (api00)
/fitline method = regression linear line = total meffect
/scatter coincident = none.
compute filt=(yr_rnd=1).
filter by filt.
regress
/dep = api00
/method = enter some_col.
igraph
/x1 = var(some_col)
/y = var (api00)
/fitline method = regression linear line = total meffect
/scatter coincident = none.
filter off.
* 3.7.1 computing interactions manually.
* Now we will look at the interaction of yr_rnd and some_col.
compute yrXsome = yr_rnd*some_col.
execute.
regress
/dep = api00
/method = enter some_col yr_rnd yrXsome
/save pre(catint).
graph
/scatterplot(bivar)=some_col with catint by yr_rnd.
graph
/scatterplot(bivar)=some_col with api00 by yr_rnd.
sort cases by yr_rnd.
split file by yr_rnd.
regress
/dep = api00
/method = enter some_col.
split file off.
regress
/dep = api00
/method = enter some_col yr_rnd yrXsome
/save pre(catint2).
graph
/scatterplot(bivar)=some_col with catint2 by yr_rnd.
* oms demo.
get file "e:\spss regression seminar\hsb2.sav".
oms select tables
/desination format = sav numbered = "Table_Number" outfile = "e:\results1a.sav"
/if commands = ['regression'] subtypes = ['Coefficients'] .
regress
/dep write
/method = enter female math.
omsend.
get file "e:\results1a.sav".
get file "e:\spss regression seminar\hsb2.sav".
oms select tables
/desination format = html outfile = "e:\resultshtml.html" .
regress
/dep write
/method = enter female math.
omsend.
get file "e:\spss regression seminar\hsb2.sav".
oms select tables
/destination format = html outfile = "e:\resultsc.html".
crosstabs tables = female by prog.
omsend.