Modfed: Modified Federov algorithm for MNL models.

Description Usage Arguments Details Value References Examples

View source: R/efficiency_algorithms.R

Description

The algorithm swaps every profile of an initial start design with candidate profiles. By doing this, it tries to minimize the D(B)-error, based on a multinomial logit model. This routine is repeated for multiple starting designs.

Usage

1
2
3
Modfed(cand.set, n.sets, n.alts, par.draws, alt.cte = NULL,
  no.choice = FALSE, start.des = NULL, parallel = TRUE,
  max.iter = Inf, n.start = 12, best = TRUE)

Arguments

cand.set

A numeric matrix in which each row is a possible profile. The Profiles function can be used to generate this matrix.

n.sets

Numeric value indicating the number of choice sets.

n.alts

Numeric value indicating the number of alternatives per choice set.

par.draws

A matrix or a list, depending on alt.cte.

alt.cte

A binary vector indicating for each alternative whether an alternative specific constant is desired. The default is NULL.

no.choice

A logical value indicating whether a no choice alternative should be added to each choice set. The default is FALSE.

start.des

A list containing one or more matrices corresponding to initial start design(s). The default is NULL.

parallel

Logical value indicating whether computations should be done over multiple cores. The default is TRUE.

max.iter

A numeric value indicating the maximum number allowed iterations. The default is Inf.

n.start

A numeric value indicating the number of random start designs to use. The default is 12.

best

A logical value indicating whether only the best design should be returned. The default is TRUE.

Details

Each iteration will loop through all profiles from the initial design, evaluating the change in D(B)-error for every profile from cand.set. The algorithm stops when an iteration occured without replacing a profile or when max.iter is reached.

By specifying a numeric vector in par.draws, the D-error will be calculated and the design will be optimised locally. By specifying a matrix, in which each row is a draw from a multivariate distribution, the DB-error will be calculated, and the design will be optimised globally. Whenever there are alternative specific constants, par.draws should be a list containing two matrices: The first matrix containing the parameter draws for the alternative specific constant parameters. The second matrix containing the draws for the rest of the parameters.

The DB-error is calculated by taking the mean over D-errors. It could be that for some draws the design results in an infinite D-error. The percentage of draws for which this was true for the final design can be found in the output inf.error.

Alternative specific constants can be specified in alt.cte. The length of this binary vector should equal n.alts, were 0 indicates the absence of an alternative specific constant and 1 the opposite.

start.des is a list with one or several matrices corresponding to initial start design(s). In each matrix each row is a profile. The number of rows equals n.sets * n.alts, and the number of columns equals the number of columns of cand.set + the number of non-zero elements in alt.cte. If start.des = NULL, n.start random initial designs will be generated. If start designs are provided, n.start is ignored.

If no.choice is TRUE, in each choice set an alternative with one alternative specific constant is added. The return value of the D(B)-error is however based on the design without the no choice option.

When parallel is TRUE, detectCores will be used to decide upon the number of available cores. That number minus 1 cores will be used to search for efficient designs. The computation time will decrease significantly when parallel = TRUE.

Value

If best = TRUE the design with the lowest D(B)-error is returned. If best = FALSE, the results of all (provided) start designs are returned.

design

A numeric matrix wich contains an efficient design.

error

Numeric value indicating the D(B)-error of the design.

inf.error

Numeric value indicating the percentage of draws for which the D-error was Inf.

probs

Numeric matrix containing the probabilities of each alternative in each choice set. If a sample matrix was provided in par.draws, this is the average over all draws.

References

\insertRef

