logo

Bivariate Kernel Density Estimation Using R tool

   

Added on  2023-05-30

7 Pages1046 Words425 Views
 | 
 | 
 | 
Running head: BIVARIATE KERNEL DENSITY ESTIMATION
1
Bivariate Kernel Density Estimation Using R tool
Student Name
Institution
Bivariate Kernel Density Estimation Using R tool_1

BIVARIATE KERNEL DENSITY ESTIMATION
2
The programming tool used for this assignment is R programming tool. The R code has
detailed comment on every step taken above the code.
R code
# R code for conducting a CTR analysis using generated data
# Load dependencies
# Code requires package fdrtool & survival to be in library
# install.packages("fdrtool")
require (fdrtool);require(survival)
#create data
# Next step is to generate example data "radio tagged distance", stored as object
x
mean(x)
sd(x)
# set random seed
set.seed(2009)
# generate data from lognormal distribution, 250 tracked seeds
# meanlog=log(15), sdlog=log(1.1)
x=rlnorm(250,log(15),log(1.1))
# truncate data after 20 units to create "tracked distances"
# with 20 m search radius
xtrunc=x[x<20]
# Prepare data for CTR
CTRdata=data.frame(
Bivariate Kernel Density Estimation Using R tool_2

BIVARIATE KERNEL DENSITY ESTIMATION
3
# all seeds that went beyond 20 meters are treated as censored events
# (distance > 20 meter)
d=c(xtrunc,rep(20,250-length(xtrunc))),
# classify events, found seeds = 1, censored seeds = 0
evnt=c(rep(1,length(xtrunc)),rep(0,250-length(xtrunc))))
# fitsurvival function
CTR_function=survfit(Surv(CTRdata$d, event=CTRdata$evnt) ~ 1)
# return survival probabilties (P) corresponding to distances (D)
P=summary(CTR_function)$surv;D=summary(CTR_function)$time
#Define dispersal kernels
# these kernels are then fit through OLS (Ordinary Least Squares) to objects P &D
# log normal
SSLN=function(param){
Ex=1-plnorm(D,meanlog=param[1],sdlog=param[2])
sum((Ex-P)^2)
}
# Weibull
SSW=function(param){
Ex=1-pweibull(D,shape=param[1],scale=param[2])
sum((Ex-P)^2)
}
# exponential
SSEX=function(param){
Bivariate Kernel Density Estimation Using R tool_3

End of preview

Want to access all the pages? Upload your documents or become a member.