Problem 1-Transportation Safety

Scenario: You are a data analyst at a transportation safety organization. Your task is to analyze the relationship between the speed of cars and their stopping distance using the built-in R dataset cars. This analysis will help in understanding how speed affects the stopping distance, which is crucial for improving road safety regulations.

Task:

Using the cars dataset in R, perform the following steps:

Data Visualization:

Create a scatter plot of stopping distance (dist) as a function of speed (speed).

Add a regression line to the plot to visually assess the relationship.

data(cars)
plot(cars$speed, cars$dist,
     xlab = "Speed (mph)",
     ylab = "Stopping Distance (ft)",
     main = "Stopping Distance vs. Speed")
abline(lm(dist ~ speed, data=cars), col = 'darkred', lwd = 2.0)

### Build a Linear Model:

Construct a simple linear regression model where stopping distance (dist) is the dependent variable and speed (speed) is the independent variable.

Summarize the model to evaluate its coefficients, R-squared value, and p-value.

model <- lm(dist ~ speed, cars)
summary(model)
## 
## Call:
## lm(formula = dist ~ speed, data = cars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -29.069  -9.525  -2.272   9.215  43.201 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -17.5791     6.7584  -2.601   0.0123 *  
## speed         3.9324     0.4155   9.464 1.49e-12 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 15.38 on 48 degrees of freedom
## Multiple R-squared:  0.6511, Adjusted R-squared:  0.6438 
## F-statistic: 89.57 on 1 and 48 DF,  p-value: 1.49e-12

Model Quality Evaluation:

Calculate and interpret the R-squared value to assess the proportion of variance in stopping distance explained by speed.

Perform a residual analysis to check the assumptions of the linear regression model, including linearity, homoscedasticity, independence, and normality of residuals.

## The R-Squared of the model is: 0.6510794

The R-squared calculated for this model is 0.6510794. This indicates approximately 65.1% of the variability in the stopping distance is explained by the car speed.

Residual Analysis:

Plot the residuals versus fitted values to check for any patterns.

Create a Q-Q plot of the residuals to assess normality.

Perform a Shapiro-Wilk test for normality of residuals.

Plot a histogram of residuals to further check for normality.

## The results of the Shapiro-Wilk Test is:
##  W = 0.9450906 , p-value = 0.02152458

Residual Analysis and R Squared Interpretation

Conclusion:

Based on the model summary and residual analysis, determine whether the linear model is appropriate for this data.

Discuss any potential violations of model assumptions and suggest improvements if necessary.

While the r-squared of our model does indicate significant agreement between the predictor and response variables, our underlying data appears to have significant concerns. Our Residual vs. Fitted values plot has a “fan” like appearance in that the variability seems to increase as the speed increase, indicating heteroscedasticity in the data used for the model. The QQ plot indicates that the points roughly follow a straight diagonal line; however, there is substantial deviation noted at the upper end of the plot. This indicates a large number of outliers that may be influencing the model. This is further confirmed by the histogram of the residuals where we see an extended right tail.

The Shapiro-Wilk Test, which tests the null hypothesis that the residuals are normally distributed, has a result very close to 1 indicating normality. However, the p-value is <= 0.05 (p=0.02152458) meaning we reject the null hypothesis that the data comes from a normally distributed population. It should be noted that the test is sensitive to sample size and minor deviations in normality may result in a low p-value when it is not practically important.

There are some methods we could suggest to improve the model such as checking for outliers and determining whether they are incorrect or restricting the model to under certain speeds to maintain the linear relationship, and normality and homoscedasticity of the residuals. We could consider transforming the data using log transformations for the speed, or including quadratic terms to improve the model fit. We could also consider a different model type if either of the above solutions do not resolve any issues (GLM). Finally, we might just accept the model as is depending on what we are using it for and it still may provide useful information for what we need it.

Problem 2-Health Policy Analyst

As a health policy analyst for an international organization, you are tasked with analyzing data from the World Health Organization (WHO) to inform global health policies. The dataset provided (who.csv) contains crucial health indicators for various countries from the year 2008. The variables include:

Country: Name of the country.
LifeExp: Average life expectancy for the country in years.
InfantSurvival: Proportion of those surviving to one year or more.
Under5Survival: Proportion of those surviving to five years or more.
TBFree: Proportion of the population without TB.
PropMD: Proportion of the population who are MDs.
PropRN: Proportion of the population who are RNs.
PersExp: Mean personal expenditures on healthcare in US dollars at average exchange rate.
GovtExp: Mean government expenditures per capita on healthcare, US dollars at average exchange rate.
TotExp: Sum of personal and government expenditures.

Your analysis will directly influence recommendations for improving global life expectancy and the allocation of healthcare resources.

Question 1: Initial Assessment of Healthcare Expenditures and Life Expectancy

Task: Create a scatterplot of LifeExp vs. TotExp to visualize the relationship between healthcare expenditures and life expectancy across countries. Then, run a simple linear regression with LifeExp as the dependent variable and TotExp as the independent variable (without transforming the variables).

Provide and interpret the F-statistic, R-squared value, standard error, and p-values. Discuss whether the assumptions of simple linear regression (linearity, independence, homoscedasticity, and normality of residuals) are met in this analysis.

## 
## Call:
## lm(formula = LifeExp ~ TotExp, data = df_2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -24.764  -4.778   3.154   7.116  13.292 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 6.475e+01  7.535e-01  85.933  < 2e-16 ***
## TotExp      6.297e-05  7.795e-06   8.079 7.71e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.371 on 188 degrees of freedom
## Multiple R-squared:  0.2577, Adjusted R-squared:  0.2537 
## F-statistic: 65.26 on 1 and 188 DF,  p-value: 7.714e-14

Discussion

While we can see that the model is statistically significant, we do have some issues. The R-square value indicates that the model only accounts for approximately 25% of the variance in the the data, indicating that a non-transformed model may be a poor choice. However, that could have been deduced from the scatter plot that clearly indicates that there is a non-linear relationship between the variables as they are currently used. A log transformation of the TotExp variable might have a better visualization. While the p-value is extremely small for the estimates, the SEs are over 10% of the estimates indicating that the variance is way too large for this model to be accurate.

