compareCondDens <- function(z, dep = .5, plot = T)
{
	#this compares the actual conditional density values (as
	#given by dmvevd in the package evd), but normalized to 
	#account for conditional piece to the conditonal density
	#approximation
	
	#assumes the first two components are observed and are 
	#trying to approximate the conditional density of the third
	
	z1 <- z[1]
	z2 <- z[2]
	
	#gives set of points on spectral density
	upBd <- z1/(z1+z2)
	ratio21 <- z2/z1
	w1 <- seq(upBd, 0, length = 201)
	w2 <- w1*ratio21
	w3 <- 1 - w1 - w2	
	w <- cbind(w1, w2, w3)
	
	#gives corresponding values of spectral density
	sd <- h(w, alpha = dep)

	#gives corresponding radii
	rad <- z1/w1
	
	#gives corresponding values of z3
	z3 <- w3*rad
	

	#densVal1 corresponds to the approximation found in the paper 
	#densVal2 corresponds with the 'true' conditional density 
	#	values obtained by the evd package for the logistic
	#	model, normalized by numerical integration


	#densVal1 obtained
	unDensVal1 <- rad^(-4)*sd
	unDensVal1[is.nan(unDensVal1)] <- 0
	#normalizing (uses trapezoidal rule with crude adjustment for
	#infininte end)
	z3Temp <- z3
	z3Temp[length(z3Temp)] <- 2 * z3Temp[length(z3Temp) - 1]
	deltaZ3 <- z3Temp[2:(length(z3Temp))] - 
				z3Temp[1:(length(z3Temp) - 1)] 
	piece11 <- deltaZ3 * unDensVal1[1:(length(unDensVal1) - 1)]
	piece12 <- deltaZ3 * unDensVal1[2:(length(unDensVal1))]
	traps1 <- 1/2*(piece11 + piece12)
	normalizer1 <- sum(traps1)
	cumTraps1 <- c(0, cumsum(traps1))/normalizer1
	densVal1 <- unDensVal1/normalizer1
	
	
	
	#densVal2 obtained
	z1l <- rep(z1, length(z3))
	z2l <- rep(z2, length(z3))
	zAll <- cbind(z1, z2, z3)
	unDensVal2 <- dmvevd(zAll, dep = dep, model = "log", d = 3, mar = c(1,1,1))
#	#normalizing (uses trapezoidal rule)
#	piece21 <- deltaZ3 * unDensVal2[1:(length(unDensVal2) - 1)]
#	piece22 <- deltaZ3 * unDensVal2[2:(length(unDensVal2))]
#	traps2 <- 1/2*(piece21 + piece22)
#	normalizer2 <- sum(traps2)
#	cumTraps2 <- c(0, cumsum(traps2))/normalizer2
#	densVal2 <- unDensVal2/normalizer2
	#normalizing, using simpson's rule for unequal nodes
	cumTraps2 <- unequalSimpson(z3Temp, unDensVal2)
	normalizer2 <- cumTraps2[length(cumTraps2)]
	densVal2 <- unDensVal2/normalizer2
	cumTraps2 <- cumTraps2/normalizer2	
	
	if(plot)
	{
		#op <- par(mfrow = c(1,2))
		plot(z3, densVal2, type = 'l', xlim = c(0,2*sum(z)), ylab = "density", xlab = "", ylim = range(c(densVal1, densVal2)), lty = 3)
		lines(z3, densVal1)
#		lines(z3, densVal3, col = 2)
		#diff <- unDensVal1 - unDensVal2
		#plot(z3, diff, type = 'l', xlim = c(0,2*sum(z)))
		#par(op)
	}


	return(cbind(z3, densVal1, cumTraps1, densVal2, cumTraps2, rad))
}

		
	
		