Page 1 of 1

Outside good or not for my MCDEV?

Posted: 03 Sep 2024, 16:46
by dce.farmers
Dear Apollo users,

I have a conceptual type of question.
I would like to use the MCDEV model to model the amount of land that my farmers decided to allocate to the planting of resistant grapevine varieties in alternative 1 and 2 (scenarios specified with different attributes characterising how they would like to carry the planting of these resistant varieties, hypothetically) in my Discrete choice experiment. In fact, they were asked, how much of their land (so between 0 and 100%) they would like to allocate to alternative 1 and 2.

I am not sure however if I use the MCDEV model with or without an outside good. I did have a status quo option (my alternative 3) that could be selected by farmers if they did not want to plant resistant grapevine varieties at all, which implicitly meant that they would keep their non-resistant varieties instead.
Given my alternative 3/status quo, does it mean that I should use the MCDEV model with an outside good? My outside good being the non-resistant varieties?

Thank you!

Best wishes,
Gaëlle

Re: Outside good or not for my MCDEV?

Posted: 04 Sep 2024, 00:51
by stephanehess
Hi

an outside good can never have a zero allocation, so in your case, that wouldn't work anyway.

Given that your study looks at allocation, you may also want to just look at a fractional logit model instead of MDCEV - details are in the manual and there's an example on the website too

Stephane

Re: Outside good or not for my MCDEV?

Posted: 05 Sep 2024, 10:12
by dce.farmers
Dear Stephane,

Thank you for your answer. The fmnl model looks interesting but I am not sure if I can use it in my case for the following reasons:

- farmers were not asked to indicate the share of land they would allocate to the status quo (alternative 3) in case they selected it. I could however assume that this would be a share of 100% in case they did select the status quo.

- farmers were asked to consider alternative 1 and then alternative 2 separately, one after the other, because it would have made little sense to consider them at the same time. So the sum of shares between alternative 1 and 2 does not always sum up to 100.

Can I still use the fmnl model despite these precisions? Would the MCDEV make better sense instead otherwise? If not, what other model?

Thank you,

Best,
Gaëlle

Re: Outside good or not for my MCDEV?

Posted: 07 Sep 2024, 17:10
by stephanehess
Hi

can you explain the survey a bit more to me, maybe with a screenshot or something?

Stephane

Re: Outside good or not for my MCDEV?

Posted: 08 Sep 2024, 11:33
by dce.farmers
Yes of course.

I am attaching a screenshot of a choice card below. The status quo has specific levels of attributes and we also made it clear to farmers that they would not plant any resistant varieties by choosing the status quo. For each choice card, farmers were asked the following question: "What would be the percentage of land you would like to plant with resistant varieties if you were: either a) in scenario A or b) in scenario B" (so not considering the two alternatives simultaneously but sequentionally, the sum of the shares for A and B in each choice card could therefore be superior to 100). Farmers were then asked to make a discrete choice between the alternatives.


Here is the complete list of attributes and levels as well in case this helps:
-Attribute a: Technical support before the replantation 1.None 2. Personalized 3. Collective
- Attribute b: Replantation work 1.Individual approach 2.Share of material and/or labour through independent group 3.Share of material and/or labour through cooperative
- Attribute c: Investment cost: 40 000 euros/ha, 44 000euros/ha, 48 000euros/ha, 52 000 euros/ha
- Attribute d: Crop protection practices for resistant varieties 1.Individual approach 2.Share of material and/or labour through independent group
3.Share of material and/or labour through cooperative
- Attribute e: Technical support after the replantation 1.Personalized 2. Collective

Let me know if you need more information.

Best,
Gaëlle

Re: Outside good or not for my MCDEV?

Posted: 09 Sep 2024, 20:35
by stephanehess
Hi

so in that case, would it make most sense to treat each screen as giving you three choices:

- a FMNL choice between A and the opt-out (summing to 100)
- a FMNL choice between B and the opt-out (summing to 100)
- a discrete (most likely nested logit) choice between A, B and the opt-out

Stephane

Re: Outside good or not for my MCDEV?

Posted: 16 Sep 2024, 13:51
by dce.farmers
Thank you so much Stephane.

I have therefore estimated a FMNL for the share allocated to A vs. status quo (alt3) and then seperately again a FMNL for the share allocated to B vs. status quo by having two separated codes (see code below, the other one is exactly the same but by replacing alt1 by alt2).
1. Is my code correct?
2. Would it be feasible and more reasonnable maybe to include both alternatives (alt1 and alt2) in the same model in the same code? If so, how could I code this? It would be something with 2 statusquo/alt3, the one that sums up to 100 with alt1 and the one that sums up to 100 with alt2. The aim would be to have just one set of parameters as results (instead of one set for alt1 vs SQ and one for alt2 vs. SQ) but i am not sure whether this is reasonnable/feasible.

Thank you!

Code: Select all

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName       = "FMNL",
  modelDescr      = "Fractional MNL model to explain share land allocated to Alt1 vs. Status quo (Alt3)",
  indivID         = "RID", 
  outputDirectory = "output"
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS                     ####
# ################################################################# #