A review of the model plots we see that there is a definite problem with our underlying model. The residuals vs. fitted plot is does not indicate a random pattern of plots around zero that would indicate linearity. The curved pattern we observe suggests non-linearity. The QQ plot deviates significantly from the diagonal suggesting non-normality. The Cook’s distance plot further identifies several data points that disproportionately influence the regression model making the results highly suspect, though statistically significant.

Making health policy decisions on the results of a flawed model such as this could lead to horrible consequence. First, correlation does not indicate causality and a model indicating that the more spending equates to long lifespans does not necessarily encompass all that could potentially influence longer life spans (R-squared ~ 25%). Reliability of linear regression is based upon adherence to the assumptions of the model and violation of linearity, independence, homoscedasticity, and the normality of residuals call into question about our ability to make inferences about the results. We see violations of those assumptions with this simple model.

Question 2: Transforming Variables for a Better Fit

Task: Recognizing potential non-linear relationships, transform the variables as follows:

Raise life expectancy to the 4.6 power (LifeExp^4.6).
Raise total expenditures to the 0.06 power (TotExp^0.06), which is nearly a logarithmic transformation.

Create a new scatterplot with the transformed variables and re-run the simple linear regression model.

Provide and interpret the F-statistic, R-squared value, standard error, and p-values for the transformed model.
Compare this model to the original model (from Question 1). Which model provides a better fit, and why?

We can clearly see that the second model provides a much better linear representation than the prior model. The statistics for this model are contained below.

Discussion: How do the transformations impact the interpretation of the relationship between healthcare spending and life expectancy? Why might the transformed model be more appropriate for policy recommendations?

Discussion

Transforming the independent variable (TotExp) changes the interpretation of the regression coefficient. Instead of representing the change in life expectancy for every one-unit increase in raw TotExp, the coefficient now represents the change in life expectancy associated with a one-unit increase in the transformed TotExp (e.g., TotExp^0.06 or log(TotExp)). This reflects the potentially non-linear relationship between healthcare spending and life expectancy.

The transformed model may better capture the diminishing returns often observed with healthcare spending, where additional dollars have less impact at higher spending levels. This is crucial for policymakers when considering cost-effectiveness and resource allocation. A transformed model that more accurately reflects this reality can lead to more informed decisions about healthcare investments.

## 
## Call:
## lm(formula = life_t ~ totexp_t)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -308616089  -53978977   13697187   59139231  211951764 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -736527910   46817945  -15.73   <2e-16 ***
## totexp_t     620060216   27518940   22.53   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 90490000 on 188 degrees of freedom
## Multiple R-squared:  0.7298, Adjusted R-squared:  0.7283 
## F-statistic: 507.7 on 1 and 188 DF,  p-value: < 2.2e-16

Question 3: Forecasting Life Expectancy Based on Transformed Expenditures

Task: Using the results from the transformed model in Question 2, forecast the life expectancy for countries with the following transformed total expenditures (TotExp^0.06):

LifeExp = -736527910 + (620060216 * Transformed_TotExp)

When TotExp^0.06 = 1.5 When TotExp^0.06 = 2.5

Discussion: Discuss the implications of these forecasts for countries with different levels of healthcare spending. What do these predictions suggest about the potential impact of increasing healthcare expenditures on life expectancy?

# Transformed model equation
LifeExp <- function(input){
  intercept = -736527910
  coefficient = 620060216
  return((intercept +(coefficient*input))^(1/4.6))
}
## Forcasted life expectancy when TotExp^0.06 = 1.5 is 63.31 years.
## Forcasted life expectancy when TotExp^0.06 = 2.5 is 86.51 years.

Discussion

Higher healthcare expenditures are generally associated with longer life expectancies, but the relationship isn’t strictly linear and may have diminishing returns, meaning additional spending might yield smaller gains in life expectancy at higher spending levels. Policymakers should consider cost-effectiveness and equitable access when making decisions about healthcare spending, as simply increasing overall expenditure doesn’t guarantee improved population health.

Increased healthcare expenditures are associated with longer life expectancies, but this doesn’t imply direct causation, as other factors like economic development and access to resources also play crucial roles. Policymakers should focus not only on increasing spending but also on equitable access to care and cost-effectiveness of interventions, considering diminishing returns and varying country contexts.

Question 4: Interaction Effects in Multiple Regression

Task: Build a multiple regression model to investigate the combined effect of the proportion of MDs and total healthcare expenditures on life expectancy. Specifically, use the model:

\[ LifeExp = b_0\: +\: b_1\: *\: PropMD\: +\: b_2\:*\:TotExp\: +\: b_3\: *\: (PropMD\: *\: TotExp) \]

Interpret the F-statistic, R-squared value, standard error, and p-values.

Evaluate the interaction term (PropMD * TotExp). What does this interaction tell us about the relationship between the number of MDs, healthcare spending, and life expectancy?

Discussion: How does the presence of more MDs amplify or diminish the effect of healthcare expenditures on life expectancy? What policy recommendations can be drawn from this analysis?

## 
## Call:
## lm(formula = LifeExp ~ PropMD + log(TotExp) + (PropMD * log(TotExp)), 
##     data = df_2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -21.834  -2.465   1.338   3.630  14.684 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          35.5434     1.9575  18.158  < 2e-16 ***
## PropMD             4060.6660  1106.8063   3.669 0.000318 ***
## log(TotExp)           3.6060     0.2254  16.001  < 2e-16 ***
## PropMD:log(TotExp) -333.7306    95.9521  -3.478 0.000629 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.602 on 186 degrees of freedom
## Multiple R-squared:  0.6354, Adjusted R-squared:  0.6296 
## F-statistic: 108.1 on 3 and 186 DF,  p-value: < 2.2e-16

Discussion

Higher healthcare spending and a greater proportion of MDs are individually linked to longer life expectancies, but their combined effect isn’t simply additive. Having more MDs seems to lessen the positive impact of increased spending, possibly due to capacity constraints, shifting priorities towards specialized care, or other factors influencing care quality.

To improve global health outcomes, policymakers should adopt a balanced approach by investing in both healthcare spending and the physician workforce, while prioritizing primary and preventative care. Improving healthcare system efficiency and addressing social determinants of health, such as education and sanitation, are crucial for maximizing impact. Targeted interventions and continuous monitoring and evaluation are essential for ensuring effective policy implementation.

