Names default to here(1); Clear Log(); lbwidth=130; dt1=current data table(); if(Not(Is Scriptable(dt1)), dtsel=Pick File("Open File",{"JMP|jmp","All files|*"}); If(dtsel == "", stop(), Try(dt1=Open(dtsel), stop()) ); ); ncdt1 = N Cols(dt1); nrdt1= N Cols(dt1); Dia_Window = Expr( // Window to get list of factors and response; colnames=dt1 << Get Column Names("string"); Try(Is Scriptable(TimeCol); _exist=1, _exist=0;); If(_exist,_out1=contains(colnames, TimeCol[1]), _out=0); pcol=0; If(N Items(colnames) > 2, For(ii=1, ii <= N Items(colnames), ii++, If(contains(Colnames[ii],"Prediction"), Pcol=ii); ); ); if(pcol > 0, post3 = Eval List({column(pcol) << get name}); pcolpos=contains(Colnames[pcol],"Prediction"); PredCol = Eval List({substr(post3[1],1,pcolpos-2)}); ); Main_dlg = New Window( "Make Before / After Indicators for:", Tab Box( "Indicator Columns", Eval(Tab1), "Groups from GenReg Prediction Formula", Eval(Tab2) ), Text Box("Written By Tony Cooper") ); Try(InList1 << Append( TimeCol[1])); Try(InList1a << Append( TimeCol[1])); Try(InList3 << Append( post3)); Try(InList2 << Append( PredCol)); Main_dlg << Bring Window to Front; ); Tab1 = Expr( Border Box( Left( 3 ), top( 2 ), V List Box( H List Box( Panel Box( "Select Columns", colListData = Col List Box(All, width( lbWidth ), nLines( Min( ncdt1, 10 ) )) ), Panel Box( "Selection", Lineup Box( N Col( 2 ), Spacing( 3 ), Button Box( "Time Series Column", Inlist1 << remove all; InList1 << Append( colListData << GetSelected ); Inlist1a << remove all; InList1a << Append( colListData << GetSelected ); ), InList1 = Col List Box( width( lbWidth ), nLines( 1 ), numeric, MinItems(1), Max Items(1)) ), cb = Check Box( {"Use Column Name as Prefix"}), cb1 = Check Box( {"Start GenReg"}) ), Panel Box( "Action", Lineup Box( N Col( 1 ), b1=Button Box( "OK", TimeCol = InList1 << GetItems; Use_cb = cb << Get() ; Use_cb1 = cb1 << Get() ; If(N Items(TimeCol)==0, Stop() , show(TimeCol, Use_cb); Main_dlg << Close Window; Eval(nextstep); ); ), b2=Button Box( "Cancel", Main_dlg << Close Window; Stop();), Text Box( " " ), b3=Button Box( "Remove", Try(InList1 << RemoveSelected); Try(InList1a << RemoveSelected); ) ) ) ) ); ), ); Tab2=expr( Border Box( Left( 3 ), top( 2 ), V List Box( H List Box( Panel Box( "Select Columns", colListDat2 = Col List Box(All, width( lbWidth ), nLines( Min( ncdt1, 10 ) )) ), Panel Box( "Selection", Lineup Box( N Col( 2 ), Spacing( 3 ), Button Box( "Time Series Column", Inlist1 << remove all; InList1 << Append( colListDat2 << GetSelected ); Inlist1a << remove all; InList1a << Append( colListDat2 << GetSelected ); ), InList1a = Col List Box( width( lbWidth ), nLines( 1 ), numeric, MinItems(1), Max Items(1)), Button Box( "Y, Response", InList2 << Append( colListDat2 << GetSelected ); ), InList2 = Col List Box( width( lbWidth ), nLines( 1 ), numeric, MinItems(1), Max Items(1)), Button Box( "Time Series Prediction Column", InList3 << Append( colListDat2 << GetSelected ); ), InList3 = Col List Box( width( lbWidth ), nLines( 1 ), numeric, MinItems(1), Max Items(1)) ), ), Panel Box( "Action", Lineup Box( N Col( 1 ), b2=Button Box( "OK", Print("b2 pressed"); YCol = InList2 << GetItems; PredCol = InList3 << GetItems; TimeCol = InList1a << GetItems; If(N Items(YCol)==0 | N Items(PredCol)==0 | N Items(TimeCol)==0, Stop() , Main_dlg << Close Window; Eval(AddGrps); ); ), b2=Button Box( "Cancel", Main_dlg << Close Window; Stop();), Text Box( " " ), b3=Button Box( "Remove", Try(InList1 << RemoveSelected); Try(InList1a << RemoveSelected); Try(InList2 << RemoveSelected); Try(InList3 << RemoveSelected); ) ) ) ) ); ), ); Form=expr(newcol=dt1 << New Column( Prefix||char(_Val), formula(_Var1 < _Val) ) ); nextstep = expr( dt2=dt1 << Summary(Group( TimeCol[1] ), Freq( "None" ), Weight( "None" ), invisible); Var1Lev = dt2 << get as matrix(TimeCol); close(dt2, nosave); If(Use_cb, Prefix=TimeCol[1]||"_", Prefix=""); NewCols={}; If(N Rows(Var1Lev) > 2, For(ii=2, ii <= NRow(Var1Lev), ii++, Eval(Substitute(Name Expr(Form), expr(_Val), Var1Lev[ii], expr(_Var1), Name Expr(As Column(TimeCol[1])) )); newcol << Set Modeling Type( "Nominal" ); Insert Into (NewCols, newcol << Get Name()); ); NewGrp = dt1 << Group Columns(NewCols); dt1 << rename column group( NewGrp, TimeCol[1]||" Indicators" ); if(Use_cb1, eval(gnrg)); , Print ("No levels for variable. Script Stopped."); Stop(); ) ); //form3=expr( // NewCol=dt1 << New Column("Group of "||TimeCol[1], "nominal", "character", formula(Choose( As Column(Colhere), Levels ))); //); //form2=expr( // NewCol=dt1 << New Column("Group of "||TimeCol[1], "nominal", "character", formula(Choose( As Column(Colhere), Levels, Next ))); //); form1a=expr( NewColBy=dt1 << New Column("Means for "||YCol[1]||" by "||TimeCol[1], formula(Col Mean( As Column(Col1), As Column(Col2)))); ); AddGrps = Expr( show(TimeCol, YCol, PredCol); ColListNow=Eval List({TimeCol[1], YCol[1], PredCol[1]}); Mat=dt1 << Get As Matrix(ColListNow); Mat=Transpose(1::N Row(dt1)) || Mat || J(N Row(dt1),1,1); Mat=Mat[Rank(Mat[0,2]),0]; For(ii=2, ii <= N Row(Mat), ii++, if(Mat[ii, 4] == Mat[ii-1, 4], Mat[ii, 5] = Mat[ii-1, 5], Mat[ii, 5] = Mat[ii-1, 5]+1); ); Mat=Mat[Rank(Mat[0,1]),0]; If(max(Mat[0,5]) <= 1, stop()); NewCol=dt1 << New Column("Group of "||TimeCol[1], "nominal", Set Values(Mat[0,5])); Summarize(dt1, nameby=By(NewCol), meanY=Mean(YCol[1]), lowtime=Minimum(TimeCol[1]), hitime=Maximum(TimeCol[1]) ); // Label1=""; // Label0={}; _Label={}; _Val=transpose(1::N Items(nameby)); // Form2a=Substitute(Name Expr(Form2),expr(Colhere), NewCol << get name()); For(ii=1, ii <= N Items(nameby), ii++, LabelNow=char(lowtime[ii]) || " - " || char(hitime[ii]) || " ("|| char(round(meanY[ii],3)) ||")"; Insert Into(_Label, LabelNow); _Val[ii]=num(nameby[ii]); // NewCol << Value Labels({_Val[ii]},{LabelNow}); // NewCol << Value Labels({1},{"one"}); // NewCol << get Value Labels(); // if(ii>1, Label1=Label1 || ", "); // Label1=Label1||LabelNow; // Insert Into(Label0, "\!""||LabelNow||"\!""); // Form2a=Substitute(Name Expr(Form2a), // expr(Levels), LabelNow // , // expr(next), name expr(eval(parse("Levels, Next"))) // ); ); show(_Val, _Label); NewCol << Value Labels(As List(_Val),_Label); // Label00=Concat Items(Label0, " , "); // Eval(Substitute(Name Expr(Form3), // expr(Colhere), NewCol << get name() , // expr(Levels), name expr(Label00) // )); Eval(Substitute(Name Expr(Form1a), expr(Col1), YCol[1] , expr(Col2), NewCol << get name() )); _temp1=NewCol << get name(); NewColsp=Insert({}, PredCol[1]); Insert Into(NewColsp, NewCol << get name()); Insert Into(NewColsp, NewColBy << get name()); NewGrp = dt1 << Group Columns(NewColsp); dt1 << rename column group( NewGrp, TimeCol[1]||" Grouping" ); ); gnrg=expr( NewColCol = eval list(dt1 << Get Column Reference( NewCols )); NewColCol[1] << label(1); genreg1 = dt1 << Fit Model( Effects(eval(NewColCol)), Personality( "Generalized Regression" ), Generalized Distribution( "Normal" ) ); genreg1 << save prediction formula(); ); eval(Dia_Window);