MLPowSim macro not working in MLWin

Welcome to the forum for MLwiN users. Feel free to post your question about MLwiN software here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Remember to check out our extensive software FAQs which may answer your question: http://www.bristol.ac.uk/cmm/software/s ... port-faqs/
Post Reply
MichaelCMichaelC
Posts: 1
Joined: Wed Feb 21, 2018 10:25 am

MLPowSim macro not working in MLWin

Post by MichaelCMichaelC »

Hello,
I am trying to run script created by MLPowSim in MLWin, however, for the most part, I get error messages and interpretable output. I have tried a number of specifications but very few have worked. I'll concentrate on explaining one here, as it seems to me that the same issues are likely behind the problems with all the specifications.

The model
I'm trying to retrospectively determine the sample size just to understand how I can use it for future projects. The original model had a normal dependent variable (ability), four independent variables (location, specialisation, gender, state - first three binary, the last is categorical with 16 levels) and three levels (school, class and student).

The state independent variable was converted into 16 binary variables. I couldn't see any other way to account for this in MLPowSim. However, if there is another way, I'd be interested to know.

MLPowSim simu.txt
For this run, I removed 4 binary variables representing levels of State because they had a very small effect size. The code is:

MARK 0
NOTE MLwiN macro code generated by MLPowSim
NOTE This is outer code to be run directly in MLwiN
NOTE You will also need simu2.txt, simu3.txt, setup.txt and analyse.txt
SEED 1
ERASE C590-C598
NOTE setup the values of beta, sigma2u, sigma2e etc.
JOIN C598 50.300000 C598
JOIN C598 4.290000 C598
JOIN C598 -12.260000 C598
JOIN C598 0.230000 C598
JOIN C598 -2.290000 C598
JOIN C598 -2.350000 C598
JOIN C598 4.550000 C598
JOIN C598 -4.620000 C598
JOIN C598 3.440000 C598
JOIN C598 -1.530000 C598
JOIN C598 -2.830000 C598
JOIN C598 1.730000 C598
JOIN C598 -2.000000 C598
JOIN C598 -4.300000 C598
JOIN C598 6.620000 C598
JOIN C598 3.210000 C598
JOIN C596 135.850000 C596
NAME c208 "N-level 3"
NAME c209 "N-level 1"
NAME c210 "N-level 2"
NAME c211 "zpow0" c231 "spow0"
NAME c251 "zlow0" c291 "slow0"
NAME c271 "zupp0" c311 "supp0"
NAME c212 "zpow1" c232 "spow1"
NAME c252 "zlow1" c292 "slow1"
NAME c272 "zupp1" c312 "supp1"
NAME c213 "zpow2" c233 "spow2"
NAME c253 "zlow2" c293 "slow2"
NAME c273 "zupp2" c313 "supp2"
NAME c214 "zpow3" c234 "spow3"
NAME c254 "zlow3" c294 "slow3"
NAME c274 "zupp3" c314 "supp3"
NAME c215 "zpow4" c235 "spow4"
NAME c255 "zlow4" c295 "slow4"
NAME c275 "zupp4" c315 "supp4"
NAME c216 "zpow5" c236 "spow5"
NAME c256 "zlow5" c296 "slow5"
NAME c276 "zupp5" c316 "supp5"
NAME c217 "zpow6" c237 "spow6"
NAME c257 "zlow6" c297 "slow6"
NAME c277 "zupp6" c317 "supp6"
NAME c218 "zpow7" c238 "spow7"
NAME c258 "zlow7" c298 "slow7"
NAME c278 "zupp7" c318 "supp7"
NAME c219 "zpow8" c239 "spow8"
NAME c259 "zlow8" c299 "slow8"
NAME c279 "zupp8" c319 "supp8"
NAME c220 "zpow9" c240 "spow9"
NAME c260 "zlow9" c300 "slow9"
NAME c280 "zupp9" c320 "supp9"
NAME c221 "zpow10" c241 "spow10"
NAME c261 "zlow10" c301 "slow10"
NAME c281 "zupp10" c321 "supp10"
NAME c222 "zpow11" c242 "spow11"
NAME c262 "zlow11" c302 "slow11"
NAME c282 "zupp11" c322 "supp11"
NAME c223 "zpow12" c243 "spow12"
NAME c263 "zlow12" c303 "slow12"
NAME c283 "zupp12" c323 "supp12"
NAME c224 "zpow13" c244 "spow13"
NAME c264 "zlow13" c304 "slow13"
NAME c284 "zupp13" c324 "supp13"
NAME c225 "zpow14" c245 "spow14"
NAME c265 "zlow14" c305 "slow14"
NAME c285 "zupp14" c325 "supp14"
NAME c226 "zpow15" c246 "spow15"
NAME c266 "zlow15" c306 "slow15"
NAME c286 "zupp15" c326 "supp15"
CALC b41 = 1000
LOOP b30 100 600 100
OBEY simu2.txt
ENDL


