2016-09-17 28 views
4

私はMatchItパッケージのRでPSM解析をしようとしていますが、一部の変数には「完全一致」、他の変数には「最近隣同じデータセット内の変数MatchItパッケージ:「最近傍」一致と「完全一致」を組み合わせる

この質問の目的で、サンプルデータセットlalondeを使用します。

test = matchit(treat ~ age + educ + married, method = "nearest", 
             exact = c(married), data = lalonde) 

私はこのコードは(01でバイナリ変数)変数marriedの正確なマッチングを実行して、モデル内の他の全ての変数は、「最も近い」マッチングを行うことが期待しました。

しかし、私は警告メッセージを以下ました:

Warning message: Exact variables not contained in data. Exact matching not done.

matchit出力の概要を見てみると、唯一の「最も近い」方法を使用しました。 「正確な」メソッドだけを使用してからの間違いがどこにあるのか分かりません。関数は正確に一致するものを特定しましたが、他の一致するメソッドとは組み合わせませんでした。

「正確な」マッチングと「最近隣」のマッチングを同じデータセットでどのように組み合わせるか、または私のミスがどこにあるか知っていますか?何が起こっている

答えて

2

あなたは、パッケージの最近傍ファイルにこのループをヒットしているということです。私はあなたがmarriedを指定された方法によるものであると考えてい

## Now for exact matching within nearest neighbor 
    ## exact should not equal T for this type of matching--that would get sent to matchit2exact 
    if (!is.null(exact)){ 
    if(!sum(exact%in%names(data))==length(exact)) { 
     warning("Exact variables not contained in data. Exact matching not done.",call.=FALSE) 
     exact=NULL 
    } 
    else { 
    ww <- exact%in%dimnames(X)[[2]] 
    nw <- length(exact) 
    exact <- data[,exact,drop=F] 
    if(sum(ww)!=nw){ 
     X <- cbind(X,exact[!ww]) 
    } 
    } 
    } 

test = matchit(treat ~ age + educ + married, method = "nearest", 
       exact = "married", data = lalonde) 

次のバージョンは、エラーをスローしません。

関連する問題