[R] To find vector X under contraints

Uwe Ligges ligges at statistik.tu-dortmund.de
Mon Sep 8 13:55:54 CEST 2008



Shubha Vishwanath Karanth wrote:
> Hi R,
> 
>  
> 
> I have the variance-covariance matrix,
> 
>  
> 
>> V=matrix(c(0.011119238, 0.002407527, 0.002407527, 0.020739401),2,2)
> 
>  
> 
> I need to find a vector X=c(x1,x2), such that 
> 
> 1) X'VX is equal to a constant 2 (say) and 
> 
> 2) sum(x) should be equal to a another constant 1.5 (say).
> 
>  
> 
> How do we do this in R?

You can try to optimize using optim() with an appropriate function to be 
minimized such as f(X) = (X'VX-2)^2 + (sum(X)-1.5)^2

Uwe Ligges





>  
> 
>  
> 
> BR, Shubha
> 
> Shubha Karanth | Amba Research
> 
> Ph +91 80 3980 8031 | Mob +91 94 4886 4510 
> 
> Bangalore * Colombo * London * New York * San José * Singapore * www.ambaresearch.com
> 
>  
> 
>  
> 
> This e-mail may contain confidential and/or privileged i...{{dropped:13}}
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list