2016-11-22 4 views
0

私の質問はR: using predict() on new data with high dimensionalityに類似しているが、StataのPCAモデルを使用してStataの新しいデータの得点を予測するにはどうすればよいですか?

ため私は第一の成分を抽出するためにデータのサブセット(実験の対照群)に主成分モデル(PCA)を実行します。次に、データの別のサブセット(実験からの治療グループ)でPCAモデルを再実行し、それらのデータのスコアも取得したいと考えています。基本的には、dataset_1で実行されるpcaモデルを使用して、新しいデータセット2のスコアを予測したいと考えています。

Rではモデルをコントロールグループにのみ適合させ、適合モデルでは「新しいデータ」引数に完全なデータセットを使用して「予測」コマンドを使用します。これは、対照群のみに適合したモデルからのすべての観察についての予測を生成する。しかし、どのようにStataでこれを行うのですか?

global xlist2a std_agreedisagree1_1_a std_revagreedisagree1_2_a std_revagreedisagree1_3_a std_agreedisagree1_4_a std_revagreedisagree1_10_a std_revagreedisagree1_5_a 
pca $xlist2a 
screeplot, yline(1)  
rotate, clear  
pca $xlist2a, com(3) 
rotate, varimax blanks (.30) 
predict pca5_p1b pca5_p2b pca5_p3b, score 

ニックの回答に基づいて固定コード:

global xlist2a std_agreedisagree1_1_a std_revagreedisagree1_2_a std_revagreedisagree1_3_a std_agreedisagree1_4_a std_revagreedisagree1_10_a std_revagreedisagree1_5_a 
pca $xlist2a if zgroupa10==1 
screeplot, yline(1)  
rotate, clear  
pca $xlist2a if zgroupa10==1, com(3) 
rotate, varimax blanks (.30) 
predict pca5_p1b pca5_p2b pca5_p3b, score 
+2

ここでは良い質問が表示されています。 –

+0

ありがとう、私はコードを含めるために投稿を編集しました。 – emily004

+0

コードを追加していただきありがとうございますが、上記のコードでは、すべての観測で 'すべての** '観測を' pca'とし、すべての観測を '予測'しています。それはあなたがすべきことではありませんが、私の答えの下のあなたのコメントは、あなたの実際のコードが必要なアプローチを適用したことを意味します。 –

答えて

0

あなたはどのようなコードを試してみたのですか?最も簡単な実験では、Stataでも同じアプローチが有効であることがわかります。

. sysuse auto, clear 
(1978 Automobile Data) 

. pca headroom trunk length displacement if foreign 

Principal components/correlation     Number of obs =   22 
               Number of comp. =   4 
               Trace   =   4 
    Rotation: (unrotated = principal)   Rho    =  1.0000 

    -------------------------------------------------------------------------- 
     Component | Eigenvalue Difference   Proportion Cumulative 
    -------------+------------------------------------------------------------ 
      Comp1 |  1.93666  .656823    0.4842  0.4842 
      Comp2 |  1.27983  .615381    0.3200  0.8041 
      Comp3 |  .664453  .545396    0.1661  0.9702 
      Comp4 |  .119057   .    0.0298  1.0000 
    -------------------------------------------------------------------------- 

Principal components (eigenvectors) 

    -------------------------------------------------------------------- 
     Variable | Comp1  Comp2  Comp3  Comp4 | Unexplained 
    -------------+----------------------------------------+------------- 
     headroom | 0.0288 0.7373 0.6749 0.0083 |   0 
      trunk | 0.2443 0.6496 -0.7199 -0.0090 |   0 
      length | 0.6849 -0.1313 0.1229 -0.7061 |   0 
    displacement | 0.6858 -0.1313 0.1054 0.7080 |   0 
    -------------------------------------------------------------------- 

. predict score1 score2 if !foreign 
(score assumed) 
(2 components skipped) 

Scoring coefficients 
    sum of squares(column-loading) = 1 

    ------------------------------------------------------ 
     Variable | Comp1  Comp2  Comp3  Comp4 
    -------------+---------------------------------------- 
     headroom | 0.0288 0.7373 0.6749 0.0083 
      trunk | 0.2443 0.6496 -0.7199 -0.0090 
      length | 0.6849 -0.1313 0.1229 -0.7061 
    displacement | 0.6858 -0.1313 0.1054 0.7080 
    ------------------------------------------------------ 

+0

私はzgroup10 == 1を挿入しないうちに、私の質問に答えてくれました.zgroup10 == 1を挿入していました。お待ち頂きまして、ありがとうございます。 – emily004

関連する問題