Question 5: Forecasting Life Expectancy with Interaction Terms

Task: Using the multiple regression model from Question 4, forecast the life expectancy for a country where:

The proportion of MDs is 0.03 (PropMD = 0.03).
The total healthcare expenditure is 14 (TotExp = 14).

Discussion: Does this forecast seem realistic? Why or why not? Consider both the potential strengths and limitations of using this model for forecasting in real-world policy settings.

##        (Intercept)             PropMD        log(TotExp) PropMD:log(TotExp) 
##           35.54335         4060.66604            3.60603         -333.73056
intercept <- model_4$coefficients[1]
PropMD_C <- model_4$coefficients[2]
TotExp_C<- model_4$coefficients[3]
Prop_Exp_C<- model_4$coefficients[4]
Reg_eq_5 <- function(PropMD, TotExp){
  return(intercept+(PropMD * PropMD_C) + (TotExp_C * TotExp) + (Prop_Exp_C * TotExp * PropMD))
}
## Forcasted life expectancy when TotExp = 14 and PropMD = 0.03 is 67.68 years.

Discussion

The results need to be carefully considered. The analysis using only total healthcare expenditure and proportion of MDs is limited, omitting crucial factors like sanitation, nutrition, and disease prevalence that impact life expectancy. A simple linear model may not capture non-linear relationships or interactions between these variables. Extrapolating predictions beyond the data’s range is risky, and the model’s accuracy relies on the quality and representativeness of the WHO data, which may vary between countries and mask within-country disparities. Finally, correlation doesn’t equal causation; other factors could be influencing both healthcare spending and life expectancy.

A simple model can be a good starting point for exploring the relationship between healthcare expenditure and life expectancy and can inform policy exploration regarding healthcare spending and physician density, but it’s crucial to acknowledge its limitations and avoid using it as the sole basis for policy decisions.

Problem 3-Retail Company Analyst

Question 1-Inventory Cost

Scenario:

A retail company is planning its inventory strategy for the upcoming year. They expect to sell 110 units of a high-demand product. The storage cost is $3.75 per unit per year, and there is a fixed ordering cost of $8.25 per order. The company wants to minimize its total inventory cost.

Task:

Using calculus, determine the optimal lot size (the number of units to order each time) and the number of orders the company should place per year to minimize total inventory costs. Assume that the total cost function is given by:

Where:

\(C(Q) = \frac{D}{Q}\text{ x }S + \frac{Q}{2}\text{ x }H\)

\(D\) is the total demand (110 units).

\(Q\) is the order quantity.

\(S\) is the fixed ordering cost per order ($8.25).

\(H\) is the holding cost per unit per year ($3.75).

Solution

First e find the derivative of the cost function with respect to quantity (Q).

