如果資料表中每個樣本有多個條目,如何為清單中的每個樣本執行腳本。我有一個數據表,其中多次測量相同的樣本(請參閱下面的範例)。 樣本由其識別符分隔。

我希望我的腳本能夠對每個樣本執行相同的計算集,以便我可以確定控制限並為 A、B、C 等製作控製圖。 我不知道每個樣本的識別碼。 我已經有一個腳本可以進行計算並為我製作圖表,它只是不能為每個標識符進行單獨的計算。
我最初的做法是使用某種循環來做到這一點。 我有一個腳本,它會傳回列表中的每個唯一標識符,並為我提供唯一標識符的數量作為循環的設定。
Identifiers = Column( "Identifier") << GetAsMatrix();
Identifiers set = Associative Array( Identifiers);
Unique Identifiers = Identifiers set << Get Keys;
nUnique Identifiers = N Items (Unique Identifiers);
但我似乎無法讓循環工作。 有一個更好的方法嗎? 或者有人可以告訴我如何做循環嗎?
我正在使用 JMP 10。
謝謝你!
品質和工藝工程回覆:如果資料表中每個樣本有多個條目,如何為清單中的每個樣本執行腳本。就像魅力一樣,謝謝!
回覆:如果資料表中每個樣本有多個條目,如何為清單中的每個樣本執行腳本。如果您不想修改腳本,您可以針對標識符每個層級的子集運行它,如下所示:
Names default to here(1);
//Open some sample data
dt = Open( "$Sample_data/big class.jmp" );
//Your code
Identifiers = Column( "age") << GetAsMatrix();
Identifiers set = Associative Array( Identifiers);
Unique Identifiers = Identifiers set << Get Keys;
nUnique Identifiers = N Items (Unique Identifiers);
//A window to hold a bunch of graphs
win = New Window("Graphs", graphbox = v list box());
//Run an analysis on a subset of the data table for each level of a variable
for( i=1, i<=nUnique Identifiers, i++,
//Make a subset of the table with only values for this level
dt << Select Where( :age == UniqueIdentifiers[i]);
dtSub = dt << Subset("Selected Rows");
//run your existing script on the subset
//For demonstration, taking a picture of the graph builder platform
// and getting the R2 value from a linear model and adding those to a window
pic = (gb = dtSub << Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Variables( X( :height ), Y( :weight ) ),
Elements( Points( X, Y, Legend( 2 ) ) ),
Local Data Filter(
Close Outline( 1 ),
Add Filter(
columns( :age ),
Where( :age == Unique Identifiers[i] ),
Display( :age, N Items( 6 ) )
)
)
)) << Get Picture;
graphbox << Append( pic );
gb << Close Window;
fm = dtSub << Fit Model(
Y( :height ),
Effects( :weight ),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" ),
Run(
:height << {Summary of Fit( 1 ), Analysis of Variance( 1 ),
Parameter Estimates( 1 ), Scaled Estimates( 0 ),
Plot Actual by Predicted( 1 ), Plot Residual by Predicted( 1 ),
Plot Studentized Residuals( 0 ), Plot Effect Leverage( 1 ),
Plot Residual by Normal Quantiles( 0 ), Box Cox Y Transformation( 0 )}
)
);
Wait( 0 );
dtSum = Report( fm )[Outline Box( "Response height" )][Outline Box( "Whole Model" )][
Outline Box( "Summary of Fit" )][Table Box( 1 )] << Make Into Data Table;
Report( fm ) << Close Window;
Rsq = dtSum:Column 2[1];
graphbox << Append( Text Box( "RSquared was " || char(Rsq) ) );
dtSum << Close Window;
//close the subset
dtSub << Close Window;
);回覆:如果資料表中每個樣本有多個條目,如何為清單中的每個樣本執行腳本。我如何能夠進行按標識符過濾的額外計算? 我想做一些資料操作,然後根據每個標識符的資料計算我自己的限制,然後將其添加到每個圖表中,因此我認為任何類型的過濾器都需要在最終圖表腳本之前出現。 我有一個可以做到這一點的腳本,如果需要我可以發布它,但它很長。 我實際上只是在尋找一種方法來製作我已經為每個標識符而不是數據表中的所有行運行的腳本
回覆:如果資料表中每個樣本有多個條目,如何為清單中的每個樣本執行腳本。我想知道使用內建控製圖平台來計算限制和繪圖度量是否有效,特別是如果您將標識符分配給“按分析”角色。
只是不希望您花費大量時間編寫腳本,如果它重複了已經可用的功能。
回覆:如果資料表中每個樣本有多個條目,如何為清單中的每個樣本執行腳本。有很多方法可以做到這一點,但其中一種方法是向現有平台添加本地資料過濾器。這是使用圖形產生器的範例:
Names default to here(1);
//Open some sample data
dt = Open( "$Sample_data/big class.jmp" );
//Your code
Identifiers = Column( "age") << GetAsMatrix();
Identifiers set = Associative Array( Identifiers);
Unique Identifiers = Identifiers set << Get Keys;
nUnique Identifiers = N Items (Unique Identifiers);
//A window to hold a bunch of graphs
win = New Window("Graphs", graphbox = v list box());
//Open a graph that is filtered to only show each unique identifier
//to keep things organized add it to a single window.
for( i=1, i<=nUnique Identifiers, i++,
win << Append(<BR /> //To get this script I opened graph builder and added a local data filter for one age<BR /> //and then copied/pasted it here and replaced the age with 4Unique Identifiers[i]
Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Variables( X( :height ), Y( :weight ) ),
Elements( Points( X, Y, Legend( 2 ) ) ),
Local Data Filter(
Close Outline( 1 ),
Add Filter(
columns( :age ),
Where( :age == Unique Identifiers[i] ),
Display( :age, N Items( 6 ) )
)
)
)
)
);