Page 1 of 1

Error in testLL[["model"]] : subscript out of bounds

Posted: 12 Oct 2021, 15:58
by NullPunkt
R version 4.1.1 (2021-08-10) -- "Kick Things"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Workspace loaded from C:/Users/neuhoff.SSP/Desktop/Lokales Arbeiten/Schätzung mit R (Arbeitstitel)/RStudio/Schätzung Sendungsgroessen/.RData]

> ### Clear memory
> rm(list = ls())
> ### Load Apollo library
> library(apollo)
Apollo 0.2.5
www.ApolloChoiceModelling.com
See url for a detailed manual, examples and a help forum.
Sign up to our mailing list for updates on new releases.
> ### Initialise code
> apollo_initialise()
Apollo ignition sequence completed
> ### Set core controls
> apollo_control = list(
+ modelName ="Schaetzung_Test",
+ modelDescr ="MNL Model Schaetzung Sendungsgroessen",
+ indivID ="RECNR"
+ )
> database = read.csv("R_Input_20211012.csv",header=TRUE, sep = ';')
> ### Vector of parameters, including any that are kept fixed in estimation
> apollo_beta=c(asc_SG1 = 0,
+ asc_SG2 = 0,
+ asc_SG3 = 0,
+ asc_SG4 = 0,
+ asc_SG5 = 0,
+ asc_SG6 = 0,
+ asc_SG7 = 0,
+ b1_SG1 = 0,
+ b1_SG2 = 0,
+ b1_SG3 = 0,
+ b1_SG4 = 0,
+ b1_SG5 = 0,
+ b1_SG6 = 0,
+ b1_SG7 = 0,
+ b2_SG1 = 0,
+ b2_SG2 = 0,
+ b2_SG3 = 0,
+ b2_SG4 = 0,
+ b2_SG5 = 0,
+ b2_SG6 = 0,
+ b2_SG7 = 0,
+ b_cost = 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_SG1")
> apollo_inputs = apollo_validateInputs()
All checks on apollo_control completed.
All checks on database completed.
> 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 mnl_settings, order is irrelevant
+ V = list()
+ V[['SG1']] = asc_SG1 + b1_SG1 * 1/database$rp_anzjahr + b2_SG1 * database$rp_wert/database$rp_anzjahr + b_cost * database$min_kost_s1
+ V[['SG2']] = asc_SG2 + b1_SG2 * 1/database$rp_anzjahr + b2_SG2 * database$rp_wert/database$rp_anzjahr + b_cost * database$min_kost_s2
+ V[['SG3']] = asc_SG3 + b1_SG3 * 1/database$rp_anzjahr + b2_SG3 * database$rp_wert/database$rp_anzjahr + b_cost * database$min_kost_s3
+ V[['SG4']] = asc_SG4 + b1_SG4 * 1/database$rp_anzjahr + b2_SG4 * database$rp_wert/database$rp_anzjahr + b_cost * database$min_kost_s4
+ V[['SG5']] = asc_SG5 + b1_SG5 * 1/database$rp_anzjahr + b2_SG5 * database$rp_wert/database$rp_anzjahr + b_cost * database$min_kost_s5
+ V[['SG6']] = asc_SG6 + b1_SG6 * 1/database$rp_anzjahr + b2_SG6 * database$rp_wert/database$rp_anzjahr + b_cost * database$min_kost_s6
+ V[['SG7']] = asc_SG7 + b1_SG7 * 1/database$rp_anzjahr + b2_SG7 * database$rp_wert/database$rp_anzjahr + b_cost * database$min_kost_s7
+
+
+ ### Define settings for MNL model component
+ mnl_settings = list(
+ alternatives = c(SG1=1, SG2=2, SG3=3, SG4=4, SG5 = 5, SG6 = 6, SG7 = 7 ),
+ avail = list(SG1=database$av_SG1, SG2=database$av_SG2, SG3=database$av_SG3, SG4=database$av_SG4,SG5=database$av_SG5, SG6=database$av_SG6, SG7=database$av_SG7 ),
+ choiceVar = Sendungsgroesse,
+ V = V
+ )
+
+ ### Compute probabilities using MNL model
+ P[['model']] = apollo_mnl(mnl_settings, functionality)
+
+
+ }
> model = apollo_estimate(apollo_beta, apollo_fixed,apollo_probabilities, apollo_inputs)

Testing likelihood function...

Overview of choices for MNL model component :
SG1 SG2 SG3 SG4 SG5 SG6 SG7
Times available 1594.00 1594.00 1594.00 1594.00 1594.00 1594.00 1594.00
Times chosen 33.00 104.00 242.00 591.00 131.00 186.00 307.00
Percentage chosen overall 2.07 6.52 15.18 37.08 8.22 11.67 19.26
Percentage chosen when available 2.07 6.52 15.18 37.08 8.22 11.67 19.26



Error in testLL[["model"]] : subscript out of bounds



Hello together,

can somebody help me with this Error in the End?

Re: Error in testLL[["model"]] : subscript out of bounds

Posted: 20 Oct 2021, 17:25
by stephanehess
Hi

it looks like you removed the two compulsory lines at the end of apollo_probabilities

Code: Select all

  P = apollo_prepareProb(P, apollo_inputs, functionality)
  return(P)
Stephane

Re: Error in testLL[["model"]] : subscript out of bounds

Posted: 20 Oct 2021, 17:26
by stephanehess
Also, you should drop database$ from anywhere inside apollo_probabilities as you are using apollo_attach