[R-sig-eco] generate pseudo-absences

Lars Westerberg lawes at ifm.liu.se
Mon Feb 13 14:38:05 CET 2012


Try:
n <- 10
x <- round(runif(10)) #array with 0 and 1
pos0 <- which(x==0) #position of 0's
n0 <- length(pos0) # number of 0's
npseudo <- round(n0*0.5) # proportion of 0's (here 50%)
pseudo0 <- sort(sample(pos0)[1:npseudo]) #Select and sort 0's to be 
pseudo-absence 0's

# alt. pseudo-absence as a proportion of presence
n1 <- n-n0
prop <- 5
#Next line checks that desired number of pseudo-absence is less than 
existing absences
if(prop*n1>n0) stop(paste("Too few 0's. Can not create ",prop*n1," 
pseudo-absence's"))
#For this example, set proportion to 30%
prop <- 0.3
npseudo <- round(n1*prop) # Number of pseudo-absence as a proportion of 1's
pseudo0 <- sort(sample(pos0)[1:npseudo]) #Sample/select and sort 0's to 
be pseudo-absence 0's

# Observed data with pseduo-absence as presence (1)
x[pseudo0] <- 1

HTH
/Lars

On 2/10/2012 10:39 PM, Frederico Mestre wrote:
> Hello all:
>
>
>
> I've got a data frame with a column of presence-only data (0 and 1) and the
> variables of interest in modeling its distribution.
>
>
>
> I want to select a number of "0" as pseudo-absences, such as a proportion of
> the "0" or 5 (for example) times the number of presences.
>
>
>
> How can it be done?
>
>
>
> Thanks,
>
>
>
> Frederico Mestre
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


-- 
Lars Westerberg, PhD
IFM Biology, division of Ecology
Linköpings University
+46 (0) 13 28 12 61
+46 (0) 70 716 86 85



More information about the R-sig-ecology mailing list