[R] Solving two nonlinear equations with two knowns

yhsu6 at illinois.edu yhsu6 at illinois.edu
Fri Jul 17 16:24:34 CEST 2009


My question is as follows 
Y~N(mu2,sigma2^2), i.e. Y has cdf F2   

X generates from: 
X=F2^{-1}(u)+a*|u-tau|^b*I(u>0.75), where u~U(0,1) 

Given tau=0.75, I want to find a and b such that 
E(X)-E(Y)=2 and Var(X)/Var(Y)=3 

I try optim and grid seaching and get different results, any solution? 


Thanks, 

Kate 
########## 
#R code: 
mu2=0.4 
sigma2=4 
tau=0.75 
mean.diff=2 
var.ratio=3 

#Use optim: 
parameter<-function(c) 
{ 
a<-c[1] 
b<-c[2] 
u<-runif(10000) 
Y<-qnorm(u,mean=mu2,sd=sigma2) 
u<-runif(10000) 
X<-qnorm(u,mean=mu2,sd=sigma2)+a*abs(u-tau)^b*(u>tau) 
return((abs(mean(X)-mean(Y))-mean.diff)^2+(var(X)/var(Y)-var.ratio)^2) 
} 


c0<-c(3,1) 
cstar<-optim(c0,parameter)$par 
astar<-cstar[1] #4.1709 
bstar<-cstar[2] #-0.2578 

#Use grid seaching (I randomly assign a rage (-10,100)): 
parameter.X<-function(a,b) 
{ 
TSE<-matrix(0, length(a),length(b)) 
u<-runif(10000) 
Y<-qnorm(u,mean=mu2,sd=sigma2) 
u<-runif(10000) 
for(i in 1: length(a)) 
{ 
for(j in 1: length(b)) 
{ 
X<-qnorm(u,mean=mu2,sd=sigma2)+a[i]*abs(u-tau)^b[j]*(u>tau) 
TSE[i,j]<-(abs(mean(X)-mean(Y))-mean.diff)^2+(var(X)/var(Y)-var.ratio)^2 
} 
} 
minTSE<-min(TSE) 
a.optimal<-a[which(TSE==min(TSE),arr.ind = TRUE)[1]] 
b.optimal<-b[which(TSE==min(TSE),arr.ind = TRUE)[2]] 
return(list(a.optimal=a.optimal,b.optimal=b.optimal,minTSE=minTSE)) 
} 

a0<-seq(-10,100,,50) 
b0<-seq(-10,100,,50) 
tse1<-parameter.X(a0,b0) 

astar<-tse1$a.optimal # 84.28571 
bstar<-tse1$b.optimal #1.224490




More information about the R-help mailing list