R/GenPNSample.R

Defines functions GenPNSample

Documented in GenPNSample

#' Generate P/N sample
#' 
#' @param X Population Covariates
#' @param y Population response
#' @param np number of positive subjects
#' @param nn number of negative subjects
#' @param replace if TRUE, sample with replacement
#' @export
GenPNSample = function(X,y,np,nn,replace = FALSE){
  
  repl = replace
  # sample labelled data
  posind =which(y==1) # where subject is positive
  sampp = sample(x = posind,size = np,replace = repl)
  X_p = X[sampp,]
  y_p = y[sampp]
  
  # sample neg-labelled data
  negind =which(y==0) # where subject is positive
  sampn = sample(x = negind,size = nn,replace = repl)
  X_n = X[sampn,]
  y_n = y[sampn]
  
  
  return(list(X=X,y=y,X_p=X_p,X_n = X_n,sampp=sampp,sampn = sampn))}
hsong1/PUlearning documentation built on May 16, 2017, 11:27 p.m.