### Loading data from package
### if data is to be loaded from a file (e.g. called data.csv), 
### the code would be: database = read.csv("data.csv",header=TRUE)
setwd("C:/Users/****/Nextcloud/Documents/Choice Experiment/Apollo")
database = read.csv("widedata.csv",header=TRUE)

##Check if missing observations for the variable shares
non_missing_count <- sum(!is.na(database$Sha_alt1))

# Print the result
non_missing_count

database <- database[order(database$RID), ]

### Convert time use into percentage of a day
#tmp <- grep("^t_a", names(database), value=TRUE)
#database[,tmp] <- database[,tmp]/database$budget
#rm(tmp)

# ################################################################# #
#### DEFINE MODEL PARAMETERS                                     ####
# ################################################################# #

##Create the alt3 that is alt1 -100##

database$Sha_alt3_alt1 <- 100 - database$Sha_alt1

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c (asc_alt3        = 0,
              b_suppnone       = 0,
              b_suppindiv      = 0,
              b_suppcoll       = 0,
              b_tvxindiv       = 0,
              b_tvxindgp       = 0,
              b_tvxcoop        = 0,
              b_cost           = 0,
              b_pulvindiv      = 0,
              b_pulvindgp      = 0,
              b_pulvcoop       = 0,
              b_techindiv      = 0, 
              b_techcoll       = 0)

### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("asc_alt3", "b_suppnone", "b_tvxindiv", "b_pulvindiv", "b_techcoll")

# ################################################################# #
#### GROUP AND VALIDATE INPUTS                                   ####
# ################################################################# #

apollo_inputs = apollo_validateInputs()

# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION                        ####
# ################################################################# #

apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
  
  ### Attach inputs and detach after function exit
  apollo_attach(apollo_beta, apollo_inputs)
  on.exit(apollo_detach(apollo_beta, apollo_inputs))
  
  ### Create list of probabilities P
  P = list()
  
  ### List of utilities: these must use the same names as in fmnl_settings, order is irrelevant
  V = list()
  V[["alt1"]] = b_suppnone*(SUPP1==1) + b_suppindiv*(SUPP1==2) + b_suppcoll*(SUPP1==3) + b_tvxindiv*(TVX1==1) + b_tvxindgp*(TVX1==2) + b_tvxcoop*(TVX1==3) + b_cost*COST1 + b_pulvindiv*(PULV1==1) + b_pulvindgp*(PULV1==2) + b_pulvcoop*(PULV1==3) + b_techindiv*(TECH1==1) + b_techcoll*(TECH1==2)                      
  V[["alt3"]] = asc_alt3 + b_suppnone*(SUPP3==1)
  
  ### Define settings for MNL model component
  fmnl_settings = list(
    alternatives  = c("alt1","alt3"), 
    choiceShares  = list(alt1 = Sha_alt1/100, 
                         alt3 = Sha_alt3_alt1/100), 
    utilities     = V
  )
  
  ### Compute probabilities using FMNL model
  P[["model"]] = apollo_fmnl(fmnl_settings, functionality)
  
  ### Take product across observation for same individual
  P = apollo_panelProd(P, apollo_inputs, functionality)
  
  ### Prepare and return outputs of function
  P = apollo_prepareProb(P, apollo_inputs, functionality)
  return(P)
}

# ################################################################# #
#### MODEL ESTIMATION                                            ####
# ################################################################# #

model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)

Re: Outside good or not for my MCDEV?

Posted: 20 Sep 2024, 08:10
by stephanehess
Hi

what you could do is to have two model components, one for 1 vs 3 and one for 2 vs 3, both FMNL, and both using the same parameters. You would then combine them with apollo_combineModels

Stephane

Re: Outside good or not for my MCDEV?

Posted: 27 Oct 2024, 15:44
by dce.farmers
Thank you Stephane!

I did try to use apollo_combineModels to combine them but I am running into erros. Could you please help me with this? :mrgreen: Thank you!

This is the error I get:
combinedModels <- apollo_combineModels(list(P1 = apollo_probabilities1, P2 = apollo_probabilities2), apollo_inputs, functionality = "validate")
Error in f(init, x[]):
non-numeric argument to binary operator

This is my code where I try to combine both models:

Code: Select all

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName       = "FMNL",
  modelDescr      = "Fractional MNL model to explain share land allocated to Alt1 vs. Status quo (Alt3)",
  indivID         = "RID", 
  outputDirectory = "output"
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS                     ####
# ################################################################# #

### Loading data from package
### if data is to be loaded from a file (e.g. called data.csv), 
### the code would be: database = read.csv("data.csv",header=TRUE)
setwd("C:/Users/****/Nextcloud/Documents/Choice Experiment/Apollo")
database = read.csv("widedata.csv",header=TRUE)

##Check if missing observations for the variable shares
non_missing_count <- sum(!is.na(database$Sha_alt1))

# Print the result
non_missing_count

database <- database[order(database$RID), ]


# ################################################################# #
#### DEFINE MODEL PARAMETERS                                     ####
# ################################################################# #

##Create the alt3 that is alt1 -100##

