自动增加使用 SPSS 语法和宏选择的随机案例数
Automatically increase number of random cases selected with SPSS syntax and macros
我试图强制 SPSS 进行伪 Monte Carlo 研究。真实世界的数据太奇怪了,我无法可靠地模拟它(如果你有兴趣,它是用来测试伤害严重程度分数的)。因此,我使用了一个包含大约 50 万个真实世界数据观察结果的数据集,然后基本上从越来越大的随机样本中引导结果。目标是找出假设正态性所必需的组大小(在什么组大小下 t 检验和 Mann-Whitney U 检验可靠地一致;换句话说,我什么时候可以指望中心极限定理)。
我的计划是使用宏的组合来重复这两个测试 100 次(但是 运行 150 次以防随机 selection 导致组大小为零),然后使用 OMS 命令将大量测试的结果导出到单独的数据文件中。
到目前为止,一切正常,但是,我想再次向 运行 该过程添加另一个循环命令,但 select 更多随机情况。因此,它会 运行 150 次,每次有 10 个随机案例 selected,然后,在 运行 前 150 个之后,它会 运行 另一个 150 但 select 20 个随机案例。最理想的情况是这样的:
Select 10 个随机案例
运行 t 检验和 Mann-Whitney U 检验
重复150次
Select 20个随机案例
运行 t 检验和 Mann-Whitney U 检验
重复150次
...
(运行宁200例后,现在增加50)
Select 250 个随机案例
运行 t 检验和 Mann-Whitney U 检验
重复150次
Select 300 个随机案例
...
Select 800 个随机案例
运行 t 检验和 Mann-Whitney U 检验
重复150次
(在 运行ning 800 个案例后停止)
使用 OMS 保存所有这些结果
以下语法中的所有内容都完美无缺,除了一个小问题,我不知道如何让它增加随机样本的大小,我宁愿不要手动这样做。
即使我必须手动完成,有没有办法将最新结果附加到现有文件而不是替换现有文件?
DEFINE !repeater().
!DO !i=1 !TO 150.
*repeat the below processes 150 times
*select a random sample from the dataset
DATASET ACTIVATE DataSet1.
USE ALL.
do if $casenum=1.
compute #s_$_1=10.
compute #s_$_2=565518.
* 565518 is the total number of cases
end if.
do if #s_$_2 > 0.
compute filter_$=uniform(1)* #s_$_2 < #s_$_1.
compute #s_$_1=#s_$_1 - filter_$.
compute #s_$_2=#s_$_2 - 1.
else.
compute filter_$=0.
end if.
VARIABLE LABELS filter_$ 'x random cases (SAMPLE)'.
FORMATS filter_$ (f1.0).
FILTER BY filter_$.
EXECUTE.
*run a non-parametric test
NPAR TESTS
/M-W= issloc BY TwoGroups(0 1)
/MISSING ANALYSIS.
*run a parametric test
T-TEST GROUPS=TwoGroups(0 1)
/MISSING=ANALYSIS
/VARIABLES=issloc
/CRITERIA=CI(.95).
!DOEND.
!ENDDEFINE.
*use OMS to extract the reported descriptives and results from the viewer
*and save them to a file
OMS /SELECT TABLES
/DESTINATION FORMAT = SAV OUTFILE = 'folder/folder/OMS file.sav'
/IF SUBTYPES=['Mann Whitney Ranks' 'Mann Whitney Test Statistics' 'Group Statistics' 'Independent Samples Test']
/COLUMNS SEQUENCE = [RALL CALL LALL].
!repeater.
OMSEND.
没关系。答案很明显,我完全错过了。我只需要在宏中定义样本大小选择。 *捂脸
我试图强制 SPSS 进行伪 Monte Carlo 研究。真实世界的数据太奇怪了,我无法可靠地模拟它(如果你有兴趣,它是用来测试伤害严重程度分数的)。因此,我使用了一个包含大约 50 万个真实世界数据观察结果的数据集,然后基本上从越来越大的随机样本中引导结果。目标是找出假设正态性所必需的组大小(在什么组大小下 t 检验和 Mann-Whitney U 检验可靠地一致;换句话说,我什么时候可以指望中心极限定理)。
我的计划是使用宏的组合来重复这两个测试 100 次(但是 运行 150 次以防随机 selection 导致组大小为零),然后使用 OMS 命令将大量测试的结果导出到单独的数据文件中。
到目前为止,一切正常,但是,我想再次向 运行 该过程添加另一个循环命令,但 select 更多随机情况。因此,它会 运行 150 次,每次有 10 个随机案例 selected,然后,在 运行 前 150 个之后,它会 运行 另一个 150 但 select 20 个随机案例。最理想的情况是这样的:
Select 10 个随机案例
运行 t 检验和 Mann-Whitney U 检验
重复150次
Select 20个随机案例
运行 t 检验和 Mann-Whitney U 检验
重复150次
...
(运行宁200例后,现在增加50)
Select 250 个随机案例
运行 t 检验和 Mann-Whitney U 检验
重复150次
Select 300 个随机案例
...
Select 800 个随机案例
运行 t 检验和 Mann-Whitney U 检验
重复150次
(在 运行ning 800 个案例后停止)
使用 OMS 保存所有这些结果
以下语法中的所有内容都完美无缺,除了一个小问题,我不知道如何让它增加随机样本的大小,我宁愿不要手动这样做。
即使我必须手动完成,有没有办法将最新结果附加到现有文件而不是替换现有文件?
DEFINE !repeater().
!DO !i=1 !TO 150.
*repeat the below processes 150 times
*select a random sample from the dataset
DATASET ACTIVATE DataSet1.
USE ALL.
do if $casenum=1.
compute #s_$_1=10.
compute #s_$_2=565518.
* 565518 is the total number of cases
end if.
do if #s_$_2 > 0.
compute filter_$=uniform(1)* #s_$_2 < #s_$_1.
compute #s_$_1=#s_$_1 - filter_$.
compute #s_$_2=#s_$_2 - 1.
else.
compute filter_$=0.
end if.
VARIABLE LABELS filter_$ 'x random cases (SAMPLE)'.
FORMATS filter_$ (f1.0).
FILTER BY filter_$.
EXECUTE.
*run a non-parametric test
NPAR TESTS
/M-W= issloc BY TwoGroups(0 1)
/MISSING ANALYSIS.
*run a parametric test
T-TEST GROUPS=TwoGroups(0 1)
/MISSING=ANALYSIS
/VARIABLES=issloc
/CRITERIA=CI(.95).
!DOEND.
!ENDDEFINE.
*use OMS to extract the reported descriptives and results from the viewer
*and save them to a file
OMS /SELECT TABLES
/DESTINATION FORMAT = SAV OUTFILE = 'folder/folder/OMS file.sav'
/IF SUBTYPES=['Mann Whitney Ranks' 'Mann Whitney Test Statistics' 'Group Statistics' 'Independent Samples Test']
/COLUMNS SEQUENCE = [RALL CALL LALL].
!repeater.
OMSEND.
没关系。答案很明显,我完全错过了。我只需要在宏中定义样本大小选择。 *捂脸