\(C' = -\frac{D}{Q^2}{S}\text{ } + \frac{H}{2}\)

We set the derivative equal to 0, and then solve for Q.

\(0 = -\frac{D}{Q^2}{S}\text{ } + \frac{H}{2}\)

\(\frac{H}{2} = \frac{D}{Q^2}{S}\)

\(Q^2 = 2\frac{D}{H}{S}\)

\(Q = \sqrt{2\frac{D}{H}{S}}\)

\(N = D/Q\)

D <- 110
S <- 8.25
H <- 3.75

Q <- sqrt((2 * D * S) / H)
## Optimal Order Quantity (Q): 22 units
## Optimal Number of Orders (N): 5 orders/year

Question 2 Revenue Maximization

Scenario:

A company is running an online advertising campaign. The effectiveness of the campaign, in terms of revenue generated per day, is modeled by the function:

\(R(t) = -3150t^{-4} - 220t +6530\)

Where:

\(R(t)\) represents the revenue in dollars after \(t\) days of the campaign.

Task:

Determine the time at which the revenue is maximized by finding the critical points of the revenue function and determining which point provides the maximum value. What is the maximum revenue the company can expect from this campaign?

Solution

First we find the first order derivative of the revenue function \(R(t)\).

\(R(t)' = (-4)(-3150)t^{-5}-220\) = \(12600t^{-5}-220\)

The critical points occur when \(R(t)'=0\) or is undefined. It is undefined at \(t=0\) but that does not matter since the campaign starts at \(t>0\).

We are therefore only interested in values where \(R(t)'=0\).

\(12600t^{-5}-220=0\) \(t^{-5}=\frac{220}{12600}\) \(t^{5}=\frac{12600}{220}=57.27\) \(t=57.27^{-5}=2.25\)

Now we must determine if this is a minimum or a maximum, and that is by calculating the value of the second order derivative of the revenue function at the point 2.25.
\(R(t)'' = (-5)(12600)t^{-6}= -63000t^{-6}\) \(R(2.25)'' = -63000(2.25^{-6})=-485.56\)

The negative value of the second order derivative indicates it is concave down at the point, indicating a maximum.

We now substitute \(t=2.25\) back into the original function to find th maximum revenue for the campaign:

\(R(2.25) = -3150(2.25^{-4}) - 220(2.25) + 6530=\$5912.09\)

Question 3 Demand Area Under Curve

Scenario:

A company sells a product at a price that decreases over time according to the linear demand function:

\(P(X) = 2x-9.3\)

Where:

\(P(x)\) is the price in dollars, and \(x\) is the quantity sold.

Task:

The company is interested in calculating the total revenue generated by this product between two quantity levels, \(x{_1}=2\) and \(x{_2}=5\), where the price still generates sales. Compute the area under the demand curve between these two points, representing the total revenue generated over this range.

Solution

We must first integrate the price function and then evaluate it over the interval of \(x=[2,5]\).

\(\int\limits_2^5 P(x)dx = \int\limits_2^5 (2x-9.3)dx = \int\limits_2^5 2xdx - \int\limits_2^5 9.3dx = (x^{2}-9.3x)\Big|_{2}^{5}\)

The total revenue is now the area under the curve evaluated from \(x=[2,5]\)

\((x^{2}-9.3x)\Big|_{2}^{5} = 5^{2}-9.3(5) - (2^2-9.3(2))=25-46.5-(4-18.6)=-6.9\)

We can see that there would be negative revenue generated during this interval. A quick look at the price at \(x_1=2\) would be -5.3 dollars, indicating that we would be paying people to take the product. This is not really reasonable, but would explain the loss in revenue for this interval. Since quantity is in integer increments, revenue is generated after \(x=5\).

Question 4 Profit Optimization

Scenario:

A beauty supply store sells flat irons, and the profit function associated with selling x flat irons is given by:

\(\Pi(x) = x\)ln\((9x) -\frac{x{^6}}{6}\)

Where:

\(\Pi(x)\) is the profit in dollars.

Task:

Use calculus to find the value of \(x\) that maximizes profit. Calculate the maximum profit that can be achieved and determine if this optimal sales level is feasible given market conditions.

Solution

Like previously, we need to first find the first order derivative of the profit function and then set it equal to zero to find any critical points.

\(\Pi(x)'= \ln{9x} + x(\frac{1}{x}) - \frac{6}{6}x^{5}=\ln{9x}+1-x^{5}\)

No we set \(\Pi(x)'=0\),
\(ln({9x})+1-x^{5}=0\)

This function can not be solved algebraically, so we will use R and the uniroot function to figure it out. This also requires us to

func_4 <- function(y) log(9*y)+1-y^5
result_4 <- uniroot(func_4, interval = c(1,100))
cat('The calculated root of this equation over the interval from 1 to 100 is:',result_4$root,'\n')
## The calculated root of this equation over the interval from 1 to 100 is: 1.280637
x_4 <- result_4$root
print('Placing the value for x back into the original profit function, we now get:')
## [1] "Placing the value for x back into the original profit function, we now get:"
print(x_4*log(x_4*9)-((x_4^6)/6))
## [1] 2.395423

Question 5 Spending Behavior

Scenario:

A market research firm is analyzing the spending behavior of customers in a retail store. The spending behavior is modeled by the probability density function:

\(f(x) = \frac{1}{6x}\)

Where \(x\) represents spending in dollars.

Task:

Determine whether this function is a valid probability density function over the interval \([1,e^{6}]\). If it is, calculate the probability that a customer spends between \(\$1\) and \(\$e^6\) dollars.

Solution

First let’s check to see if f(x) is a valid function over the \([1,e^{6}]\). To determine this \(f(x)\geq{0}\) and \(\int_{1}^{e^{6}}{f(x)}=1\). \(\int_{1}^{e^{6}}{f(x)}dx=\int_{1}^{e^{6}}\frac{1}{6x}dx=\frac{1}{6}\int_{1}^{e^{6}}\frac{1}{x}dx=\frac{1}{6}lnx\Big|_{1}^{e^{6}}=\frac{1}{6}ln(e^{6})-\frac{1}{6}(ln(1))=\frac{6}{6}-0=1\).

Since we have a valid probability function over the interval \([1,e^{6}]\).

Also, since the probability density function equals 1 for the area under the curve for the interval \([1,e^{6}]\), that also means the probability that someone spends anywhere within the interval is also 100%.

Question 6 Market Share Estimation

Scenario:

An electronics company is analyzing its market share over a certain period. The rate of market penetration is given by:

\(\frac{dN}{dt} = \frac{500}{t^{4}+10}\)

Where \(N(t)\) is the cumulative market share at time \(t\).

Task:

Integrate this function to find the cumulative market share \(N(t)\) after \(t\) days, given that the initial market share \(N(1) = 6530\).

What will the market share be after 10 days?

Solution

First, let’s integrate the function: \(\frac{dN}{dt} = \frac{500}{{t^{4}+10}}\)
\(\int{dN}=N(t)=\int\frac{500}{{t^{4}+10}}dt=500\int{\frac{1}{t^{4}+10}}dt+C\)

This is not an easy integration to do by hand, so we will employ the integrate method in R to get the result. We also know that \(N(1)=6530\), so we have the constant (C) of the integration to start from day 1. We can then integrate over the interval to Day 10 and add that to the constant and get our expected market share on Day 10.

elec_func <- function(t){
  500/(t^4+10)
}
result6 <- integrate(elec_func, lower = 1, upper = 10)
C <- 6530
N_10 <- result6$value
## Our starting market share on Day 1 is: 6530
## Integrating over the interval [1,10] we get the value: 49.54001
## Our market share after 10 Days will be: 6579.54

Problem 4 Business Optimization

As a data scientist at a consultancy firm, you are tasked with optimizing various business functions to improve efficiency and profitability. Taylor Series expansions are a powerful tool to approximate complex functions, allowing for simpler calculations and more straightforward decision-making. This week, you will work on Taylor Series expansions of popular functions commonly encountered in business scenarios.

Question 1 Revenue and Cost

Scenario:

A company’s revenue from a product can be approximated by the function \(R(x)=e^x\), where \(x\) is the number of units sold. The cost of production is given by \(C(x)=ln(1+x)\). The company wants to maximize its profit, defined as \(\Pi(x)=R(x)-C(x)\).

Task:

  1. Approximate the Revenue Function: Use the Taylor Series expansion around \(x=0\) (Maclaurin series) to approximate the revenue function \(R(x)=e^x\) up to the second degree. Explain why this approximation might be useful in a business context.

The Taylor Series to the second degree for \(e^x\approx1+x+\frac{x^2}{2!}\). Therefore, our revenue function now becomes the simple quadratic equation:

\(R(x)=1+x+\frac{x^{2}}{2}\)

The approximation simplifies the ability to do calculations and simulations when differentiation and integration may be difficult or problematic. Critical points can be easier to identify for optimization. Also, we can see how revenue increases with differing levels of sales and we can add on additional degree terms should more accuracy be needed.

  1. Approximate the Cost Function: Similarly, approximate the cost function $C(x)=ln(1+x) using its Maclaurin series expansion up to the second degree. Discuss the implications of this approximation for decision-making in production.

The Taylor Series to the second degree for \(ln(1+x)\approx x-\frac{x^{2}}{2}\). Therefore our cost function now becomes the simple quadratic equation:

\(C(x) = x-\frac{x^{2}}{2}\)

As with the revenue function, the approximation simplifies our ability to do calculations and deal with difficult differentiation or integration to find optimization points. We can calculate the costs by various levels of production to set prices for units sold.

  1. Linear vs. Nonlinear Optimization: Using the Taylor Series expansions, approximate the profit function \(\Pi(x)\). Compare the optimization results when using the linear approximations versus the original nonlinear functions. What are the differences, and when might it be more appropriate to use the approximation?

Non-Linear Functions
\(\Pi(x)=e^x-ln(1+x)\)
\(\Pi'(x)=e^x -\frac{1}{1+x}\)
Linear Approximation
\(\Pi(x) = 1+x+\frac{x^2}{2}-(x-\frac{x^2}{2})=1+x+\frac{x^2}{2}-x+\frac{x^2}{2}=x^2+1\)
\(\Pi'(x)=2x\)

We can immediately see that the linear approximation would be easier to manage, while the non-linear functions would require advanced numerical techniques to solve. We would elect to use the linear approximations when precision may not be needed or when results are needed quickly. When high precision is needed or when very small changes have a significant effect. The linear approximations may not truly identify the complex interactions that may be better handled with the non-linear functions themselves. Something of note is that the non-linear function grows at much larger rate than the linear approximation and that the linear approximation may significantly under-estimate the profit.

Question 2 Financial Modeling

Scenario:

A financial analyst is modeling the risk associated with a new investment. The risk is proportional to the square root of the invested amount, modeled as \(f(x)=\sqrt{x}\), where \(x\) is the amount invested. However, to simplify calculations, the analyst wants to use a Taylor Series expansion to approximate this function for small investments.

Task:

  1. Maclaurin Series Expansion: Derive the Taylor Series expansion of \(f(x)=\sqrt{x}\) around \(x=0\) up to the second degree.

We have to modify this a bit because a Maclaurin series does not exist for \(f(x)=\sqrt{x}\) because all of the derivatives are not defined at \(x=0\). However, we can modify this to a Taylor Series for evaluation, \(f(x)=\sqrt{x+1}\) for the interval of \([0,\infty]\).
The Maclaurin Series for \(f(x)=\sqrt{x+1}\) to the second degree is:
\(\sqrt{x+1}\approx 1+\frac{x}{2}-\frac{x^2}{8}\)
No we can substitute \((x-1)\) for \(x\) and get back to \(\sqrt{x}\)
\(\sqrt{x}\approx\frac{3}{8}+\frac{3x}{4}-\frac{x^2}{8}\)

  1. Practical Application: Use the derived series to approximate the risk for small investment amounts (e.g., when \(x\) is small). Compare the approximated risk with the actual function values for small and moderate investments. Discuss when this approximation might be useful in financial modeling.

For this we will try a number of small investments \([0.5,10]\) and look at the results between the approximation and the actual risk function.

actual_risk <- function(x) sqrt(x)
approx_risk <- function(x) 3/8+(3/4)*x-(1/8)*x^2

small_investments <- c(0.5,1,1.5,2,3,4,5,6,7,8,9,10)

risk_results <- data.frame(
  Investment=small_investments,
  Actual=sapply(small_investments,actual_risk),
  Approximation=sapply(small_investments, approx_risk)
)
print(risk_results)
##    Investment    Actual Approximation
## 1         0.5 0.7071068       0.71875
## 2         1.0 1.0000000       1.00000
## 3         1.5 1.2247449       1.21875
## 4         2.0 1.4142136       1.37500
## 5         3.0 1.7320508       1.50000
## 6         4.0 2.0000000       1.37500
## 7         5.0 2.2360680       1.00000
## 8         6.0 2.4494897       0.37500
## 9         7.0 2.6457513      -0.50000
## 10        8.0 2.8284271      -1.62500
## 11        9.0 3.0000000      -3.00000
## 12       10.0 3.1622777      -4.62500

We can see from the results that the linear approximation keeps very close to actual for investments below 5, and become nonsensical after 8.

  1. Optimization Scenario: Suppose the goal is to minimize risk while maintaining a certain level of investment return. Using the Taylor Series approximation, suggest an optimal investment amount \(x\) that balances risk and return.

For this we need to create a function based upon both the risk and rate of return so that we can suggest an optimal amount for investment. The rate of return is simply \(R(x)=rx\), where \(r\) is the rate of return on investment(yield) and \(x\) is the amount invested. From prior we have \(f(x)\approx\frac{3}{8}+\frac{3x}{4}-\frac{x^2}{8}\) base upon on series approximation, which is our risk associate with our investment \(x\). We can now create the following function for optimization:

\(F(x)=rx-(\frac{3}{8}+\frac{3x}{4}-\frac{x^2}{8})\), and let’s stake the first order derivative:

\(F'(x)= r-\frac{3}{4}+\frac{x}{4}\), and set this \(=0\):

\(r-\frac{3}{4}+\frac{x}{4}=0\), and now solve for x:

\(x=3-4r\)

The amount of investment decreases as the rate of return increases, which makes sense since high risk comes with high reward and you don’t want to lose a lot of money on a risky investment. Also, you need not invest as much to get the same end value.

Question 3 inventory Management

Scenario:

In a manufacturing process, the demand for a product decreases as the price increases, modeled by \(D(p)=1-p\), where \(p\) is the price. The cost associated with producing and selling the product is modeled as \(C(p)=e^p\). The company wants to maximize its profit, which is the difference between revenue and cost.

Task:

  1. Taylor Series Expansion: Expand the cost function \(C(p)=e^p\) into a Taylor Series around \(p=0\) up to the second degree. Discuss why approximating the cost function might be useful in a pricing strategy.

The Taylor Series around \(p=0\) is fairly straight forward as \(\Sigma_{n=0}^{\infty}\frac{x^n}{n!}\) and expanded to the second degree is simply:

\(C(p)\approx1+p+\frac{p^2}{2}\)

While this is a simplified model, the cost function is only being considered around \(p=0\). So as the price increases this may not be the best method of approximation and we will need to consider the cost analyses at other pricing points for accuracy. However, the calculation of cost in comparison to demand at different prices provides a way to maximize revenue.

  1. Approximating Profit: Using the Taylor Series expansion, approximate the profit function \(\Pi(p)=pD(p)-C(p)\). Compare the results when using the original nonlinear cost function versus the approximated cost function. What differences do you observe, and when might the approximation be sufficient?

\(\Pi(p)=pD(p)-C(p)=p(1-p) - (1+p+\frac{p^2}{2})= p-p^2-1-p-\frac{p^2}{2}\)
\(\Pi(p) =(-1)(1+\frac{3p^2}{2})\)

We need to emphasize right here that based upon the profit function as written, the company selling this product will always be suffering a loss. This is true whether it is the original or the Taylor Series estimation. However, the approximation of the loss is best over the interval [0,1], as the approximation significantly underestimates the loss after that point.

Let’s use R to compare:

D <- function(p) 1-p
C <- function(p) exp(p)
C_taylor <- function(p) 1+p+p^2/2
profit <- function(p) p*D(p)-C(p)
profit_approx <- function(p) p*D(p) - C_taylor(p)
p_values <- seq(0,1,0.1)
O_profit <- sapply(p_values, profit)
A_profit <- sapply(p_values, profit_approx)
profit_results <- data.frame(p_values,O_profit,A_profit)
print(profit_results)
##    p_values  O_profit A_profit
## 1       0.0 -1.000000   -1.000
## 2       0.1 -1.015171   -1.015
## 3       0.2 -1.061403   -1.060
## 4       0.3 -1.139859   -1.135
## 5       0.4 -1.251825   -1.240
## 6       0.5 -1.398721   -1.375
## 7       0.6 -1.582119   -1.540
## 8       0.7 -1.803753   -1.735
## 9       0.8 -2.065541   -1.960
## 10      0.9 -2.369603   -2.215
## 11      1.0 -2.718282   -2.500
  1. Pricing Strategy: Based on the Taylor Series approximation, suggest a pricing strategy that could maximize profit. Explain how the Taylor Series approximation helps in making this decision.

The pricing strategy involves revisiting the demand function as written. \(D(p)=1-p\) simply identifies a fractional demand that is not reasonable when the cost of the product is based upon \(e^p\). When the product is free, the demand is 1. When the price is 1, the demand is 0. So \((p*D(p))\) will never show a profit as the cost of a single unit will exceed any profit. This is also true if the price is less than 1. However, if we decide that the maximum number of products that can be demanded at a \(p=0\) is 100, we can alter the \(D(p)=100-p\) and then look at unit increases in price from \([0,10]\)dollars and see what happens. We see that approximation is only good for a certain interval and then it is grossly inaccurate and over-estimates the revenue, or does not identify the loss.

D <- function(p) 100-p
C <- function(p) exp(p)
C_taylor <- function(p) 1+p+p^2/2
profit <- function(p) p*D(p)-C(p)
profit_approx <- function(p) p*D(p) - C_taylor(p)
p_values <- seq(0,10,1)
O_profit <- sapply(p_values, profit)
A_profit <- sapply(p_values, profit_approx)
profit_results <- data.frame(p_values,O_profit,A_profit)
print(profit_results)
##    p_values     O_profit A_profit
## 1         0     -1.00000     -1.0
## 2         1     96.28172     96.5
## 3         2    188.61094    191.0
## 4         3    270.91446    282.5
## 5         4    329.40185    371.0
## 6         5    326.58684    456.5
## 7         6    160.57121    539.0
## 8         7   -445.63316    618.5
## 9         8  -2244.95799    695.0
## 10        9  -7284.08393    768.5
## 11       10 -21126.46579    839.0

Question 4 Economic Forecasting

Scenario:

Scenario: An economist is forecasting economic growth, which can be modeled by the logarithmic function \(G(x)=ln(1+x)\), where \(x\) represents investment in infrastructure. The government wants to predict growth under different levels of investment.

Task:

  1. Maclaurin Series Expansion: Derive the Maclaurin Series expansion of \(G(x)=ln(1+x)\) up to the second degree. Explain the significance of using this approximation for small values of \(x\) in economic forecasting.
    Generating the Maclaurin Series for \(G(x)=ln(1+x)=\Sigma_{n=1}^{\infty}\frac{(-1)^{n+1}x^n}{n}\). Now we expand to the second order for our approximation and that is now \(ln(x+1)\approx x-\frac{x^2}{2}\) For small values of \(x\), this represents small investments as they relate to the overall larger economy so this approximation captures that phenomena. Also, the second degree term captures the curvature of the function and represents a possible diminishing of returns since it is negative in value.

  2. Approximation of Growth: Use the Taylor Series to approximate the growth for small investments. Compare this approximation with the actual growth function. Discuss the accuracy of the approximation for different ranges of \(x\).

Here we can use R and compare the approximation to the actual function and see that the approximation breaks down near 0.4 and that it also underestimates the actual growth rate. It also predicts a negative growth rate for \(x>2\).

G <- function(x) log(1+x)
T <- function(x) x-x^2/2
investment_values <- seq(0,2,0.1)

growth_g <- sapply(investment_values,G)
growth_t <- sapply(investment_values,T)

results_g <- data.frame(investment_values,
                      growth_g,
                      growth_t)
print(results_g)
##    investment_values   growth_g growth_t
## 1                0.0 0.00000000    0.000
## 2                0.1 0.09531018    0.095
## 3                0.2 0.18232156    0.180
## 4                0.3 0.26236426    0.255
## 5                0.4 0.33647224    0.320
## 6                0.5 0.40546511    0.375
## 7                0.6 0.47000363    0.420
## 8                0.7 0.53062825    0.455
## 9                0.8 0.58778666    0.480
## 10               0.9 0.64185389    0.495
## 11               1.0 0.69314718    0.500
## 12               1.1 0.74193734    0.495
## 13               1.2 0.78845736    0.480
## 14               1.3 0.83290912    0.455
## 15               1.4 0.87546874    0.420
## 16               1.5 0.91629073    0.375
## 17               1.6 0.95551145    0.320
## 18               1.7 0.99325177    0.255
## 19               1.8 1.02961942    0.180
## 20               1.9 1.06471074    0.095
## 21               2.0 1.09861229    0.000

Policy Recommendation: Using the approximation, recommend a level of investment that could achieve a target growth rate. Discuss the limitations of using Taylor Series approximations for such policy recommendations.

If we were solely utilizing the approximation, and not the actual growth function, we would recommend and investment value of 1.0 which would provide a target growth rate of 0.500. However, the actual growth function would indicate a growth rate of 0.69314718, which is ~38% higher. The underestimation is significant and adding in a third degree term may make the approximation more accurate. However, the conservative nature of the growth model may favor the use of the underestimation.

Problem 5 Proft, Cost, & Pricing

Question 1 Profit Maximization

Scenario:

A company produces two products, A and B. The profit function for the two products is given by:

\(\Pi(x,y)=30x-2x^2-3xy+24y-4y^2\)

Where:

\(x\) is the quantity of Product A produced and sold. \(y\) is the quantity of Product B produced and sold. \(\Pi(x,y)\) is the profit in dollars.

Task:

  1. Find all local maxima, local minima, and saddle points for the profit function \(\Pi(x,y)\).

First we need to calculate the derivative of \(\Pi(x,y)\) and set it equal to 0 or indeterminate. This can be done by implicit differentiation.

\(\frac{d(\Pi(x,y))}{dx} = \frac{30-4x-3y}{3x+8y-24}\). We now use R to solve the simultaneous equations and identify the critical points.

profit_5_1 <- function(x,y){
  30*x - 2*x^2 - 3*x*y + 24*y - 4*y^2 # Numerator is 0
}
der_x <- function(x,y){
  30 - 4*x - 3*y
}
der_y <- function(x,y){
  3*x + 8*y - 24
}
# 4x + 3y = 30
# 3x + 8y = 24

# Create the matrix
A <- matrix(c(4,3,3,8), nrow=2, byrow = TRUE)
b <- c(30,24)
critical_points <- solve(A,b)
print(critical_points)
## [1] 7.3043478 0.2608696
x_crit <- critical_points[1]
y_crit <- critical_points[2]
cat('Critical Point is at x=',x_crit,'and y=',y_crit,'\n')  
## Critical Point is at x= 7.304348 and y= 0.2608696
cat('Profit at the critical point is:$',round(profit_5_1(x_crit,y_crit),2))
## Profit at the critical point is:$ 112.7

From this point, we need to determine what kind of critical point exists. We need to calculate the second order derivatives of each of the differentials with respect to dx and dy and calculate the determinant of the Hessian matrix. So we have the following:

\(\frac{d^2\Pi}{dx^2}=-4\)
\(\frac{d^2\Pi}{dydx}=-3\)
\(\frac{d^2\Pi}{dxdy}=-3\)
\(\frac{d^2\Pi}{dy^2}=-8\)

\(Det=\frac{d^2\Pi}{dx^2}\frac{d^2\Pi}{dy^2}-\frac{d^2\Pi}{dxdy}\frac{d^2\Pi}{dydx}=((-8)(-4)-(-3)(-3)=32-9=23\)

Since the Hessian matrix \(det>0\) and \(\frac{d^2\Pi}{dx^2} <0\), then we have a local maximum.

  1. Write your answer(s) in the form \((x,y,\Pi(x,y))\). Separate multiple points with a comma.

Therefore, the result is \((7.304348, 0.2608696, \$112.7)\)

Discussion: Discuss the implications of the results for the company’s production strategy. Which production levels maximize profit, and what risks are associated with the saddle points?

Since this is a singular result of a local maximum, any consideration of a saddle point is not relevant. However, the result indicates a fractional production level for X and Y that may not seem reasonable or possible. An approximate 1/4 unit of \(y\), or more than 7 units of \(y\), may not be possible to produce.

Question 2 Pricing Strategy

Scenario:

A supermarket sells two competing brands of a product: Brand X and Brand Y. The store manager estimates that the demand for these brands depends on their prices, given by the functions:

Demand for Brand X: \(D_X(x,y)=120-15x+10y\)
Demand for Brand Y: \(D_Y(x,y)=80+5x-20y\)
Where:

\(x\) is the price of Brand X in dollars. \(y\) is the price of Brand Y in dollars. \(D_X(x,y)\) and $D_Y(x,y) are the quantities demanded for Brand X and Brand Y, respectively.

Task:

  1. Revenue Function: Find the revenue function \(R(x,y)\) for both brands combined.

Revenue function for Brand X:
\(R_x=Price\:x\:D_x(x,y)=x*(120-15x+10y)=120x-15x^2+10xy\)
Revenue function for Brand X:
\(R_y=Price\:y\:D_x(x,y)=y*(80+5x-20y)=80y+5xy-20y^2\) Total Revenue Function:
\(R(x,y)=R_x(x,y)+R_y(x,y)=(120x-15x^2+10xy)+(80y+5xy-20y^2)=120x+80y+15xy-15x^2-20y^2\)

  1. Optimal Pricing: Determine the prices \(x\) and \(y\) that maximize the store’s total revenue. Are there any saddle points to consider in the pricing strategy?

First we derive \(R'(x,y)\) which is:

\(R'(x,y) = \frac{30x-15y-120}{15x-40y-80}\)

Our critical points are where the numerator and denominator are equal to 0. We can use R and solve for the matrix of simultaneous equations of the following:

A=matrix(c(30,-15,-15,40), nrow=2, byrow = TRUE)
b=c(120,80)
crit_point_5_2 <- solve(A,b)
cat('Critical Point occurs at (x,y)=','(',crit_point_5_2[1],",", crit_point_5_2[2],')')
## Critical Point occurs at (x,y)= ( 6.153846 , 4.307692 )

\(R'_{xx}=-30\)
\(R_{yy}=-40\)
\(R'_{xy}=15\)
\(R'_{yx}=15\)

The determinant of the Hessian matrix is \(D=R'_{xx}R'_{yy}-R'_{yx}R'_{xy}=(-30)(-40)-(15)(15)=975\)

Since \(R'_{xx}=-30\) which is <0, and the determinant of the Hessian matrix >0, we have a local maximum and there are no saddle points. So the revenue is optimized when x is sold at $6.15 and y is sold at $4.31

Discussion: Explain the significance of the optimal pricing strategy and how it can be applied in a competitive retail environment.

By setting prices that maximize total revenue, a store can gain a competitive advantage and increase its profitability. Finding the right balance between the prices of competing brands, the store can attract more customers and generate higher sales volume. The lower price of Brand Y at $4.31 may attract more budget-conscious customers, while the higher price of Brand X at $6.15 may appeal to customers who perceive it as a premium option.

Question 3 Cost Minimization

Scenario:

A manufacturing company operates two plants, one in New York and one in Chicago. The company needs to produce a total of 200 units of a product each week. The total weekly cost of production is given by: \(C(x,y) = \frac{1}{8}x^2+\frac{1}{10}y^2+12x+18y+1500\)

Where:

\(x\) is the number of units produced in New York. \(y\) is the number of units produced in Chicago. \(C(x,y)\) is the total cost in dollars.

Task:

  1. Determine how many units should be produced in each plant to minimize the total weekly cost.

The cost function is constrained by the fact that only 200 units can be produced by both plants combined. So for whatever value of \(y\) is optimized, the corresponding \(x\) will be \(200-y\), or vice versa. So we can substitute \(200-x\) for \(y\) and turn our cost function into a single variable function, and then optimize for that variable. Our cost function now becomes:

\(C(x,y)=\frac{1}{8}x^2+\frac{1}{10}y^2+12x+18y+1500=\frac{1}{8}x^2+\frac{1}{10}(200-x)^2+12x+18(200-x)+1500\)
\(=\frac{x^2}{8}+\frac{(200-x)^2}{10}+12x+18(200-x)+1500=\frac{x^2}{8}+\frac{40000-400x+x^2}{10}+12x+3600-18x+1500\)
\(=\frac{x^2}{8}+\frac{40000}{10}-\frac{400x}{10}+\frac{x^2}{10}+12x+3600-18x+1500=\frac{x^2}{8}+{4000}-{40x}+\frac{x^2}{10}+12x+3600-18x+1500\)
\(=\frac{x^2}{8}+\frac{x^2}{10}-{40x}+12x-18x+1500+{4000}+3600=\frac{9x^2}{40}-46x+9100=x^2+204.4x+40444\)

Now we calculate the first order derivative and set it equal to 0 to find any critical points:
\(C'_x=(9/40)(2)x-46=\frac{9x}{20}-46\) \(\frac{9x}{20}-46=0\) \(\frac{9x}{20}=46\) \({9x}=46*20=920\) \({x}=92=102.2\approx102\) \(y=200-x=200-102=98\)

So, New York will need to produce 102 units, while Chicago will need to produce 98 units.

  1. What is the minimized total cost, and how does the distribution of production between the two plants affect overall efficiency?

We can now substitute the calculated optimal values for \(x\) and \(y\) into the original cost function and get the optimized minimal cost:

cost_function <- function(x, y) {
  (1/8) * x^2 + (1/10) * y^2 + 12 * x + 18 * y + 1500
}
minimum_cost <- cost_function(102,98)
cat('Minimum cost=$', minimum_cost)
## Minimum cost=$ 6748.9

Discussion: Discuss the benefits of this cost-minimization strategy and any practical considerations that might influence the allocation of production between the two plants.

By optimizing the allocation of production between the New York and Chicago plants, the company can minimize its total production costs, leading to improved profitability and efficient resource utilization. The company should consider factors such as capacity constraints, transportation costs, labor availability and skills, maintenance and downtime, demand fluctuations, quality control, and regulatory and environmental factors when allocating production between the two plants.

Question 4 Marketing Mix

Scenario:

A company is launching a marketing campaign that involves spending on online ads (\(x\)) and television ads (\(y\)). The effectiveness of the campaign, measured in customer reach, is modeled by the function: \(E(x,y)=500x+700y-5x^2-10xy-8y^2\)

Where:

\(x\) is the amount spent on online ads (in thousands of dollars). \(y\) is the amount spent on television ads (in thousands of dollars). \(E(x,y)\) is the estimated customer reach.

Task:

  1. Find the spending levels for online and television ads that maximize customer reach.

Let us first calculate the partial derivatives with respect to \(x\) and \(y\).
\(E'_x=500-10x-10y\) \(E'_y=700-10x-10y\)

We can now set these equations to \(0\) so that we might find the critical points. This now gives us the following where we can use matrix calculations in R to find the critical points:
\(E'_x=500-10x-10y=0\) \(E'_y=700-10x-10y=0\)

\(10x+10y=500\) \(10x+16y=700\)

A=matrix(c(10,10,10,16), nrow = 2, byrow = TRUE)
b=c(500,700)
critical_point <- solve(A,b)
cat('Critical Point (x,y) is (',round(critical_point[1],4),',',round(critical_point[2],4),')')
## Critical Point (x,y) is ( 16.6667 , 33.3333 )

Based upon our critical point identification, and there is only one, we would spend $16,678 for online ads, and $33,333 dollars on television ads, for a total of $50,011 for advertising.

  1. Identify any saddle points and discuss how they could affect the marketing strategy.

We will now need to find the determinant of the Hessian matrix of second order derivatives. This are found fairly easily:

\(E'_{xx}=-10\) \(E'_{yy}=-16\) \(E'_{xy}=E'{yx}=-10\)

We can use R to find this result easily, but we can also do it by hand just as easily:

\(Hessian\: A=\begin{pmatrix} -10&-10\\ -10&-16\\ \end{pmatrix}\)

\(det\:A=(-10)(-16)-(-10)(-10)=160-100=60\)

Since the second order derivative with respect to \(x\), \(E'_{xx}\), is \(<0\), and the determinant of the Hessian matrix is \(>0\), we have a local maximum. There are no saddle points for this optimization problem.

Discussion: Explain how the results can be used to allocate the marketing budget effectively and what the company should consider if it encounters saddle points in the optimization.

The company should allocate its marketing budget according to the optimal spending levels ($16,678 for online ads, and $33,333 dollars on television ads) to maximize customer reach. However, it is essential to consider other factors, such as budget constraints, target audience preferences, and the overall marketing mix, when making final decisions. If the company encounters saddle points in the optimization, it means that the optimal solution found might not be a stable maximum. In other words, slight deviations from these optimal spending levels could lead to a significant decrease in customer reach. The plan would would have to be closely monitored for effectivness.