##############################################################################
# Packages
library(exams)
library(manacc)
library(tidyverse)
library(knitr)
library(kableExtra)


##############################################################################
# Initialization
question_id <- "EN00000030"
wdir <- getwd()
parameters <- teachR::param_quest(wdir, question_id, alttype = "mcq", altlevel = "3 Apply")
for (i in 1:length(parameters)) assign(names(parameters)[[i]], parameters[[i]])
options(xtable.comment = FALSE, xtable.floating = FALSE, xtable.timestamp = "")
set.seed(seed)


##############################################################################
# Preparation
basepar <- manacc::income_statements(basevol = 5000, profitable = c(TRUE))
volumes <- 2500 + round(runif(5)*100)*10
highlow <- manacc::ce_highlow(vols = volumes, uvc = basepar$uvc[[1]], fc = basepar$fc[[1]], fdc <- round(basepar$fc[[1]]/10,1))

company <- basepar$company[[1]]
product <- basepar$product[[1]]
singular <- basepar$singular[[1]]
plural <- basepar$plural[[1]]

dailycosts <- highlow$base[sample(c(1:5),5,replace = FALSE),] %>%
  mutate(Day = c("Monday","Tuesday","Wednesday","Thursday","Friday")) %>%
  select(Day, volumes, total_costs)

names(dailycosts) <- c("Day", paste0("Number of ", plural), "Total cost")

daymonth <- 20

predvol <- sample(setdiff(seq(from = min(volumes), to = max(volumes), by = 50), volumes), 1) * daymonth

uvc <- highlow$solution$uvc
dayfc <- highlow$solution$fc
monthfc <- highlow$solution$fc * daymonth

predictions <- data.frame(
  right = c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE),
  volume = predvol,
  uvc = c(uvc    , uvc * daymonth, uvc  , uvc * daymonth, sample(highlow$wrong_uvc,3)),
  fc =  c(monthfc, monthfc       , dayfc, dayfc         , sample(highlow$wrong_fc,3)*20)
) %>%
  mutate(prediction = paste0(currencysymb," ",writR::dbl(volume * uvc + fc),"."))


selection <- dailycosts %>%
  subset(dailycosts[,paste0("Number of ", plural)] == min(dailycosts[,paste0("Number of ", plural)]) | dailycosts[,paste0("Number of ", plural)] == max(dailycosts[,paste0("Number of ", plural)]))

selection <- selection[order(selection[,2]),]

ql <- selection[1,2]
cl <- selection[1,3]
qh <- selection[2,2]
ch <- selection[2,3]


##############################################################################
# Answers

if (reqexpl != "" & exasolu == "exam" & type_table != "html") lines <- paste0("\\vspace{",10,"cm}") else lines <- rep(" \\ ", 2)
#lines <- rep("\\ ", 2)

questions <- c(
  right1 = predictions$prediction[[1]],
  wrong1 = predictions$prediction[[2]],
  wrong2 = predictions$prediction[[3]],
  wrong3 = predictions$prediction[[4]],
  wrong4 = predictions$prediction[[5]],
  wrong5 = predictions$prediction[[6]],
  wrong6 = predictions$prediction[[7]]
)

solutions <- predictions$right

explanations <- c(
  "",
  "You also multiplied the unit variable cost by the number of days.",
  "You forgot to multiply the daily fixed costs by the number of days.",
  "You multiplied the unit variable cost by the number of days instead of the daily fixed costs.",
  "",
  "",
  ""
)


##############################################################################
# Randomize order (do not edit)
alea <- sample(c(1, sample(2:length(questions), (alternatives-1))), alternatives)
questions <- questions[alea]
solutions <- solutions[alea]
explanations <- explanations[alea]

Question

r txt_question_id r company produces and sells r product. Last week, the daily volume of activity and corresponding total costs were the following:

dailycosts[,2] <- writR::int(dailycosts[,2])
dailycosts[,3] <- writR::dbl(dailycosts[,3])

if (type_table == "html"){
  dailycosts %>%
    knitr::kable(format = type_table, booktabs = TRUE, align = "lrr") %>%
    kable_styling(bootstrap_options = c("striped", "hover"))
} else {
  dailycosts %>%
    knitr::kable(format = type_table, booktabs = TRUE, align = "lrr") %>%
    kable_styling(latex_options = "striped")
}

\ Using the high-low method, build a daily cost equation for r company. Then, knowing that there are r writR::int(daymonth) working days in a month, build a monthly cost equation assuming a stable level of activity and no underlying technological change. What total costs would you predict for a monthly volume of r writR::int(predvol) r writR::int(plural)? r reqexpl r points

if (reqexpl == "") exams::answerlist(questions, markup = "markdown") else writeLines(lines)

Solution

First, you need to identify the highest and lowest volumes of activity and the corresponding costs:

selection[,2] <- writR::int(selection[,2])
selection[,3] <- writR::dbl(selection[,3])

if (type_table == "html"){
  selection %>%
    knitr::kable(format = type_table, booktabs = TRUE, align = "lrr") %>%
    kable_styling(bootstrap_options = c("striped", "hover"))
} else {
  selection %>%
    knitr::kable(format = type_table, booktabs = TRUE, align = "lrr") %>%
    kable_styling(latex_options = "striped")
}

\ Then, you can apply the formula of the high-low method to build a daily cost equation based on daily observations:

$$ \begin{aligned} V_c & = \frac{\Delta TC}{\Delta Q} = \frac{r writR::dbl(ch) - r writR::dbl(cl)}{r writR::int(qh) - r writR::int(ql)} = \frac{r writR::dbl(highlow$solution$deltacost)}{r writR::int(highlow$solution$deltavol)} = r writR::dbl(highlow$solution$uvc) \end{aligned} $$

$$ \begin{aligned} FC & = TC_{low} - Q_{low} \times V_c = r writR::dbl(cl) - r writR::dbl(ql) \times r writR::dbl(highlow$solution$uvc) = r writR::dbl(highlow$solution$fc) \end{aligned} $$

Therefore, you obtain the following daily cost equation:

$$ TC_{day} = Q \times r writR::dbl(highlow$solution$uvc) + r writR::dbl(highlow$solution$fc) $$

To transform this daily cost equation into a monthly cost equation, you need to multiply (only) the daily fixed costs by the number of working days in the month, r writR::int(daymonth):

$$ TC_{month} = Q \times r writR::dbl(highlow$solution$uvc) + r writR::dbl(highlow$solution$fc * daymonth) $$

The volume we must predict is within the relevant range: the activity is stable, there is no technological change and the volume to be predicted lies between the low and high volumes used to build the cost equation. Therefore, by substituting the predicted monthly volume r writR::int(predvol) to Q in the monthly cost equation, you obtain the required cost prediction:

$$ \begin{aligned} TC_{month} & = r writR::int(predvol) \times r writR::dbl(highlow$solution$uvc) + r writR::dbl(highlow$solution$fc * daymonth) \ & = r writR::dbl(predvol * highlow$solution$uvc + highlow$solution$fc * daymonth) \end{aligned} $$

if (reqexpl == "") exams::answerlist(ifelse(solutions, "True", "False"), explanations, markup = "markdown") else writeLines(c("\\ ","\\ "))

Meta-information

extype: r extype exsolution: r exams::mchoice2string(solutions, single = TRUE) exname: r question_id



NicolasJBM/manacc documentation built on Jan. 16, 2020, 1:42 p.m.