File: checkdata.R

package info (click to toggle)
r-cran-eco 4.0-1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 772 kB
  • sloc: ansic: 4,214; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,422 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
checkdata <- function(X,Y, supplement, ndim) {
   # check and reorganize inputs 
   if (any(X<0) || any(X>1) || any(Y<0) || any(Y>1))
     stop("Values of X and Y have to be between 0 and 1.")
   ind <- 1:length(X)
   res <- list()
   res$X1type <- res$samp.X1 <- res$X1.W1 <- 0 
   res$X0type <- res$samp.X0 <- res$X0.W2 <- 0  
   
   ## X = 1
   X1.ind <- ind[along=(X==1)]
   if (length(X[X!=1])<length(X)){
      res$X1type <- 1
      res$samp.X1 <- length(X1.ind)
      res$X1.W1 <- Y[X1.ind]
   }

   ## X = 0 
   X0.ind <- ind[along=(X==0)]
   if (length(X[X!=0])<length(X)){
      res$X0type <- 1
      res$samp.X0 <- length(X0.ind)
      res$X0.W2 <- Y[X0.ind]
   }

   XX.ind <- setdiff(ind, union(X0.ind, X1.ind))
   res$X.use <- X[XX.ind]
   res$Y.use <- Y[XX.ind]

   res$order.old<-order(c(XX.ind, X0.ind, X1.ind))
   res$n.samp <- length(res$Y.use)	 
   res$d <- cbind(res$X.use, res$Y.use)

   ## check survey data
   if (any(supplement <0) || any(supplement >1)) 
      stop("survey data have to be between 0 and 1.")
   if(is.null(supplement))
     res$survey.samp <- res$survey.data <- res$survey.yes <- 0
   else
     if (dim(supplement)[2] != ndim)
       stop("when context=TRUE, use n by 3. Otherwise use n by 2 matrix for survey data")
     else {
       res$survey.samp <- length(supplement[,1])
       res$survey.data <- as.matrix(supplement)
       res$survey.yes <- 1
     }

   return(res)

}