database$Sha_alt3_alt1 <- 100 - database$Sha_alt1
database$Sha_alt3_alt2 <- 100 - database$Sha_alt2


### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c (asc_alt3        = 0,
               b_suppnone       = 0,
               b_suppindiv      = 0,
               b_suppcoll       = 0,
               b_tvxindiv       = 0,
               b_tvxindgp       = 0,
               b_tvxcoop        = 0,
               b_cost           = 0,
               b_pulvindiv      = 0,
               b_pulvindgp      = 0,
               b_pulvcoop       = 0,
               b_techindiv      = 0, 
               b_techcoll       = 0)

### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("b_suppnone", "b_tvxindiv", "b_pulvindiv", "b_techindiv")

# ################################################################# #
#### GROUP AND VALIDATE INPUTS                                   ####
# ################################################################# #

apollo_inputs = apollo_validateInputs()

# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION 1                     ####
# ################################################################# #

apollo_probabilities1=function(apollo_beta, apollo_inputs, functionality="estimate"){
  
  ### Attach inputs and detach after function exit
  apollo_attach(apollo_beta, apollo_inputs)
  on.exit(apollo_detach(apollo_beta, apollo_inputs))
  
  ### Create list of probabilities P
  P1 = list()
  
  ### List of utilities: these must use the same names as in fmnl_settings, order is irrelevant
  V = list()
  V[["alt1"]] = b_suppnone*(SUPP1==1) + b_suppindiv*(SUPP1==2) + b_suppcoll*(SUPP1==3) + b_tvxindiv*(TVX1==1) + b_tvxindgp*(TVX1==2) + b_tvxcoop*(TVX1==3) + b_cost*COST1 + b_pulvindiv*(PULV1==1) + b_pulvindgp*(PULV1==2) + b_pulvcoop*(PULV1==3) + b_techindiv*(TECH1==1) + b_techcoll*(TECH1==2)                      
  V[["alt3"]] = asc_alt3 + b_suppnone*(SUPP3==1)
  
  ### Define settings for MNL model component
  fmnl_settings1 = list(
    alternatives  = c("alt1","alt3"), 
    choiceShares  = list(alt1 = Sha_alt1/100, 
                         alt3 = Sha_alt3_alt1/100), 
    utilities     = V
  )
  
  ### Compute probabilities using FMNL model
  P1[["model"]] = apollo_fmnl(fmnl_settings1, functionality)
  
  ### Take product across observation for same individual
  P1 = apollo_panelProd(P1, apollo_inputs, functionality)
  
  ### Prepare and return outputs of function
  P1 = apollo_prepareProb(P1, apollo_inputs, functionality)
  return(P1)
}

apollo_probabilities1(apollo_beta, apollo_inputs, functionality="validate")

# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION 2                   ####
# ################################################################# #

apollo_probabilities2=function(apollo_beta, apollo_inputs, functionality="estimate"){
  
  ### Attach inputs and detach after function exit
  apollo_attach(apollo_beta, apollo_inputs)
  on.exit(apollo_detach(apollo_beta, apollo_inputs))
  
  ### Create list of probabilities P
  P2 = list()
  
  ### List of utilities: these must use the same names as in fmnl_settings, order is irrelevant
  V = list()
  V[["alt2"]] = b_suppnone*(SUPP1==1) + b_suppindiv*(SUPP1==2) + b_suppcoll*(SUPP1==3) + b_tvxindiv*(TVX1==1) + b_tvxindgp*(TVX1==2) + b_tvxcoop*(TVX1==3) + b_cost*COST1 + b_pulvindiv*(PULV1==1) + b_pulvindgp*(PULV1==2) + b_pulvcoop*(PULV1==3) + b_techindiv*(TECH1==1) + b_techcoll*(TECH1==2)                      
  V[["alt3"]] = asc_alt3 + b_suppnone*(SUPP3==1)
  
  ### Define settings for MNL model component
  fmnl_settings2 = list(
    alternatives  = c("alt2","alt3"), 
    choiceShares  = list(alt2 = Sha_alt2/100, 
                         alt3 = Sha_alt3_alt2/100), 
    utilities     = V
  )
  
  ### Compute probabilities using FMNL model
  P2[["model"]] = apollo_fmnl(fmnl_settings2, functionality)
  
  ### Take product across observation for same individual
  P2 = apollo_panelProd(P2, apollo_inputs, functionality)
  
  ### Prepare and return outputs of function
  P2 = apollo_prepareProb(P2, apollo_inputs, functionality)
  return(P2)
}

apollo_probabilities2(apollo_beta, apollo_inputs, functionality="validate")

# ################################################################# #
#### MODEL MERGING                                         ####
# ################################################################# #


combinedModels <- apollo_combineModels(list(P1 = apollo_probabilities1, P2 = apollo_probabilities2), apollo_inputs, functionality = "validate")

Re: Outside good or not for my MCDEV?

Posted: 04 Dec 2024, 12:49
by stephanehess
Hi

you need to do this inside the model, i.e. a single apollo_probabilites function with multiple model components. You can have a look at the RP-SP one as an example: https://apollochoicemodelling.com/files ... NL_RP_SP.r

Stephane