Rim weighting example
In the target weighting examples in the previous topics, we have known the targets for each cell in the weighting matrix. You use rim weighting (see
Rim weighting when you do not have this information. For example, when you want to base your weighting on the following information:
▪A 50:50 balance of male and female respondents (gender variable).
▪A 75:25 balance of respondents who live in this country and those who do not live in this country (resident variable)
▪Targets for the various age groups as shown in the following table (age variable).
Age group
|
Target
|
11-16 years
|
50
|
17-20 years
|
100
|
21-24 years
|
100
|
25-34 years
|
200
|
35-44 years
|
100
|
45-54 years
|
50
|
55-64 years
|
30
|
65+ years
|
15
|
Here is the mrScriptBasic code to set up the weighting in a variable,
Weight, that must already exist. You will get an error if you attempt to run the example when this variable does not exist. (For an example that creates this variable, see
Creating a new variable to hold the weighting information.)
' This script weights the files created by Weight1a.mrs
' and Weight1b.mrs
Dim MDM2, WgtEng, Wgt, fso, ReptFile
' Create the MDM object
Set MDM2 = CreateObject("MDM.Document")
' Open the .mdd file created by Weight1a.mrs MDM2.Open("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\
Output\museum_weight.mdd")
' Create an instance of the Weight Engine object
Set WgtEng = CreateObject("mrWeight.WeightEngine")
WgtEng.Initialize(MDM2)
Set Wgt = WgtEng.CreateWeight("Weight", "gender, age,
resident", 3)
Set fso = CreateObject("Scripting.FileSystemObject")
Set ReptFile = fso.CreateTextFile("C:\Program Files\IBM\SPSS\
DataCollection\7\DDL\Output\Weight5.htm", True)
Wgt.Rims["gender"].Targets = "50; 50"
Wgt.Rims["age"].Targets = "50; 100; 100; 200; 100; 50; 30; 15"
Wgt.Rims["resident"].RimElements[0].Target = "75"
Wgt.Rims["resident"].RimElements[1].Target = "25"
Wgt.Rims["resident"].RimElements[2].Target = "0"
Wgt.TotalType = 2
WgtEng.Prepare(Wgt)
ReptFile.Write(Wgt.Report)
WgtEng.Execute(Wgt)
ReptFile.Write(Wgt.Report)
ReptFile.Close()
' Close the database connection and flush pending data updates
Set WgtEng = Null MDM2.Close()
In the line Set Wgt = WgtEng.CreateWeight("Weight", "gender, age, resident", 3), 3 defines the weighting method as rim weighting.
The line Wgt.TotalType = 2 specifies that the weighted total should be based on the unweighted total. If we had not included this line, the weighted total would have been set to 100, which is the sum of the targets defined for the first variable specified (gender).
Here is a table of resident by gender run on the Museum example data weighted using the weight variable:
There are some options that are specific to rim weighting. For example, by default, the weighting report (see
Weighting report) shows the weights that are calculated by the final iteration of the rim weighting algorithm. However, you can make it report the weights that are calculated by each iteration by including the following line in your script:
Wgt.RimReportInDetail = True
This example is in the UNICOM Intelligence Developer Documentation Library as a sample script called Weight5.mrs. For more information, see
Sample mrScriptBasic files.
Requirements
UNICOM Intelligence Professional
See also