Analyse.txt
NOTE MLwiN macro code generated by MLPowSim
CODE 17 1 b41 c30
CODE 137 1 b41 c31
SPLIT c1011 c30 c51-c67
SPLIT c1012 c31 c101-c237
NOTE calculate IGLS interval coverage
NED 0.975000 b42
JOIN c208 b30 c208
JOIN c209 b21 c209
JOIN c210 b22 c210
CALC c101 = c101*(c101>0) - c101*(c101<0)
CALC c101 = sqrt(c101)
CALC c200= c51 - b42*c101
CALC c201= c200>0
AVER c201 b202 b203 b204
JOIN c211 b203 c211
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c251 b205 c251
CALC b205 = b203+b42*sqrt(b204)
JOIN c271 b205 c271
CALC c103 = c103*(c103>0) - c103*(c103<0)
CALC c103 = sqrt(c103)
CALC c200= c52 - b42*c103
CALC c201= c200>0
AVER c201 b202 b203 b204
JOIN c212 b203 c212
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c252 b205 c252
CALC b205 = b203+b42*sqrt(b204)
JOIN c272 b205 c272
CALC c106 = c106*(c106>0) - c106*(c106<0)
CALC c106 = sqrt(c106)
CALC c200= c53 + b42*c106
CALC c201= c200<0
AVER c201 b202 b203 b204
JOIN c213 b203 c213
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c253 b205 c253
CALC b205 = b203+b42*sqrt(b204)
JOIN c273 b205 c273
CALC c110 = c110*(c110>0) - c110*(c110<0)
CALC c110 = sqrt(c110)
CALC c200= c54 - b42*c110
CALC c201= c200>0
AVER c201 b202 b203 b204
JOIN c214 b203 c214
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c254 b205 c254
CALC b205 = b203+b42*sqrt(b204)
JOIN c274 b205 c274
CALC c115 = c115*(c115>0) - c115*(c115<0)
CALC c115 = sqrt(c115)
CALC c200= c55 + b42*c115
CALC c201= c200<0
AVER c201 b202 b203 b204
JOIN c215 b203 c215
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c255 b205 c255
CALC b205 = b203+b42*sqrt(b204)
JOIN c275 b205 c275
CALC c121 = c121*(c121>0) - c121*(c121<0)
CALC c121 = sqrt(c121)
CALC c200= c56 + b42*c121
CALC c201= c200<0
AVER c201 b202 b203 b204
JOIN c216 b203 c216
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c256 b205 c256
CALC b205 = b203+b42*sqrt(b204)
JOIN c276 b205 c276
CALC c128 = c128*(c128>0) - c128*(c128<0)
CALC c128 = sqrt(c128)
CALC c200= c57 - b42*c128
CALC c201= c200>0
AVER c201 b202 b203 b204
JOIN c217 b203 c217
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c257 b205 c257
CALC b205 = b203+b42*sqrt(b204)
JOIN c277 b205 c277
CALC c136 = c136*(c136>0) - c136*(c136<0)
CALC c136 = sqrt(c136)
CALC c200= c58 + b42*c136
CALC c201= c200<0
AVER c201 b202 b203 b204
JOIN c218 b203 c218
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c258 b205 c258
CALC b205 = b203+b42*sqrt(b204)
JOIN c278 b205 c278
CALC c145 = c145*(c145>0) - c145*(c145<0)
CALC c145 = sqrt(c145)
CALC c200= c59 - b42*c145
CALC c201= c200>0
AVER c201 b202 b203 b204
JOIN c219 b203 c219
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c259 b205 c259
CALC b205 = b203+b42*sqrt(b204)
JOIN c279 b205 c279
CALC c155 = c155*(c155>0) - c155*(c155<0)
CALC c155 = sqrt(c155)
CALC c200= c60 + b42*c155
CALC c201= c200<0
AVER c201 b202 b203 b204
JOIN c220 b203 c220
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c260 b205 c260
CALC b205 = b203+b42*sqrt(b204)
JOIN c280 b205 c280
CALC c166 = c166*(c166>0) - c166*(c166<0)
CALC c166 = sqrt(c166)
CALC c200= c61 + b42*c166
CALC c201= c200<0
AVER c201 b202 b203 b204
JOIN c221 b203 c221
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c261 b205 c261
CALC b205 = b203+b42*sqrt(b204)
JOIN c281 b205 c281
CALC c178 = c178*(c178>0) - c178*(c178<0)
CALC c178 = sqrt(c178)
CALC c200= c62 - b42*c178
CALC c201= c200>0
AVER c201 b202 b203 b204
JOIN c222 b203 c222
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c262 b205 c262
CALC b205 = b203+b42*sqrt(b204)
JOIN c282 b205 c282
CALC c191 = c191*(c191>0) - c191*(c191<0)
CALC c191 = sqrt(c191)
CALC c200= c63 + b42*c191
CALC c201= c200<0
AVER c201 b202 b203 b204
JOIN c223 b203 c223
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c263 b205 c263
CALC b205 = b203+b42*sqrt(b204)
JOIN c283 b205 c283
CALC c205 = c205*(c205>0) - c205*(c205<0)
CALC c205 = sqrt(c205)
CALC c200= c64 + b42*c205
CALC c201= c200<0
AVER c201 b202 b203 b204
JOIN c224 b203 c224
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c264 b205 c264
CALC b205 = b203+b42*sqrt(b204)
JOIN c284 b205 c284
CALC c220 = c220*(c220>0) - c220*(c220<0)
CALC c220 = sqrt(c220)
CALC c200= c65 - b42*c220
CALC c201= c200>0
AVER c201 b202 b203 b204
JOIN c225 b203 c225
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c265 b205 c265
CALC b205 = b203+b42*sqrt(b204)
JOIN c285 b205 c285
CALC c236 = c236*(c236>0) - c236*(c236<0)
CALC c236 = sqrt(c236)
CALC c200= c66 - b42*c236
CALC c201= c200>0
AVER c201 b202 b203 b204
JOIN c226 b203 c226
CALC b204 = (b203)*(1-b203)/b41
CALC b205 = b203-b42*sqrt(b204)
JOIN c266 b205 c266
CALC b205 = b203+b42*sqrt(b204)
JOIN c286 b205 c286
NOTE calculate IGLS SE method
AVER c101 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=50.300000/b203
CALC b203 = (-1)*b203+b42
CALC b206=50.300000/b206
CALC b206 = (-1)*b206+b42
CALC b207=50.300000/b207
CALC b207 = (-1)*b207+b42
NPRO b203 b204
JOIN c231 b204 c231
NPRO b206 b204
JOIN c291 b204 c291
NPRO b207 b204
JOIN c311 b204 c311
AVER c103 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=4.290000/b203
CALC b203 = (-1)*b203+b42
CALC b206=4.290000/b206
CALC b206 = (-1)*b206+b42
CALC b207=4.290000/b207
CALC b207 = (-1)*b207+b42
NPRO b203 b204
JOIN c232 b204 c232
NPRO b206 b204
JOIN c292 b204 c292
NPRO b207 b204
JOIN c312 b204 c312
AVER c106 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=(-12.260000)/b203
CALC b203 = b203+b42
CALC b206=(-12.260000)/b206
CALC b206 = b206+b42
CALC b207=(-12.260000)/b207
CALC b207 = b207+b42
NPRO b203 b204
JOIN c233 b204 c233
NPRO b206 b204
JOIN c293 b204 c293
NPRO b207 b204
JOIN c313 b204 c313
AVER c110 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=0.230000/b203
CALC b203 = (-1)*b203+b42
CALC b206=0.230000/b206
CALC b206 = (-1)*b206+b42
CALC b207=0.230000/b207
CALC b207 = (-1)*b207+b42
NPRO b203 b204
JOIN c234 b204 c234
NPRO b206 b204
JOIN c294 b204 c294
NPRO b207 b204
JOIN c314 b204 c314
AVER c115 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=(-2.290000)/b203
CALC b203 = b203+b42
CALC b206=(-2.290000)/b206
CALC b206 = b206+b42
CALC b207=(-2.290000)/b207
CALC b207 = b207+b42
NPRO b203 b204
JOIN c235 b204 c235
NPRO b206 b204
JOIN c295 b204 c295
NPRO b207 b204
JOIN c315 b204 c315
AVER c121 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=(-2.350000)/b203
CALC b203 = b203+b42
CALC b206=(-2.350000)/b206
CALC b206 = b206+b42
CALC b207=(-2.350000)/b207
CALC b207 = b207+b42
NPRO b203 b204
JOIN c236 b204 c236
NPRO b206 b204
JOIN c296 b204 c296
NPRO b207 b204
JOIN c316 b204 c316
AVER c128 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=4.550000/b203
CALC b203 = (-1)*b203+b42
CALC b206=4.550000/b206
CALC b206 = (-1)*b206+b42
CALC b207=4.550000/b207
CALC b207 = (-1)*b207+b42
NPRO b203 b204
JOIN c237 b204 c237
NPRO b206 b204
JOIN c297 b204 c297
NPRO b207 b204
JOIN c317 b204 c317
AVER c136 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=(-4.620000)/b203
CALC b203 = b203+b42
CALC b206=(-4.620000)/b206
CALC b206 = b206+b42
CALC b207=(-4.620000)/b207
CALC b207 = b207+b42
NPRO b203 b204
JOIN c238 b204 c238
NPRO b206 b204
JOIN c298 b204 c298
NPRO b207 b204
JOIN c318 b204 c318
AVER c145 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=3.440000/b203
CALC b203 = (-1)*b203+b42
CALC b206=3.440000/b206
CALC b206 = (-1)*b206+b42
CALC b207=3.440000/b207
CALC b207 = (-1)*b207+b42
NPRO b203 b204
JOIN c239 b204 c239
NPRO b206 b204
JOIN c299 b204 c299
NPRO b207 b204
JOIN c319 b204 c319
AVER c155 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=(-1.530000)/b203
CALC b203 = b203+b42
CALC b206=(-1.530000)/b206
CALC b206 = b206+b42
CALC b207=(-1.530000)/b207
CALC b207 = b207+b42
NPRO b203 b204
JOIN c240 b204 c240
NPRO b206 b204
JOIN c300 b204 c300
NPRO b207 b204
JOIN c320 b204 c320
AVER c166 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=(-2.830000)/b203
CALC b203 = b203+b42
CALC b206=(-2.830000)/b206
CALC b206 = b206+b42
CALC b207=(-2.830000)/b207
CALC b207 = b207+b42
NPRO b203 b204
JOIN c241 b204 c241
NPRO b206 b204
JOIN c301 b204 c301
NPRO b207 b204
JOIN c321 b204 c321
AVER c178 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=1.730000/b203
CALC b203 = (-1)*b203+b42
CALC b206=1.730000/b206
CALC b206 = (-1)*b206+b42
CALC b207=1.730000/b207
CALC b207 = (-1)*b207+b42
NPRO b203 b204
JOIN c242 b204 c242
NPRO b206 b204
JOIN c302 b204 c302
NPRO b207 b204
JOIN c322 b204 c322
AVER c191 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=(-2.000000)/b203
CALC b203 = b203+b42
CALC b206=(-2.000000)/b206
CALC b206 = b206+b42
CALC b207=(-2.000000)/b207
CALC b207 = b207+b42
NPRO b203 b204
JOIN c243 b204 c243
NPRO b206 b204
JOIN c303 b204 c303
NPRO b207 b204
JOIN c323 b204 c323
AVER c205 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=(-4.300000)/b203
CALC b203 = b203+b42
CALC b206=(-4.300000)/b206
CALC b206 = b206+b42
CALC b207=(-4.300000)/b207
CALC b207 = b207+b42
NPRO b203 b204
JOIN c244 b204 c244
NPRO b206 b204
JOIN c304 b204 c304
NPRO b207 b204
JOIN c324 b204 c324
AVER c220 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=6.620000/b203
CALC b203 = (-1)*b203+b42
CALC b206=6.620000/b206
CALC b206 = (-1)*b206+b42
CALC b207=6.620000/b207
CALC b207 = (-1)*b207+b42
NPRO b203 b204
JOIN c245 b204 c245
NPRO b206 b204
JOIN c305 b204 c305
NPRO b207 b204
JOIN c325 b204 c325
AVER c236 b202 b203 b204 b205
CALC b206= b203+b42*b205
CALC b207= b203-b42*b205
CALC b203=3.210000/b203
CALC b203 = (-1)*b203+b42
CALC b206=3.210000/b206
CALC b206 = (-1)*b206+b42
CALC b207=3.210000/b207
CALC b207 = (-1)*b207+b42
NPRO b203 b204
JOIN c246 b204 c246
NPRO b206 b204
JOIN c306 b204 c306
NPRO b207 b204
JOIN c326 b204 c326


