0

R で、調査パッケージの svytotal 関数を使用して、ある郡から他のいくつかの郡に移動する人の数の推定値と標準誤差を生成し、反対方向への移動に同じ関数を使用すると、どうすればよいでしょうか。正味の移行と対応する標準誤差を計算しますか? IPUMSデータから一方向の移行を計算する方法は次のとおりです。

mig_count_left=as.data.frame(svytotal(~nowpuma,design=subset(pums_design,left==1)))

nowpumaは、人が現在住んでいる場所の名前を持つ要素です。leftは、その人物が以前の郡を離れたと識別された場合に 1 に等しくなります。結果は次のようになります。

                                                                  total         SE
nowpumaAllegany & Garrett Counties                                  342  134.08951
nowpumaAnne Arundel County                                         2132  851.19956
nowpumaBaltimore County                                            5473 1153.62968
etc...

私は次のようなことを望んでいます:

in_out_df=merge(mig_count_left,mig_count_entered,by=row.names) #put in & out migration in a single dataframe
in_out_df$net=in_out_df$total_left-in_out_df$total_entered #compute net
in_out_df$net_SE=????   #calculate standard error for the net migration
4

1 に答える 1

1

すべての puma についてこれを計算するために、私が既に提供したコードを使用してループを記述していただけますか?

# loop through one puma at a time
for ( asp in all.state.pumas ){

    pums_design <- 
        update( 
            pums_design , 
            this.net.migration = 
                ifelse( nowpuma == asp & prevpuma != asp , -1 ,
                ifelse( prevpuma == asp & nowpuma != asp , 1 ,
                0 ) )
        )

    # compute in-migration, out-migration, and net migration for the current puma
    # with all standard errors
    out <-
        svytotal( 
            ~ as.numeric( nowpuma == asp & prevpuma != asp ) +
            as.numeric( prevpuma == asp & nowpuma != asp  ) +
            this.net.migration , 
            pums_design 
        )

    # stack `out` with all the other pumas
}
于 2014-10-24T08:43:15.577 に答える