harmonize | R Documentation |
This function harmonize the two weight schemes such that the totals are equal.
harmonize(X1, d1, id1, X2, d2, id2, totals)
X1 |
A matrix, the matching variables of sample 1. |
d1 |
A numeric vector that contains the initial weights of the sample 1. |
id1 |
A character or numeric vector that contains the labels of the units in sample 1. |
X2 |
A matrix, the matching variables of sample 2. |
d2 |
A numeric vector that contains the initial weights of the sample 1. |
id2 |
A character or numeric vector that contains the labels of the units in sample 2. |
totals |
An optional numeric vector that contains the totals of the matching variables. |
All details of the method can be seen in the manuscript: Raphaël Jauslin and Yves Tillé (2021) <arXiv:>.
A list of two vectors, the new weights of sample 1 (respectively new weights of sample 2).
#--- SET UP
N = 1000
p = 5
X = array(rnorm(N*p),c(N,p))
n1=100
n2=200
s1 = sampling::srswor(n1,N)
s2 = sampling::srswor(n2,N)
id1=(1:N)[s1==1]
id2=(1:N)[s2==1]
d1=rep(N/n1,n1)
d2=rep(N/n2,n2)
X1 = X[s1==1,]
X2 = X[s2==1,]
re <- harmonize(X1,d1,id1,X2,d2,id2)
colSums(re$w1*X1)
colSums(re$w2*X2)
#--- if the true totals is known
totals <- c(N,colSums(X))
re <- harmonize(X1,d1,id1,X2,d2,id2,totals)
colSums(re$w1*X1)
colSums(re$w2*X2)
colSums(X)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.