The error message
Error detected by MLN
error while obeying batch file analysis.txt at line number 167:
CALC c200= c65 - b42*c220
Error in arithmetic expression

Output
The following columns contained a seemingly random range of numbers (including -ve). I was expecting incrementally increasing numbers of units at each level.

NAME c208 "N-level 3"
NAME c209 "N-level 1"
NAME c210 "N-level 2"

The corresponding Power estimates were also similar and not what I was expecting.

thanks for any help,

Michael
billb
Posts: 157
Joined: Fri May 21, 2010 1:21 pm

Re: MLPowSim macro not working in MLWin

Post by billb »

Hi Michael,
Thanks for the query. Always good to hear people using MLPowSim even if they aren't having much success. I can't really diagnose the issue as you have only sent some of the files through and I suspect setup.txt is the one to look at.
I wonder whether the issue is the number of state categories which involves 15 dummies? If so and the category is being randomly generated then with your lowest sample size of 100 I suspect there is a real possibility of generating samples that do not include individuals in all 16 categories and thus you may end up with an X variable that is a column of zeros that might cause problems in model fitting etc.
Either that or possibly the software hasn't been tested with so many categories and you are experiencing a column overwrite where a column has been mistakenly used twice.
If you want to send me (william.browne@bristol.ac.uk) your script files I'll see if I or Chris Charlton can take a look.
Best wishes,
Bill.
adam80090
Posts: 2
Joined: Sat May 12, 2018 6:50 am