idefixidefix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## Not run: 
# DB-efficient designs
# 3 Attributes, all dummy coded. 1 alternative specific constant = 7 parameters
cand.set <- Profiles(lvls = c(3, 3, 3), coding = c("D", "D", "D"))
mu <- c(0.5, 0.8, 0.2, -0.3, -1.2, 1.6, 2.2) # Prior parameter vector
v <- diag(length(mu)) # Prior variance.
set.seed(123) 
pd <- MASS::mvrnorm(n = 10, mu = mu, Sigma = v) # 10 draws.
p.d <- list(matrix(pd[,1], ncol = 1), pd[,2:7])
Modfed(cand.set = cand.set, n.sets = 8, n.alts = 2, 
       alt.cte = c(1, 0), parallel = FALSE, par.draws = p.d, best = FALSE)

# DB-efficient design with start design provided.  
# 3 Attributes with 3 levels, all dummy coded (= 6 parameters).
cand.set <- Profiles(lvls = c(3, 3, 3), coding = c("D", "D", "D")) 
mu <- c(0.8, 0.2, -0.3, -0.2, 0.7, 0.4) # Prior mean (total = 5 parameters).
v <- diag(length(mu)) # Prior variance.
sd <- list(example_design)
set.seed(123)
ps <- MASS::mvrnorm(n = 10, mu = mu, Sigma = v) # 10 draws.
Modfed(cand.set = cand.set, n.sets = 8, n.alts = 2, 
       alt.cte = c(0, 0), parallel = FALSE, par.draws = ps, start.des = sd)

## End(Not run)

Example output

Loading required package: shiny
[[1]]
[[1]]$design
          alt1.cte Var12 Var13 Var22 Var23 Var32 Var33
set1.alt1        1     1     0     1     0     0     0
set1.alt2        0     0     0     0     0     0     1
set2.alt1        1     0     0     0     0     0     0
set2.alt2        0     0     1     0     1     1     0
set3.alt1        1     0     1     0     1     0     0
set3.alt2        0     1     0     1     0     0     0
set4.alt1        1     0     0     0     1     1     0
set4.alt2        0     0     1     0     0     0     0
set5.alt1        1     0     1     1     0     1     0
set5.alt2        0     1     0     0     1     0     1
set6.alt1        1     0     1     1     0     0     1
set6.alt2        0     1     0     0     0     1     0
set7.alt1        1     0     1     0     0     0     0
set7.alt2        0     0     0     1     0     0     0
set8.alt1        1     0     0     1     0     0     0
set8.alt2        0     1     0     0     1     0     1

[[1]]$error
[1] 2.03506

[[1]]$inf.error
[1] 0

[[1]]$probs
      Pr(alt1)  Pr(alt2)
set1 0.3939043 0.6060957
set2 0.5600010 0.4399990
set3 0.2596024 0.7403976
set4 0.6121064 0.3878936
set5 0.6545990 0.3454010
set6 0.5506264 0.4493736
set7 0.6320556 0.3679444
set8 0.2992373 0.7007627


[[2]]
[[2]]$design
          alt1.cte Var12 Var13 Var22 Var23 Var32 Var33
set1.alt1        1     1     0     1     0     1     0
set1.alt2        0     0     1     0     0     0     1
set2.alt1        1     1     0     0     1     0     1
set2.alt2        0     0     0     1     0     1     0
set3.alt1        1     0     0     1     0     0     0
set3.alt2        0     0     1     0     0     0     1
set4.alt1        1     0     0     1     0     0     1
set4.alt2        0     1     0     0     0     1     0
set5.alt1        1     0     0     0     0     0     0
set5.alt2        0     0     1     0     1     1     0
set6.alt1        1     0     1     0     0     0     0
set6.alt2        0     0     0     1     0     0     1
set7.alt1        1     0     1     1     0     0     0
set7.alt2        0     0     0     0     1     1     0
set8.alt1        1     0     1     0     1     1     0
set8.alt2        0     1     0     0     1     0     0

[[2]]$error
[1] 1.970279

[[2]]$inf.error
[1] 0

[[2]]$probs
      Pr(alt1)  Pr(alt2)
set1 0.6504600 0.3495400
set2 0.5305600 0.4694400
set3 0.2099733 0.7900267
set4 0.5030403 0.4969597
set5 0.5600010 0.4399990
set6 0.2984251 0.7015749
set7 0.6150238 0.3849762
set8 0.7635427 0.2364573


[[3]]
[[3]]$design
          alt1.cte Var12 Var13 Var22 Var23 Var32 Var33
set1.alt1        1     0     0     1     0     1     0
set1.alt2        0     0     1     0     0     0     1
set2.alt1        1     0     0     0     0     1     0
set2.alt2        0     0     0     0     1     0     1
set3.alt1        1     0     1     1     0     0     0
set3.alt2        0     1     0     0     1     1     0
set4.alt1        1     0     1     0     1     1     0
set4.alt2        0     0     0     0     0     0     0
set5.alt1        1     0     0     0     1     0     0
set5.alt2        0     0     1     1     0     0     0
set6.alt1        1     0     0     0     1     0     1
set6.alt2        0     1     0     0     1     0     0
set7.alt1        1     0     1     0     0     1     0
set7.alt2        0     1     0     1     0     0     1
set8.alt1        1     1     0     0     1     0     0
set8.alt2        0     0     0     0     1     1     0

[[3]]$error
[1] 2.215915

[[3]]$inf.error
[1] 0

[[3]]$probs
      Pr(alt1)  Pr(alt2)
set1 0.5158263 0.4841737
set2 0.7704242 0.2295758
set3 0.4349190 0.5650810
set4 0.6599613 0.3400387
set5 0.3273547 0.6726453
set6 0.7978913 0.2021087
set7 0.4034655 0.5965345
set8 0.4427888 0.5572112


[[4]]
[[4]]$design
          alt1.cte Var12 Var13 Var22 Var23 Var32 Var33
set1.alt1        1     1     0     1     0     1     0
set1.alt2        0     0     0     0     0     0     1
set2.alt1        1     0     0     0     1     0     0
set2.alt2        0     0     1     0     0     0     0
set3.alt1        1     0     1     1     0     0     0
set3.alt2        0     1     0     0     1     1     0
set4.alt1        1     0     0     0     1     0     1
set4.alt2        0     1     0     0     0     0     0
set5.alt1        1     0     0     0     0     1     0
set5.alt2        0     1     0     0     1     0     1
set6.alt1        1     0     0     0     0     0     0
set6.alt2        0     0     1     0     1     1     0
set7.alt1        1     0     1     0     0     0     0
set7.alt2        0     0     0     1     0     0     1
set8.alt1        1     0     1     0     0     0     1
set8.alt2        0     0     0     1     0     1     0

[[4]]$error
[1] 1.974534

[[4]]$inf.error
[1] 0

[[4]]$probs
      Pr(alt1)  Pr(alt2)
set1 0.6927579 0.3072421
set2 0.3209794 0.6790206
set3 0.4349190 0.5650810
set4 0.4934461 0.5065539
set5 0.6094862 0.3905138
set6 0.5600010 0.4399990
set7 0.2984251 0.7015749
set8 0.7193478 0.2806522


[[5]]
[[5]]$design
          alt1.cte Var12 Var13 Var22 Var23 Var32 Var33
set1.alt1        1     0     0     0     1     0     1
set1.alt2        0     1     0     0     0     0     0
set2.alt1        1     0     1     0     0     0     0
set2.alt2        0     1     0     0     1     0     1
set3.alt1        1     0     1     0     1     0     1
set3.alt2        0     0     0     0     1     1     0
set4.alt1        1     0     0     1     0     0     0
set4.alt2        0     1     0     0     1     1     0
set5.alt1        1     0     1     1     0     1     0
set5.alt2        0     0     0     0     0     0     1
set6.alt1        1     1     0     1     0     0     0
set6.alt2        0     0     0     0     0     1     0
set7.alt1        1     1     0     0     0     0     0
set7.alt2        0     0     1     1     0     0     1
set8.alt1        1     0     0     1     0     1     0
set8.alt2        0     0     1     0     1     0     1

