欠損データを回帰値で置き換える<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />こんにちは
変数に欠損値がある時系列があります。 欠損値を、時間内で最も近い利用可能な値から導出された線形モデルで置き換えたいと考えています。
最善の方法は何でしょうか?
そして、スクリプトがテーブルのすべての列 (時刻を除く) に対してそれを行うことができれば、さらに良いでしょう。
ありがとう
例
私が持っているもの
私が欲しいもの:
| t | 出力 |
|---|
| 0 | 10 |
| 1 | 15 |
| 2 | 20 |
| 4 | 30 |
| 10 | 22.5 |
| 20 | 10 |
Re: 欠損データを回帰値で置き換えるJMP 式が JMP 関数とともに機能する仕組みは、最後に作成または参照された変数が式または関数から渡されるということです。 したがって、置換式では、行の値として返されるのは、Row() 番号に等しい「値」行列の値です。 そして、「Values」行列は列の値が << getvalues メッセージで取得された場所であるため、次のように指定することで「Values」行列に対して補間が行われました。
値[行()]
数式は、値を一度に 1 行ずつ新しい列に移動します。
これを説明する別の方法は、次の式のプロセス フローをたどることです。
すべての数式は、データ テーブルの行 1 から最後の行まで、データ テーブルのすべての行をループします。
行 1 の処理では、列「p (g/L)」のすべての値が処理のために行列に移動されます。 処理は行列の要素 1 から行列の最後までループし、必要に応じて補間を実行します。 ループの終わりまでに、行列のすべての要素が埋められます。 次に、「値」行列の最初の要素の値が、列の 1 行目に使用される値として数式に返されます。
次に、行の値が移動されて 2 行目の数式が実行され、2 行目で実行されるステートメントは次のとおりです。
値[行()]
これは、「値」行列の要素 2 である列 2 行の値を式に返します。
式は後続の行ごとに 1 回ループを続け、ステートメントのみを実行します。
値{行()]
これが意味があるといいのですがRe: 欠損データを回帰値で置き換えるジム、
本当にありがとう。これは今では非常にうまくいきます。最後の「values[Row()];」が何なのか説明してもらえますか?する
Re: 欠損データを回帰値で置き換える:Time 値が 0 の場合に、Interpreted 列の値を 0 に等しくしたい場合は、コードを以下のように変更すると機能します。
For( i = 1, i <= N Rows( values ), i++,
If( :Time[i] == 0, values[i]=0); // **************
If( Is Missing( values[i] ),
counter++,
If( counter > 0,
For( k = 1, k <= counter, k++,
base = values[i - counter - 1];
incr = Abs( (base - values[i]) / (counter + 1) );
If( base < values[i],
values[(i - counter - 1) + k] = base + k * incr,
values[(i - counter - 1) + k] = base - k * incr
);
);
counter = 0;
)
)
);Re: 欠損データを回帰値で置き換えるそれは最初の値に対してそれを行いますが、私が必要とするのは、すべての「時間」が0であり、補間値がゼロであることです。時間列には複数の 0 が含まれます
Re: 欠損データを回帰値で置き換える私が提供したコードから、これがあなたが求めていることですか?
If( Is Missing( values[1] ),
values[1] = 0
);Re: 欠損データを回帰値で置き換えるジム、
スクリプトが機能するようになりました。 補間評価ループの両方の増分計算のデルタ時間を考慮するために、いくつかの計算を追加する必要がありました。最後の問題は、複数の実行ファイルを結合してスクリプトを実行することを計画しているため、time = 0 (time: 0,12,24,48,0,12,24,48...) の場所が複数あることです。 )、したがって、指定されたデータ チャンクの最初の補間値は 0 になるはずです。 行列表記でこれを行う方法がわかりません。
Re: 欠損データを回帰値で置き換える私の経験から言えば、数式内で実際の数式列を参照しようとすると、非常に多くの問題が発生しました。 したがって、示されたアプローチ。 また、For() ループでデータを実行する回数の観点から、数式にも懸念がありました。 私の方法では、データテーブルを 1 回だけステップ実行します。反復置換はカウントしません。Re: 欠損データを回帰値で置き換えるジム、
本当にありがとう、試してみます。 でも、私は興味があります。元のスクリプトに戻ると、増分を計算して rows-counter-1 = 3-2-1 =0 を取得するため、再帰的エラーは行 3 から発生していると思いました。エラー メッセージを無視すると、最後を除く列の残りの部分が正常に補間されます。補間されるテーブルにさらにデータを追加すると、問題が軽減されます。それらは別の問題かもしれないと思いました。
Re: 欠損データを回帰値で置き換える数式列自体内の値を変更しようとすると、数式内で再帰的な問題が発生します。マトリックスを使用してすべての作業を事前に行うように数式を作り直しました。結果の値は各行の値に使用されます。
Names Default To Here( 1 );
col_name_list = Current Data Table() << get column names( string );
If( !Contains( col_name_list, "Interpolated p (g/L)" ),
Current Data Table() << New Column( "Interpolated p (g/L)",
Numeric,
Continuous,
Formula(
dt = Current Data Table();
If( Row() == 1,
counter = 0;
values = dt:Name( "p (g/L)" ) << get values;
If( Is Missing( values[1] ),
values[1] = 0
);
counter = 0;
For( i = 1, i <= N Rows( values ), i++,
If( Is Missing( values[i] ),
counter++,
If( counter > 0,
For( k = 1, k <= counter, k++,
base = values[i - counter - 1];
incr = Abs( (base - values[i]) / (counter + 1) );
If( base < values[i],
values[(i - counter - 1) + k] = base + k * incr,
values[(i - counter - 1) + k] = base - k * incr
);
);
counter = 0;
)
)
);
);
values[Row()];
)
)
);Re: 欠損データを回帰値で置き換えるここにテーブルがあります
Re: 欠損データを回帰値で置き換えるジム、
明確にしていただきありがとうございます。 スクリプトに問題があります。最後の間隔を実行して補間することはありません。それがループのネストと「while」条件に関係があるのかどうかはわかりません。基本的に、テーブルの長さに関係なく、欠落データの最後の間隔を埋めることはできません。
col_name_list = Current Data Table() << get column names( string );
If( !Contains( col_name_list, "Interpolated p (g/L)" ),
Current Data Table() << New Column(
"Interpolated p (g/L)",
Numeric,
Continuous,
Formula(
If(
Is Missing( :Name( "time (h)" ) ),
Empty(),
:name( "time (h)" ) == 0,
0,
!Is Missing( :Name( "p (g/L)" ) ),
:name( "p (g/L)" ),
dt = Current Data Table();
For( rows = 1, rows <= (N Rows( dt )), rows++,
If( Rows == 1, counter = 0 );
If( Is Missing( dt:name( "Interpolated p (g/L)" )[rows] ) == 1,
counter++);
If( counter > 0 & Is Missing( dt:name( "Interpolated p (g/L)" )[rows] ) == 0,
incr = (dt:name( "Interpolated p (g/L)" )[Rows] - dt:name( "Interpolated p (g/L)" )[Rows - counter - 1]) / (dt
:name( "time (h)" )[Rows] - dt:name( "time (h)" )[Rows - counter - 1]);
For( i = rows - counter, i <= rows - 1, i++,
dt:name( "Interpolated p (g/L)" )[i] = dt:name( "Interpolated p (g/L)" )[i - 1] + (incr * (dt:name( "time (h)" )[i]
-dt:name( "time (h)" )[i - 1]))
);
counter = 0;
);
);
)
)
)
);
Re: 欠損データを回帰値で置き換えるJMP では関数やステートメントで大文字と小文字が区別されないため、rows=RowsRe: 欠損データを回帰値で置き換えるジム、
「行」と「行」に違いはありますか?説明していただけますか。 私は初心者です。
Re: 欠損データを回帰値で置き換えるよく釣れる……はずだ。
If this is row 1 initialize a variable named counter to 0
Re: 欠損データを回帰値で置き換えるありがとう、うまくいきました!あなたはコメントしました
If this is row 1 initialize a variable named counter to 1
、「0へのカウンター」のことですか?
Re: 欠損データを回帰値で置き換えるこれは、私の元のコードの更新/注釈付きバージョンです。列名を「出力」から、値を変更したい列の名前に変更するだけです。
// Set all default referenced memory variables to this unique application
Names Default To Here( 1 );
// Set the variable dt to be a pointer to the current active data table
dt = Current Data Table();
// Loop through the data table from row 1 to the last row and use a
// variable names "rows" as the index
For( rows = 1, rows <= N Rows( dt ), rows++,
// If this is row 1 initialize a variable named counter to 1
If( Rows == 1, counter = 0 );
// If the current row's value for the column named "Output" in the
// data table referenced by "dt" is missing (blank, null) increase
// the counter
If( Is Missing( dt:output[rows] ) == 1,
counter++
);
// If row is found with a non missing value for the column called Output,
// and the counter is > 0, which indicates previous rows with missing
// values, then calculate the required values and place them in their
// appropriate rows
If( counter > 0 & Is Missing( dt:output[rows] ) == 0,
// Calculate the incremental steps to use for the missing cells
incr = (dt:output[Rows] - dt:output[Rows - counter - 1]) / (counter + 1);
// Loop across the rows with missing values and fill in the data
For( i = Rows - counter, i <= Rows - 1, i++,
dt:output[i] = dt:output[i - 1] + incr
);
// reinitialize the counter
counter = 0;
);
);Re: 欠損データを回帰値で置き換えるテキネルソン、
コメントを追加してスクリプトを更新していただけますか? 私は JSL を初めて使用するため、JSL が自分の問題にどのように適用されるかを理解するのに助けが必要です。 OPと同じニーズがありますが、入力する必要がある列は1つだけです。代わりに、私は過去に次の VBA コードを使用して Excel の欠落データを埋めました。 JSL に End(xlDown).value 関数に似たものがあるのではないかと考えていました。オフセットは、時点データの場所を指定するために使用されます。 ありがとう!
Sub interpolatedata()
For Each cell In Range("k4:k29")
If cell.Value = "" Then
y2 = cell.End(xlDown).Value
x2 = cell.End(xlDown).Offset(0, -8).Value
y1 = cell.End(xlUp).Value
x1 = cell.End(xlUp).Offset(0, -8).Value
x = cell.Offset(0, -8).Value
y = (y1) + (x - x1) * (y2 - y1) / (x2 - x1)
cell.Value = y
End If
Next
Re: 欠損データを回帰値で置き換えるMSのスポット、
乾杯!
Re: 欠損データを回帰値で置き換える私も数年前に同様の問題があり、「局所回帰」による代入を行うスクリプトを書きました。
更新されたバージョンは次のとおりです。
dt = Current Data Table();
n = N Rows(dt);
x = Column(1);// Column("t")
For(i = 2, i <= N Col(dt), i++,
y = Column(i);
For Each Row(
If(1 < Row() < n & Is Missing(y[]),
// find previous non-missing row
Eval(Eval Expr(r1 = Max(dt << get rows where(!Is Missing(y[]) & Row() < Expr(Row())))));
// find next non-missing row
Eval(Eval Expr(r2 = Min(dt << get rows where(!Is Missing(y[]) & Row() > Expr(Row())))));
y[] = y[r1] + (y[r2] - y[r1]) / (x[r2] - x[r1]) * (x[] - x[r1]);
)
)
);
Re: 欠損データを回帰値で置き換えるこれがタスクを実行するスクリプトです
Names Default To Here( 1 );
dt = Current Data Table();
For( rows = 1, rows <= N Rows( dt ), rows++,
If( Rows == 1, counter = 0 );
If( Is Missing( dt:output[rows] ) == 1,
counter = counter + 1,
If( counter > 0,
incr = (dt:output[Rows] - dt:output[Rows - counter - 1]) / (counter + 1);
For( i = Rows - counter, i <= Rows - 1, i++,
dt:output = dt:output[i - 1] + incr
);
counter = 0;
)
);
);
// Set all default referenced memory variables to this unique application
Names Default To Here( 1 );
// Set the variable dt to be a pointer to the current active data table
dt = Current Data Table();
// Loop through the data table from row 1 to the last row and use a
// variable names "rows" as the index
For( rows = 1, rows <= N Rows( dt ), rows++,
// If this is row 1 initialize a variable named counter to 1
If( Rows == 1, counter = 0 );
// If the current row's value for the column named "Output" in the
// data table referenced by "dt" is missing (blank, null) increase
// the counter
If( Is Missing( dt:output[rows] ) == 1,
counter++
);
// If row is found with a non missing value for the column called Output,
// and the counter is > 0, which indicates previous rows with missing
// values, then calculate the required values and place them in their
// appropriate rows
If( counter > 0 & Is Missing( dt:output[rows] ) == 0,
// Calculate the incremental steps to use for the missing cells
incr = (dt:output[Rows] - dt:output[Rows - counter - 1]) / (counter + 1);
// Loop across the rows with missing values and fill in the data
For( i = Rows - counter, i <= Rows - 1, i++,
dt:output[i] = dt:output[i - 1] + incr
);
// reinitialize the counter
counter = 0;
);
);Re: 欠損データを回帰値で置き換えるありがとうロン、でもこの中に補間を行うものは何もないのですが?
Re: 欠損データを回帰値で置き換える手始めにこれを試してください
代入アドイン