Re: MLPowSim macro not working in MLWin

Post by adam80090 »

HI bilb
I (efficaciously) ran a multinomial model, then cleared the Equations window and set up a binomial version. when I pressed begin, I were given an errors message which said:

"error even as obeying batch record C:program FilesMLwiN v2.10discretepre at line number eleven: name c1180 'H' C1181 'F~(H)' C1182 'H*' C1183 'P' c1184 'mask' c1189 'Y-VAR'
reproduction column name."

this error message takes place because whilst MLwiN estimates a binomial or multinomial version, it sets up some special columns inside the worksheet. while it does this it offers them certain names. The names for the columns used while strolling a multinomial model are P, -P, H, F~(H), H*, Pi and Y-VAR, and these occupy c1178 to c1183 and c1189. when the model is cleared, those columns are not deleted. If some other multinomial version is installation and run, c1178 to c1183 and c1189 get given these names once more. this doesn't cause a problem because the same column is being given the same call. but, if rather a binomial version is installation and run, the names and locations of some of the unique columns are one of a kind: H, F~(H), H*, P and Y-VAR are put in c1180 to c1183 and c1189. while MLwiN attempts to give those names to these columns, it discovers that P is already the name of c1178. considering the fact that there cannot be two columns with the identical name, the mistake message is produced.

To solve the hassle, when you clean the Equations window truely scroll down within the Names window to discover c1178 to c1189, spotlight those columns and select the Delete button at the top of the window. This gets rid of the contents of the columns and renames them c1178, c1179, and so on. while you set up and run the binomial model MLwiN is then able to properly create the unique columns it desires.
billb
Posts: 157
Joined: Fri May 21, 2010 1:21 pm

Re: MLPowSim macro not working in MLWin

Post by billb »

Hi Adam80090,
I'll pass that on to my colleague Chris Charlton as I am sure we can probably fix this in the software - I wrote the MCMC functionality but not the core code so this one will be in Chris's domain.
Thanks for pointing it out.
Bill.
Post Reply