Test difference of population proportion and weighted sample proportion

I want to test for differences of the known proportion of the population vs. the proportion of a sample. The sample is weighted by sampling weights. The sum of weights is equal to the size of the population.

Consider the following example (coded in R):

set.seed(12345)

theta <- 0.7 # True population value

N <- 100000 # Sample size
samp_values <- rbinom(N, 1, 0.69) # Sample values
weights <- runif(N, 0, 20) # Sampling weights (summing up to the population size)

According to this thread, I could test for differences by applying a z-test:

theta_hat <- sum((samp_values * weights)) / sum(weights) # Weighted proportion

(theta_hat - theta) / sqrt((theta * (1 - theta)) / N) # z-test
#  -7.101598

To me the result seems to be fine. However, the other thread is not taking weights into account and surprisingly I did not find any other sources about the topic.

Question: How could weights be incorporated into a test for differences between population proportion and weighted sample proportion?

• It rather depends on what the weights represent. The key question is how they translate into an effective sample size – Henry Jan 9 '18 at 8:09
• @Henry Thanks for your comment. I updated the question in order to explain the weights better. The weights where created by calibrating to the population, i.e. the sum of weights is equal to the size of the population. – JSP Jan 9 '18 at 8:55