Skip to content

Commit 9cef1d4

Browse files
committed
Version 1.0.3.
Version 1.0.3: Fixed a bug causing the Monte Carlo procedure to produce exactly the same dataset Version 1.0.2: Fixed the duplicates algorithm so that compares the two variable names that have been formatted to 8 characters or fewer using the "format_mplus" function Modified the "format_mplus" algorithm for formatting the Mplus variable names. Fixed a bug in the observed correlation tables that would not allow you to display variable names / labels. Version 1.0.1: Fixed bug in Fit Statistics tabular output where the DF and p were not displayed for the chi-square statistic Fixed a bug in which MEANS/INTERCEPTS/THRESHOLDS were not properly loaded from the sample statistics for categorical variables
1 parent 8c3293d commit 9cef1d4

18 files changed

+363
-263
lines changed

ArrayFunctions.bas

+22-22
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ Function ARRAY_RND(ByRef temp_array, target, ByRef temp_array2, wnum)
136136

137137
n = rand_between(1, num_instances)
138138

139-
ctr = 0
139+
Ctr = 0
140140
For a = 1 To UBound(temp_array, 1)
141-
If temp_array(a) = target And temp_array2(a) <> wnum Then ctr = ctr + 1
142-
If ctr = n Then
141+
If temp_array(a) = target And temp_array2(a) <> wnum Then Ctr = Ctr + 1
142+
If Ctr = n Then
143143
ARRAY_RND = a
144144
Exit Function
145145
End If
@@ -682,20 +682,20 @@ Function ARRAY_MULTIPLY(ByVal arr1, ByVal arr2, Optional formula = True)
682682

683683
For x = 1 To a2_x_len ' Move across new array column
684684
For y = 1 To a1_y_len ' Move across new array rows
685-
For c = 1 To a1_x_len ' Populate the cell
686-
Debug.Print "X:"; x; "of"; a2_x_len; "Y:"; y; "of"; a1_y_len; "Cell entry: "; c; "of"; a1_x_len
685+
For C = 1 To a1_x_len ' Populate the cell
686+
Debug.Print "X:"; x; "of"; a2_x_len; "Y:"; y; "of"; a1_y_len; "Cell entry: "; C; "of"; a1_x_len
687687
If formula = True Then
688688
Debug.Print "Providing formula as output"
689-
If c = 1 Then new_array(y, x) = "SUM("
690-
new_array(y, x) = new_array(y, x) & CStr(array1(y, c)) & "*" & CStr(array2(c, x))
691-
If c < a1_x_len Then
689+
If C = 1 Then new_array(y, x) = "SUM("
690+
new_array(y, x) = new_array(y, x) & CStr(array1(y, C)) & "*" & CStr(array2(C, x))
691+
If C < a1_x_len Then
692692
new_array(y, x) = new_array(y, x) & ","
693693
Else
694694
new_array(y, x) = new_array(y, x) & ")"
695695
End If
696696
Else
697-
If c = 1 Then new_array(y, x) = 0
698-
new_array(y, x) = new_array(y, x) + array1(y, c) * array2(c, x)
697+
If C = 1 Then new_array(y, x) = 0
698+
new_array(y, x) = new_array(y, x) + array1(y, C) * array2(C, x)
699699
End If
700700
Next
701701
Next
@@ -830,56 +830,56 @@ Function UNIQUE(data_range, Optional unique_case = 0)
830830
temp_data = data_range
831831
End If
832832

833-
c = 0
833+
C = 0
834834

835835
If n_cols > 0 Then
836836
For a = 1 To n_rows
837837
For b = 1 To n_cols
838838
If temp_data(a, b) <> "" Then
839-
If c > 0 Then
839+
If C > 0 Then
840840
found_match = False
841-
For d = 1 To c
841+
For d = 1 To C
842842
If temp_array(d) = temp_data(a, b) Then
843843
found_match = True
844844
Exit For
845845
End If
846846
Next
847847
If found_match = False Then
848-
temp_array(c + 1) = temp_data(a, b)
849-
c = c + 1
848+
temp_array(C + 1) = temp_data(a, b)
849+
C = C + 1
850850
End If
851851
Else
852852
temp_array(1) = temp_data(a, b)
853-
c = 1
853+
C = 1
854854
End If
855855
End If
856856
Next
857857
Next
858858
Else
859859
For a = 1 To n_rows
860860
If temp_data(a) <> "" Then
861-
If c > 0 Then
861+
If C > 0 Then
862862
found_match = False
863-
For d = 1 To c
863+
For d = 1 To C
864864
If temp_array(d) = temp_data(a) Then
865865
found_match = True
866866
Exit For
867867
End If
868868
Next
869869
If found_match = False Then
870-
temp_array(c + 1) = temp_data(a)
871-
c = c + 1
870+
temp_array(C + 1) = temp_data(a)
871+
C = C + 1
872872
End If
873873
Else
874874
temp_array(1) = temp_data(a)
875-
c = 1
875+
C = 1
876876
End If
877877
End If
878878
Next
879879
End If
880880

881881
If unique_case = 0 Then
882-
UNIQUE = c
882+
UNIQUE = C
883883
Else
884884
UNIQUE = temp_array(unique_case)
885885
End If

Form_CFATable.frx

0 Bytes
Binary file not shown.

Form_FactorCorrelations.frx

0 Bytes
Binary file not shown.

Form_FitStats.frx

0 Bytes
Binary file not shown.

Form_ObsMatrices.frx

0 Bytes
Binary file not shown.

Form_PathSEM.frx

0 Bytes
Binary file not shown.

GlobalVars.bas

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
Attribute VB_Name = "GlobalVars"
2+
' Version 1.0.3:
3+
' Fixed a bug causing the Monte Carlo procedure to produce exactly the same dataset
4+
5+
' Version 1.0.2:
6+
' Fixed the duplicates algorithm so that compares the two variable names that have been formatted to 8 characters or fewer using the "format_mplus" function
7+
' Modified the "format_mplus" algorithm for formatting the Mplus variable names.
8+
' Fixed a bug in the observed correlation tables that would not allow you to display variable names / labels.
9+
10+
' Version 1.0.1:
11+
' Fixed bug in Fit Statistics tabular output where the DF and p were not displayed for the chi-square statistic
12+
' Fixed a bug in which MEANS/INTERCEPTS/THRESHOLDS were not properly loaded from the sample statistics for categorical variables
13+
214
' Global variables
315

416
Public MplusOutput, DataStructure
@@ -8,6 +20,7 @@ Public use_formula
820
Public n_decimals ' Number of decimal places (1, 2, 3)
921
Public var_disp_mode ' 0: display variable name only, 1: display variable label, 2: display variable label and [name]
1022

23+
1124
Sub GotoSettings()
1225
Call ResetDefaults
1326
Settings.Show

InputForm.frx

0 Bytes
Binary file not shown.

InputForm_CFA.frx

0 Bytes
Binary file not shown.

Input_Create.bas

