Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. # alpha is 50 x 1 (for 50 products)
  2. # psi is 50 x 1
  3. # U = utility (objective function is to maximise the utility obtained from consuming the 50 products) = rowSums(gamma1/alpha[hh,1]*psi[hh,1]*((x/gamma1+1)^alpha[hh,1]-1)
  4. # constraint is price*x=budget where x is 50 x 1 and price is 50 x 1
  5. # below is for 1 purchase occasion. Ultimately, I would like to have n occasions and each occasion will have a different budget. Assume price of the 50 products stay constant for now.
  6.  
  7. x=matrix(0,nrow=51,ncol=1)
  8. fr <- function(x) {
  9. U = rowSums(1/alpha*psi*((x/1+1)^alpha-1),na.rm = TRUE)
  10. }
  11.  
  12. s0 <- matrix(c(
  13. 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0
  14. ),
  15. ncol = ncol(alpha)
  16. )
  17.  
  18. ui <- -1*matrix(c(
  19. 1.690000, 1.390000, 1.150000, 1.290000, 1.590000, 1.850000, 1.790000, 1.690000, 0.890000, 1.990000,
  20. 1.290000, 0.890000, 1.600000, 0.990000, 1.090000, 1.190000, 0.690000, 0.390000, 3.590000, 1.690000,
  21. 1.490000, 1.890000, 0.790000, 1.990000, 1.890000, 0.990000, 1.090000, 0.690000, 1.990000, 1.990000,
  22. 1.690000, 1.690000, 2.490000, 1.390000, 1.490000, 1.990000, 1.690000, 1.850000, 1.219630, 1.590000,
  23. 1.690000, 0.790000, 1.590000, 1.979011, 1.390000, 1.390000, 1.490000, 0.990000, 1.290000, 1.690000,
  24. 1.240271
  25. ),
  26. ncol = ncol(alpha)
  27. )
  28.  
  29. ci <- -20
  30.  
  31. constrOptim(s0, fr, ui=ui, ci=ci, control = list(fnscale = -1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement