Running examples in ‘TeachingSampling-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: HH
> ### Title: The Hansen-Hurwitz Estimator
> ### Aliases: HH
> ### Keywords: survey
> 
> ### ** Examples
> 
> ############
> ## Example 1
> ############
> # Vector U contains the label of a population of size N=5
> U <- c("Yves", "Ken", "Erik", "Sharon", "Leslie")
> # Vectors y1 and y2 give the values of the variables of interest
> y1<-c(32, 34, 46, 89, 35)
> y2<-c(1,1,1,0,0)
> y3<-cbind(y1,y2)
> # The population size is N=5
> N <- length(U)
> # The sample size is m=2
> m <- 2
> # pk is the probability of selection of every single unit
> pk <- c(0.35, 0.225, 0.175, 0.125, 0.125)
> # Selection of a random sample with replacement
> sam <- sample(5,2, replace=TRUE, prob=pk)
> # The selected sample is
> U[sam]
[1] "Yves" "Ken" 
> # The values of the variables of interest for the units in the sample
> y1[sam]
[1] 32 34
> y2[sam]
[1] 1 1
> y3[sam,]
     y1 y2
[1,] 32  1
[2,] 34  1
> # The Hansen-Hurwitz estimator
> HH(y1[sam],pk[sam])
                       y
Estimation     121.26984
Standard Error  29.84127
CVE             24.60733
> HH(y2[sam],pk[sam])
                        y
Estimation      3.6507937
Standard Error  0.7936508
CVE            21.7391304
> HH(y3[sam,],pk[sam])
                      y1         y2
Estimation     121.26984  3.6507937
Standard Error  29.84127  0.7936508
CVE             24.60733 21.7391304
> 
> 
> ############
> ## Example 2
> ############
> # Uses the Lucy data to draw a simple random sample with replacement
> data(Lucy)
> attach(Lucy)
> 
> N <- dim(Lucy)[1]
> m <- 400
> sam <- sample(N,m,replace=TRUE)
> # The vector of selection probabilities of units in the sample
> pk <- rep(1/N,m)
> # The information about the units in the sample is stored in an object called data
> data <- Lucy[sam,]
> attach(data)
The following objects are masked from Lucy:

    Employees, ID, Income, Level, SPAM, Taxes, Ubication, Zone

> names(data)
[1] "ID"        "Ubication" "Level"     "Zone"      "Income"    "Employees"
[7] "Taxes"     "SPAM"     
> # The variables of interest are: Income, Employees and Taxes
> # This information is stored in a data frame called estima
> estima <- data.frame(Income, Employees, Taxes)
> HH(estima, pk)
                     Income    Employees        Taxes
Estimation     1.004235e+06 1.496002e+05 26966.980000
Standard Error 3.128381e+04 3.715376e+03  1779.232304
CVE            3.115187e+00 2.483536e+00     6.597818
> 
> ################################################################
> ## Example 3 HH is unbiased for with replacement sampling designs
> ################################################################
> 
> # Vector U contains the label of a population of size N=5
> U <- c("Yves", "Ken", "Erik", "Sharon", "Leslie")
> # Vector y1 and y2 are the values of the variables of interest
> y<-c(32, 34, 46, 89, 35)
> # The population size is N=5
> N <- length(U)
> # The sample size is m=2
> m <- 2
> # pk is the probability of selection of every single unit
> pk <- c(0.35, 0.225, 0.175, 0.125, 0.125)
> # p is the probability of selection of every possible sample
> p <- p.WR(N,m,pk)
> p
 [1] 0.122500 0.157500 0.122500 0.087500 0.087500 0.050625 0.078750 0.056250
 [9] 0.056250 0.030625 0.043750 0.043750 0.015625 0.031250 0.015625
> sum(p)
[1] 1
> # The sample membership matrix for random size without replacement sampling designs
> Ind <- nk(N,m)
> Ind
      [,1] [,2] [,3] [,4] [,5]
 [1,]    2    0    0    0    0
 [2,]    1    1    0    0    0
 [3,]    1    0    1    0    0
 [4,]    1    0    0    1    0
 [5,]    1    0    0    0    1
 [6,]    0    2    0    0    0
 [7,]    0    1    1    0    0
 [8,]    0    1    0    1    0
 [9,]    0    1    0    0    1
[10,]    0    0    2    0    0
[11,]    0    0    1    1    0
[12,]    0    0    1    0    1
[13,]    0    0    0    2    0
[14,]    0    0    0    1    1
[15,]    0    0    0    0    2
> # The support with the values of the elements
> Qy <- SupportWR(N,m, ID=y)                 
Error in if (ID == FALSE) { : the condition has length > 1
Calls: SupportWR
Execution halted