+17-16
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Sub CreateDataFile(data_object, ByVal data_filename, Optional export_to = "Mplus
8181
' If nreps > 1 then it generates a Monte Carlo dataset
8282

8383
Dim file_path: file_path = ActiveWorkbook.Path
84-
If file_path = "" Then file_path = MyDocsPath()
84+
If file_path = "" Or Left(file_path, 4) = "http" Then file_path = MyDocsPath()
8585

8686
If nreps > 1 Then ' Set up Monte Carlo file
8787
Open file_path & "\" & data_filename For Output As 1
@@ -96,6 +96,7 @@ Sub CreateDataFile(data_object, ByVal data_filename, Optional export_to = "Mplus
9696
Open file_path & "\" & STEM_FILE(data_filename) & a & ".csv" For Output As 1
9797
ActiveSheet.EnableCalculation = False
9898
ActiveSheet.EnableCalculation = True
99+
data_object.RefreshDatastructure
99100
Else
100101
Open file_path & "\" & STEM_FILE(data_filename) & ".csv" For Output As 1
101102
End If
@@ -112,20 +113,20 @@ Sub CreateDataFile(data_object, ByVal data_filename, Optional export_to = "Mplus
112113

113114
temp = ""
114115
For b = 1 To data_object.Cases_N
115-
For c = 1 To data_object.Variables_N
116-
temp_val = data_object.Dataset(b, c)
116+
For C = 1 To data_object.Variables_N
117+
temp_val = data_object.Dataset(b, C)
117118
If temp_val = data_object.MissingValue And export_to = "R" Then
118119
' If there is missing data and you are exporting to R, then write NA instead
119120
temp = temp & "NA"
120121
Else
121122
temp = temp & temp_val
122123
End If
123-
If c < data_object.Variables_N Then temp = temp & ","
124+
If C < data_object.Variables_N Then temp = temp & ","
124125
Next
125126
Print #1, temp
126127
temp = ""
127128
Next
128-
Close #1
129+
Close #1
129130
Next
130131

131132
End Sub
@@ -161,7 +162,7 @@ Sub CreateInputSyntax(data_object, _
161162

162163
' Locate the file path; if this fails, save to "My Documents"
163164
Dim file_path: file_path = ActiveWorkbook.Path
164-
If file_path = "" Then file_path = MyDocsPath()
165+
If file_path = "" Or Left(file_path, 4) = "http" Then file_path = MyDocsPath()
165166

166167
Dim y2: y2 = 0
167168
lb = Chr(10)
@@ -619,25 +620,25 @@ lb = Chr(10)
619620
If InputForm_CFA.BCFA_CL = True Then
620621
n_ind = 0
621622
For a = 1 To DataStructure.ScaleInclude
622-
For c = 1 To DataStructure.ScaleInclude
623-
If c = 1 Then
623+
For C = 1 To DataStructure.ScaleInclude
624+
If C = 1 Then
624625
temp_line = DataStructure.ScaleName(a, True) & " BY"
625626
Else
626627
temp_line = ""
627628
End If
628629
n_ind_line = 0
629-
For b = 1 To DataStructure.ScaleIndicator(c, 0, True)
630-
If a <> c Then
630+
For b = 1 To DataStructure.ScaleIndicator(C, 0, True)
631+
If a <> C Then
631632
n_ind_line = n_ind_line + 1
632633
End If
633-
temp_ind = format_mplus(DataStructure.ScaleIndicator(c, b, True))
634+
temp_ind = format_mplus(DataStructure.ScaleIndicator(C, b, True))
634635
If Len(temp_line) + Len(temp_ind) < 75 Then
635636
If Len(temp_line) > 0 Then temp_line = temp_line & " "
636637
temp_line = temp_line & temp_ind
637-
If a <> c And b = 1 Then temp_line = temp_line & "*"
638-
If a = c And c > 1 And b = 1 Then temp_line = temp_line & "@1"
638+
If a <> C And b = 1 Then temp_line = temp_line & "*"
639+
If a = C And C > 1 And b = 1 Then temp_line = temp_line & "@1"
639640
Else
640-
If a <> c Then
641+
If a <> C Then
641642
temp_line = temp_line & " (L" & n_ind + 1
642643
If n_ind_line > 1 Then
643644
temp_line = temp_line & "-L" & n_ind + n_ind_line - 1
@@ -654,15 +655,15 @@ lb = Chr(10)
654655

655656
model_syntax = model_syntax & temp_line
656657

657-
If a <> c Then
658+
If a <> C Then
658659
model_syntax = model_syntax & " (L" & n_ind + 1
659660
If n_ind_line > 1 Then
660661
model_syntax = model_syntax & "-L" & n_ind + n_ind_line
661662
End If
662663
model_syntax = model_syntax & ")"
663664
n_ind = n_ind + n_ind_line
664665
End If
665-
If c = DataStructure.ScaleInclude Then model_syntax = model_syntax & ";"
666+
If C = DataStructure.ScaleInclude Then model_syntax = model_syntax & ";"
666667
model_syntax = model_syntax & lb
667668
Next
668669
model_syntax = model_syntax & lb

LoadMplusOutput.frx

0 Bytes
Binary file not shown.

MiscFunctions.bas

+45-28
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,47 @@ Function format_mplus(ByVal orig_string)
1616
End If
1717
a = a + 1
1818
Loop
19-
19+
20+
' Mode 1: Simply return the variable name without modification
2021
If Len(orig_string) <= 8 Then
2122
orig_string = Replace(orig_string, " ", "_")
2223
format_mplus = orig_string
2324
Exit Function
2425
End If
25-
26+
2627
orig_string = auto_capital(orig_string)
2728
orig_string = Replace(orig_string, " ", "_")
2829

30+
' Mode 2: If there 3 or more words, then create a shortened name based on all words
31+
temp_array = Split(orig_string, "_")
32+
If UBound(temp_array) >= 2 Then
33+
Dim temp_array2()
34+
ReDim temp_array2(LBound(temp_array) To UBound(temp_array))
35+
cntr = 0
36+
temp_array2 = ARRAY_POPULATE(temp_array2, "")
37+
For a = 1 To 8
38+
For b = LBound(temp_array) To UBound(temp_array)
39+
temp = Mid(temp_array(b), a, 1)
40+
If a = 1 Then
41+
temp = UCase(temp)
42+
Else
43+
temp = LCase(temp)
44+
End If
45+
If cntr < 8 Then
46+
temp_array2(b) = temp_array2(b) & temp
47+
cntr = cntr + 1
48+
End If
49+
Next
50+
Next
51+
52+
format_mplus = ""
53+
For a = LBound(temp_array2) To UBound(temp_array2)
54+
format_mplus = format_mplus & temp_array2(a)
55+
Next
56+
Exit Function
57+
End If
58+
59+
' Mode 3: Try to reduce the string
2960
' Define a variable to count the length
3061
Dim len_cntr: len_cntr = 0
3162
Dim end_str
@@ -64,21 +95,10 @@ Function format_mplus(ByVal orig_string)
6495
' Capitalise the first letter if it's not a capital. This is needed to parse the number of capitalised words.
6596

6697
If Left(orig_string, 1) <> UCase(Left(orig_string, 1)) Then orig_string = UCase(Left(orig_string, 1)) & Right(orig_string, Len(orig_string) - 1)
67-
68-
' If item_id <> "" Then
69-
' b = InStr(1, orig_string, item_id) - 1
70-
' If b = 0 Then
71-
' orig_string = Replace(orig_string, item_id, "")
72-
' b = Len(orig_string)
73-
' End If
74-
' Else
75-
' b = Len(orig_string)
76-
' End If
77-
7898

79-
For c = 1 To Len(orig_string) + 1
99+
For C = 1 To Len(orig_string) + 1
80100
If Len(orig_string) > 2 Then
81-
If Mid(orig_string, Len(orig_string) - c, 1) = "_" Then
101+
If Mid(orig_string, Len(orig_string) - C, 1) = "_" Then
82102
junk = junk + 1
83103
Else
84104
Exit For
@@ -96,10 +116,6 @@ Function format_mplus(ByVal orig_string)
96116
num_lpw = Int(num_lr / num_wrds)
97117
'Debug.Print 4
98118

99-
'Debug.Print "'" & word_num(orig_string, 1, end_str) & "'"
100-
101-
'Debug.Print "Number of words: " & num_wrds & "; Num letters remaining: " & num_lr & ", Num letters per word: " & num_lpw
102-
103119
If num_wrds > num_lr Then
104120
' If the number of words more than the remaining number of letters, just use the first letter from each word
105121
For a = 1 To num_lr
@@ -423,21 +439,21 @@ Function CRONBACH_array(cellscopy, Optional format = True, Optional AboveDiag =
423439

424440
' Get covariances / correlations
425441
Dim covars()
426-
c = 1
442+
C = 1
427443

428444
ReDim covars(1 To (num_v ^ 2 - num_v) / 2)
429445
num_cv = UBound(covars)
430446
For a = 1 To num_v
431447
For b = 1 To a
432448
If AboveDiag = False Then
433449
If a <> b Then
434-
covars(c) = cellscopy(a, b)
435-
c = c + 1
450+
covars(C) = cellscopy(a, b)
451+
C = C + 1
436452
End If
437453
Else
438454
If a <> b Then
439-
covars(c) = cellscopy(b, a)
440-
c = c + 1
455+
covars(C) = cellscopy(b, a)
456+
C = C + 1
441457
End If
442458
End If
443459
Next
@@ -525,7 +541,7 @@ Function t_to_r(t, n)
525541
t_to_r = (Abs(t) / t) * Sqr((t ^ 2) / ((t ^ 2) + n - 2))
526542
End Function
527543

528-
Function crit_val_asterisk(r, n)
544+
Function crit_val_asterisk(R, n)
529545
If n = 0 Then
530546
crit_val_asterisk = ""
531547
Exit Function
@@ -538,9 +554,9 @@ Function crit_val_asterisk(r, n)
538554
r01 = t_to_r(t01, n)
539555
r001 = t_to_r(t001, n)
540556

541-
If Abs(r) > r05 Then crit_val_asterisk = "*"
542-
If Abs(r) > r01 Then crit_val_asterisk = "**"
543-
If Abs(r) > r001 Then crit_val_asterisk = "***"
557+
If Abs(R) > r05 Then crit_val_asterisk = "*"
558+
If Abs(R) > r01 Then crit_val_asterisk = "**"
559+
If Abs(R) > r001 Then crit_val_asterisk = "***"
544560
End Function
545561

546562
Function IsArrayAllocated(arr As Variant) As Boolean
@@ -692,3 +708,4 @@ Sub dump_matrix()
692708
Next
693709
Next
694710
End Sub
711+

Output_FitStats.bas

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Sub WriteModelFit(MplusOutput, _
191191
Cells(start_y + offset_y, start_x + offset_x) = MplusOutput.ChiSq
192192
Cells(start_y + offset_y, start_x + offset_x + 1) = MplusOutput.DF
193193
Cells(start_y + offset_y, start_x + offset_x + 2) = format(MplusOutput.ChiSqP, ".000")
194-
offset_x = offset_x + 1
194+
offset_x = offset_x + 3
195195
End If
196196
If CFI = True And MplusOutput.CFI <> Empty Then
197197
If heading = True Then Cells(start_y, start_x + offset_x) = "CFI"

0 commit comments

Comments
 (0)