Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # alpha is 50 x 1 (for 50 products)
- # psi is 50 x 1
- # 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)
- # constraint is price*x=budget where x is 50 x 1 and price is 50 x 1
- # 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.
- x=matrix(0,nrow=51,ncol=1)
- fr <- function(x) {
- U = rowSums(1/alpha*psi*((x/1+1)^alpha-1),na.rm = TRUE)
- }
- s0 <- matrix(c(
- 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
- ),
- ncol = ncol(alpha)
- )
- ui <- -1*matrix(c(
- 1.690000, 1.390000, 1.150000, 1.290000, 1.590000, 1.850000, 1.790000, 1.690000, 0.890000, 1.990000,
- 1.290000, 0.890000, 1.600000, 0.990000, 1.090000, 1.190000, 0.690000, 0.390000, 3.590000, 1.690000,
- 1.490000, 1.890000, 0.790000, 1.990000, 1.890000, 0.990000, 1.090000, 0.690000, 1.990000, 1.990000,
- 1.690000, 1.690000, 2.490000, 1.390000, 1.490000, 1.990000, 1.690000, 1.850000, 1.219630, 1.590000,
- 1.690000, 0.790000, 1.590000, 1.979011, 1.390000, 1.390000, 1.490000, 0.990000, 1.290000, 1.690000,
- 1.240271
- ),
- ncol = ncol(alpha)
- )
- ci <- -20
- constrOptim(s0, fr, ui=ui, ci=ci, control = list(fnscale = -1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement