jacknifing

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

jacknifing

<Peter M?>
Hallo,

I want to run the following example:

but my problem is, I can't get the frequency tables:


***oms_bootstrapping.sps***.
***if c:\temp is not a valid drive\path, replace all instances of c:\temp
   with a valid drive\path.

PRESERVE.
SET TVARS NAMES.

*first OMS command just suppresses Viewer output.
OMS /DESTINATION VIEWER=NO /TAG='suppressall'.

*select regression coefficients tables and write to data file.
OMS /SELECT TABLES
    /IF COMMANDS=['Regression'] SUBTYPES=['Coefficients']
    /DESTINATION FORMAT=SAV OUTFILE='c:\temp\temp.sav'
   /COLUMNS DIMNAMES=[ 'Variables'  'Statistics']
   /TAG='reg_coeff'.

*define a macro to draw samples with replacement and
 run Regression commands.
DEFINE regression_bootstrap (samples=!TOKENS(1)
                                           /depvar=!TOKENS(1)
                                           /indvars=!CMDEND)

COMPUTE dummyvar=1.
AGGREGATE
  /OUTFILE='c:\temp\aggrtemp.sav'
  /BREAK=dummyvar
  /filesize=N.
MATCH FILES FILE=* /TABLE='c:\temp\aggrtemp.sav'
  /BY dummyvar.
!DO !other=1 !TO !samples
SET SEED RANDOM.
WEIGHT OFF.
FILTER OFF.
DO IF $casenum=1.
- COMPUTE #samplesize=filesize.
- COMPUTE #filesize=filesize.
END IF.
DO IF (#samplesize>0 and #filesize>0).
- COMPUTE sampleWeight=rv.binom(#samplesize, 1/#filesize).
- COMPUTE #samplesize=#samplesize-sampleWeight.
- COMPUTE #filesize=#filesize-1.
ELSE.
- COMPUTE sampleWeight=0.
END IF.
WEIGHT BY sampleWeight.
FILTER BY sampleWeight.
REGRESSION
  /STATISTICS COEFF
  /DEPENDENT !depvar
  /METHOD=ENTER !indvars.
!DOEND
!ENDDEFINE.

***insert any valid path\data file name***.
GET FILE='c:\Program Files\SPSS\Employee data.sav'.

***Call the macro, and specify number of samples,
   dependent variable, and independent variables.
regression_bootstrap
   samples=100
   depvar=salary
   indvars=salbegin  jobtime .

OMSEND.

GET FILE 'c:\temp\temp.sav'.

FREQUENCIES
  VARIABLES=salbegin_B salbegin_Beta jobtime_B jobtime_Beta
  /FORMAT NOTABLE
  /PERCENTILES= 2.5 97.5
  /HISTOGRAM NORMAL.

RESTORE.




Actually I want to use this macro to make a jacknifing resampling by using
the following SPSS - resolution, which says that I have only to replace the
procedure in the beginning of the macro:

*** oms_bootstrapping.sps ***.

*********************************************************** .
* This macro is a 'Wrapper' for arbitrary syntax.
* Relace the contents of the block indicated below
* with syntax of your chosing.
* Nothing else need change.
*********************************************************** .
define syntax_macro(
      sample_weight=!tokens(1)
     /groupvar=!tokens(1) !default('')
).
************************************************************ .

weight by !unquote(!sample_weight) .
*.
* Add any block of syntax below:
*.
*///// Beginning of block of syntax to be replaced.......


FREQUENCIES
  VARIABLES=!groupvar
  /ORDER=  ANALYSIS .
GLM
  salbegin salary BY gender minority
  /WSFACTOR = time 2 Polynomial
  /EMMEANS = TABLES(gender*minority*time) COMPARE(gender)
  /WSDESIGN = time
  /DESIGN = gender minority gender*minority .

*///snytax to replace, sayfor example:*.
REGRESSION
  /STATISTICS COEFF
  /DEPENDENT salary
  /METHOD=ENTER salbegin jobtime.

*\\\\\ End of block of syntax to be replaced..................
*.
************************************************************ .
!enddefine .
************************************************************ .


************************************************************ .
* draw samples with replacement and run syntax commands
************************************************************ .
DEFINE bootstrap (
    samples=!TOKENS(1)
   /groupvar=!TOKENS(1) !DEFAULT('dummyvar')
   /groupsize=!TOKENS(1) !DEFAULT('')
   /syntax_parameters=!CMDEND !DEFAULT('')
).

************************************************************ .

/* This section computes the groupsize, or filesize */

/* if no size variable is given, compute group size */
!if (!groupsize !eq '') !then
!if (!groupvar !eq 'dummyvar') !then
COMPUTE dummyvar=1.
!else
SORT CASES BY !groupvar .
!ifend
AGGREGATE /OUTFILE=* MODE=ADDVARIABLES
 /BREAK=!groupvar
 /filesize=N.
!else
SORT CASES BY !groupvar .
compute filesize=!unquote(!groupsize) .
!ifend

/* Now compute the sample weights repeatedly */

!DO !other=1 !TO !samples
SET SEED RANDOM.
WEIGHT OFF.
FILTER OFF.
DO IF ($casenum=1) OR (!groupvar ~= LAG(!groupvar)).
- COMPUTE #samplesize=filesize.
- COMPUTE #filesize=filesize.
END IF.
DO IF (#samplesize>0 and #filesize>0).
- COMPUTE sampleWeight=rv.binom(#samplesize, 1/#filesize).
- COMPUTE #samplesize=#samplesize-sampleWeight.
- COMPUTE #filesize=#filesize-1.
ELSE.
- COMPUTE sampleWeight=0.
END IF.
WEIGHT BY sampleWeight.
FILTER BY sampleWeight.

/* Finally it's time to run the syntax */

syntax_macro
    sample_weight=sampleWeight
    groupvar=!groupvar
   !unquote(!syntax_parameters)
.

!DOEND
************************************************************ .
!enddefine.
************************************************************ .


************************************************************ .
* macro to simplify use of OMS.
************************************************************ .
define oms_macro(
    commands=!tokens(1)
   /subtypes=!tokens(1)
   /outfile=!tokens(1)
   /format=!tokens(1) !default('SAV')
).
************************************************************ .
OMS
 /SELECT TABLES
 /IF COMMANDS = [!quote(!unquote(!commands))]
     SUBTYPES = [!quote(!unquote(!subtypes))]
 /DESTINATION FORMAT = !unquote(!format)
  OUTFILE = !quote(!unquote(!outfile)) .
************************************************************ .
!enddefine.
************************************************************ .

/*** end macro definitions ***/


/*** use of the macros is illustrated below ***/




/*************************************************************/
* Run from here to end .
*.


*** if c:\temp is not a valid drive\path, replace all instances of c:\temp
with a valid drive\path ***.

/* ensure that the variable names in the files are what the syntax expects
*/
PRESERVE.
SET TVARS NAMES.
set mprint=on .

*** insert any valid path\data file name ***.
GET FILE='c:\Program Files\SPSS\Employee data.sav'.

/* Try the log to see if it helps make the variances equal */
compute salary = ln(salary) .
compute salbegin = ln(salbegin).
/* To sample from a balanced design, need a suitable group variable */
compute gender_by_minority = 2 * (gender='m') + minority .

compute sampleWeight = 1 .
execute.

/* Call syntax_macro to see what the output without sampling is */
syntax_macro
    sample_weight=sampleWeight
    groupvar=gender_by_minority
.


*** first OMS command just suppresses Viewer output ***.
OMS /DESTINATION VIEWER=NO /TAG='suppressall'.



*;),) and I#m not quite sure how to replace the OMS- commands**.

*** Now use the macro to divert any desired tables into files.

oms_macro
   commands=GLM
   subtypes="Tests of Within Subjects Contrasts"
   outfile="C:\temp\ws_effects.sav"
.

oms_macro
   commands=GLM
   SUBTYPES = "EMMEANS Pairwise Comparisons"
   OUTFILE = "C:\temp\emmeans.sav" .
.

oms_macro
  COMMANDS = "Frequencies"
  SUBTYPES = "Frequencies"
  OUTFILE = "c:\temp\temp_freq.sav"
.

/*
* Call the macro:
* always specify number of samples.
* If groupvar is not given, groupsize will apply to the entire file.
* If groupvar is given, groupsize will be computed for each of its values,
* unless groupsize is also given.
* In that case: if groupsize is a variable, the first value in each group
is used.
* If groupsize is a number, the same number wil be chosen from each group.
* For example, to get a balanced ANOVA design, construct a single groupvar
* from A and B; e.g. 2*A+B, and select an equal number from each.
*/

bootstrap
   samples=100
   groupvar=gender_by_minority
   groupsize=30
.

/* end all of the OMS requests and write the files */
OMSEND.


/* check to see if the within-subjects effects are significant */
GET FILE 'c:\temp\ws_effects.sav'.
SORT CASES BY Var1 .
SPLIT FILE
  LAYERED BY Var1 .
FREQUENCIES
  VARIABLES=F
  /FORMAT NOTABLE
  /PERCENTILES= 2.5 97.5
  /STATISTICS=MEAN MEDIAN
  /HISTOGRAM NORMAL.
FREQUENCIES
  VARIABLES=Sig
  /FORMAT NOTABLE
  /PERCENTILES= 2.5 97.5
  /STATISTICS=MEAN MEDIAN
  /HISTOGRAM NORMAL.

/* Check to see if there is a difference between groups */
GET FILE = 'c:\temp\emmeans.sav' .
SELECT IF(Var3 = 'Male').
EXECUTE .
SORT CASES BY Var1 Var2.
SPLIT FILE
  LAYERED BY Var1 Var2.
FREQUENCIES
  VARIABLES=MeanDifferenceIJ
  /FORMAT NOTABLE
  /PERCENTILES= 2.5 97.5
  /STATISTICS=MEAN MEDIAN
  /HISTOGRAM  NORMAL
  /ORDER=  ANALYSIS .
FREQUENCIES
  VARIABLES=Sig
  /FORMAT NOTABLE
  /PERCENTILES= 2.5 97.5
  /STATISTICS=MEAN MEDIAN
  /HISTOGRAM  NORMAL
  /ORDER=  ANALYSIS .



Has anyone got an idea??

Peter