[[5]]$error
[1] 2.064151

[[5]]$inf.error
[1] 0

[[5]]$probs
      Pr(alt1)  Pr(alt2)
set1 0.4934461 0.5065539
set2 0.3499510 0.6500490
set3 0.7339624 0.2660376
set4 0.3883984 0.6116016
set5 0.5663089 0.4336911
set6 0.4625583 0.5374417
set7 0.4016106 0.5983894
set8 0.7165908 0.2834092


[[6]]
[[6]]$design
          alt1.cte Var12 Var13 Var22 Var23 Var32 Var33
set1.alt1        1     1     0     0     1     0     0
set1.alt2        0     0     0     0     0     0     0
set2.alt1        1     0     0     1     0     1     0
set2.alt2        0     1     0     0     0     0     1
set3.alt1        1     0     1     0     0     0     1
set3.alt2        0     1     0     1     0     1     0
set4.alt1        1     0     1     1     0     0     0
set4.alt2        0     0     0     0     1     1     0
set5.alt1        1     0     0     0     0     0     0
set5.alt2        0     0     1     0     1     0     1
set6.alt1        1     0     0     1     0     0     1
set6.alt2        0     0     1     0     0     1     0
set7.alt1        1     0     1     0     1     1     0
set7.alt2        0     1     0     0     1     0     0
set8.alt1        1     0     1     1     0     0     0
set8.alt2        0     1     0     0     0     1     0

[[6]]$error
[1] 2.014211

[[6]]$inf.error
[1] 0

[[6]]$probs
      Pr(alt1)  Pr(alt2)
set1 0.4746443 0.5253557
set2 0.3557405 0.6442595
set3 0.5432689 0.4567311
set4 0.6150238 0.3849762
set5 0.4846091 0.5153909
set6 0.6373371 0.3626629
set7 0.7635427 0.2364573
set8 0.2060361 0.7939639


[[7]]
[[7]]$design
          alt1.cte Var12 Var13 Var22 Var23 Var32 Var33
set1.alt1        1     0     1     0     0     0     1
set1.alt2        0     0     0     1     0     1     0
set2.alt1        1     0     1     1     0     1     0
set2.alt2        0     0     0     0     0     0     1
set3.alt1        1     0     0     0     1     0     1
set3.alt2        0     1     0     0     0     0     0
set4.alt1        1     0     0     1     0     0     0
set4.alt2        0     1     0     0     1     1     0
set5.alt1        1     0     0     0     0     1     0
set5.alt2        0     0     1     1     0     0     1
set6.alt1        1     1     0     1     0     1     0
set6.alt2        0     0     1     0     1     0     1
set7.alt1        1     1     0     1     0     0     0
set7.alt2        0     0     1     0     0     1     0
set8.alt1        1     0     1     0     0     0     0
set8.alt2        0     0     0     1     0     0     1

[[7]]$error
[1] 1.92047

[[7]]$inf.error
[1] 0

[[7]]$probs
      Pr(alt1)  Pr(alt2)
set1 0.7193478 0.2806522
set2 0.5663089 0.4336911
set3 0.4934461 0.5065539
set4 0.3883984 0.6116016
set5 0.5378965 0.4621035
set6 0.8282069 0.1717931
set7 0.4328330 0.5671670
set8 0.2984251 0.7015749


[[8]]
[[8]]$design
          alt1.cte Var12 Var13 Var22 Var23 Var32 Var33
set1.alt1        1     0     0     0     1     0     1
set1.alt2        0     1     0     0     0     0     0
set2.alt1        1     0     1     1     0     0     0
set2.alt2        0     1     0     0     1     0     1
set3.alt1        1     1     0     1     0     0     0
set3.alt2        0     0     1     0     0     1     0
set4.alt1        1     0     0     1     0     1     0
set4.alt2        0     0     1     0     0     0     1
set5.alt1        1     1     0     0     0     1     0
set5.alt2        0     0     0     1     0     0     1
set6.alt1        1     0     0     0     0     0     1
set6.alt2        0     1     0     0     1     1     0
set7.alt1        1     0     1     1     0     0     1
set7.alt2        0     0     0     0     0     1     0
set8.alt1        1     0     1     0     0     0     0
set8.alt2        0     1     0     1     0     1     0

