data(invData)
# data from one period are considered:
invData2018 <- invData[invData$year == 2018,]
invData2018$investments <- invData2018$investments/1000
attach(invData2018)
N <- nrow(invData2018) # population size
con <- rep(0,N)
set.seed(123456)
con[sample(N,50)] <- 1 # sample size equals 50
YS <- log((investments[con == 1])) # log-transformed values
backTrans <- function(x) {exp(x)} # back-transformation of the variable of interest
fixed.part <- 'log(newly_registered)'
random.part <- '(1|NUTS2)'
random.part2 <- '(1|NUTS4type)'
reg <- invData2018[, -which(names(invData2018) == 'investments')]
weights <- rep(1,N) # homoscedastic random components
weights.mis <- sqrt(newly_registered)
# Characteristics to be predicted:
# the population mean and the population total
thetaFun <- function(x) {c(mean(x), median(x))}
predictorLMMmis <- plugInLMM(YS, fixed.part, random.part, reg,con,weights.mis,backTrans,thetaFun)
predictorLMMmis$thetaP
predictorLMM <- plugInLMM(YS, fixed.part, random.part, reg, con, weights, backTrans, thetaFun)
predictorLMM$thetaP
predictorLMM2 <- plugInLMM(YS, fixed.part, random.part2, reg, con, weights, backTrans, thetaFun)
predictorLMM2$thetaP
Ypop <- log(invData2018$investments)
# Monte Carlo simulation study under the misspecified model defined in predictorLMMmis
# with modified covariance matrices R and G
set.seed(123456)
mcLMMmis(Ypop, predictorLMMmis, predictorLMM, predictorLMM2, 5, c(0.75,0.9), 2, 0.1)
# Monte Carlo simulation study under the model defined in predictorLMM
# correctly specified for predictorLMM and misspecified for predictorLMM2
set.seed(123456)
mcLMMmis(Ypop, predictorLMM, predictorLMM, predictorLMM2, 5, c(0.75,0.9), 1, 1)
detach(invData2018)
Run the code above in your browser using DataLab