[[8]]$error
[1] 2.043119

[[8]]$inf.error
[1] 0

[[8]]$probs
      Pr(alt1)  Pr(alt2)
set1 0.4934461 0.5065539
set2 0.3530127 0.6469873
set3 0.4328330 0.5671670
set4 0.5158263 0.4841737
set5 0.6639083 0.3360917
set6 0.8065731 0.1934269
set7 0.7343044 0.2656956
set8 0.2350659 0.7649341


[[9]]
[[9]]$design
          alt1.cte Var12 Var13 Var22 Var23 Var32 Var33
set1.alt1        1     0     0     1     0     1     0
set1.alt2        0     0     1     0     0     0     1
set2.alt1        1     0     1     1     0     0     0
set2.alt2        0     0     0     0     1     0     1
set3.alt1        1     0     1     0     1     1     0
set3.alt2        0     0     0     1     0     0     1
set4.alt1        1     0     1     1     0     0     1
set4.alt2        0     1     0     0     0     1     0
set5.alt1        1     1     0     0     1     0     1
set5.alt2        0     0     0     1     0     1     0
set6.alt1        1     0     0     0     0     0     0
set6.alt2        0     1     0     0     1     1     0
set7.alt1        1     0     1     0     0     1     0
set7.alt2        0     1     0     1     0     0     0
set8.alt1        1     1     0     0     0     0     0
set8.alt2        0     0     1     0     1     1     0

[[9]]$error
[1] 1.911718

[[9]]$inf.error
[1] 0

[[9]]$probs
      Pr(alt1)  Pr(alt2)
set1 0.5158263 0.4841737
set2 0.5243941 0.4756059
set3 0.3215490 0.6784510
set4 0.5506264 0.4493736
set5 0.5305600 0.4694400
set6 0.3901932 0.6098068
set7 0.7365214 0.2634786
set8 0.6916024 0.3083976


[[10]]
[[10]]$design
          alt1.cte Var12 Var13 Var22 Var23 Var32 Var33
set1.alt1        1     0     0     1     0     0     1
set1.alt2        0     1     0     0     0     1     0
set2.alt1        1     0     0     0     1     1     0
set2.alt2        0     0     1     0     1     0     1
set3.alt1        1     1     0     0     1     0     0
set3.alt2        0     0     1     0     1     1     0
set4.alt1        1     0     1     1     0     0     0
set4.alt2        0     0     0     0     1     0     1
set5.alt1        1     0     0     0     0     0     1
set5.alt2        0     1     0     0     1     1     0
set6.alt1        1     0     1     0     0     0     0
set6.alt2        0     1     0     1     0     1     0
set7.alt1        1     0     1     0     1     0     1
set7.alt2        0     0     0     1     0     0     0
set8.alt1        1     0     1     0     0     1     0
set8.alt2        0     1     0     1     0     0     1

[[10]]$error
[1] 2.200042

[[10]]$inf.error
[1] 0

[[10]]$probs
      Pr(alt1)  Pr(alt2)
set1 0.5030403 0.4969597
set2 0.5292016 0.4707984
set3 0.4229261 0.5770739
set4 0.5243941 0.4756059
set5 0.8065731 0.1934269
set6 0.2350659 0.7649341
set7 0.7296663 0.2703337
set8 0.4034655 0.5965345


[[11]]
[[11]]$design
          alt1.cte Var12 Var13 Var22 Var23 Var32 Var33
set1.alt1        1     0     1     0     1     1     0
set1.alt2        0     1     0     0     0     0     0
set2.alt1        1     0     1     0     0     0     1
set2.alt2        0     1     0     0     1     1     0
set3.alt1        1     1     0     0     1     0     1
set3.alt2        0     0     0     1     0     1     0
set4.alt1        1     1     0     1     0     0     0
set4.alt2        0     0     0     0     1     0     1
set5.alt1        1     0     0     1     0     0     1
set5.alt2        0     0     1     0     0     1     0
set6.alt1        1     0     0     0     0     0     0
set6.alt2        0     1     0     0     1     1     0
set7.alt1        1     0     1     1     0     0     0
set7.alt2        0     0     0     0     0     1     0
set8.alt1        1     0     0     0     0     1     0
set8.alt2        0     0     1     1     0     0     1

[[11]]$error
[1] 1.968403

[[11]]$inf.error
[1] 0

[[11]]$probs
      Pr(alt1)  Pr(alt2)
set1 0.4702887 0.5297113
set2 0.8312682 0.1687318
set3 0.5305600 0.4694400
set4 0.6790485 0.3209515
set5 0.6373371 0.3626629
set6 0.3901932 0.6098068
set7 0.3445595 0.6554405
set8 0.5378965 0.4621035


[[12]]
[[12]]$design
          alt1.cte Var12 Var13 Var22 Var23 Var32 Var33
set1.alt1        1     1     0     1     0     1     0
set1.alt2        0     0     1     0     1     0     1
set2.alt1        1     1     0     0     1     1     0
set2.alt2        0     0     0     0     0     0     1
set3.alt1        1     0     0     1     0     0     0
set3.alt2        0     0     1     0     1     1     0
set4.alt1        1     0     1     1     0     0     1
set4.alt2        0     0     0     0     0     1     0
set5.alt1        1     0     1     1     0     0     0
set5.alt2        0     1     0     0     1     0     1
set6.alt1        1     0     0     0     1     0     1
set6.alt2        0     1     0     1     0     0     0
set7.alt1        1     1     0     0     0     0     0
set7.alt2        0     0     0     1     0     1     0
set8.alt1        1     0     1     0     0     1     0
set8.alt2        0     1     0     0     1     0     1

[[12]]$error
[1] 1.936165

[[12]]$inf.error
[1] 0

[[12]]$probs
      Pr(alt1)  Pr(alt2)
set1 0.8282069 0.1717931
set2 0.4223997 0.5776003
set3 0.5523275 0.4476725
set4 0.7343044 0.2656956
set5 0.3530127 0.6469873
set6 0.4932305 0.5067695
set7 0.4293410 0.5706590
set8 0.6444287 0.3555713


$design
          Time1 Time2 Price1 Price2 Comfort1 Comfort2
set1.alt1     1     0      0      0        0        0
set1.alt2     0     1      0      1        1        0
set2.alt1     0     0      0      0        1        0
set2.alt2     1     0      1      0        0        0
set3.alt1     0     1      0      0        0        1
set3.alt2     1     0      0      1        0        0
set4.alt1     0     1      0      0        0        1
set4.alt2     0     0      1      0        1        0
set5.alt1     1     0      1      0        0        1
set5.alt2     0     1      0      1        0        0
set6.alt1     1     0      0      1        0        1
set6.alt2     0     0      1      0        0        0
set7.alt1     0     0      1      0        0        1
set7.alt2     1     0      0      0        1        0
set8.alt1     0     1      1      0        1        0
set8.alt2     0     0      0      0        0        1

$error
[1] 1.555778

$inf.error
[1] 0

$probs
      Pr(alt1)  Pr(alt2)
set1 0.5904930 0.4095070
set2 0.4829926 0.5170074
set3 0.5685217 0.4314783
set4 0.4580358 0.5419642
set5 0.7203659 0.2796341
set6 0.6665164 0.3334836
set7 0.2637380 0.7362620
set8 0.6049697 0.3950303

idefix documentation built on Nov. 27, 2020, 1:07 a.m.