Class 17
Between Class Sessions - Prep for Day 17
Please spend around 2 hours working between class sessions, focusing on the tasks below. Use any extra time to complete KnewtonAlta assignments and/or work on Project tasks.
Pick something from your prep today that you can share with your group in class. It might be something new that you learned. It might be questions you have that are still unanswered, or a question along with what helped you eventually answer it. It might be something tricky that you solved. It might be a review topic that helped you remember something. It might be a conversation you had with AI that was helpful. You will have a chance to share this with your peers during class. Come ready to articulate your thinking and questions.
Preparation
(1) Derivative Rules
- Watch Intro to Derivative Rules (~9 minutes)
- Begin Knewton Alta assignment 2 – Derivative Rules (Power Function, Sum/Difference, Constant Multiple)
(2) Loglikelihood
Loglikelihood Function
The loglikelihood function is the natural log of the likelihood function.
Useful Fact: The loglikelihood will have a maximum at the same location (i.e. for the same parameter value, or collection of parameter values for multidimensional likelihood functions) as the likelihood function.
For each of the likelihood functions below, write the corresponding loglikelihood function.
\(L_1(\lambda; \mathbf{x}) = \prod_{i=1}^n \frac{\lambda^{x_i}}{x_i!}e^{-\lambda}\) with \(x_i = 0, 1, 2, 3, ...\) for \(i = 1, 2, ... n\) where \(\lambda > 0\).
\(L_2(\lambda; \mathbf{x}) = \prod_{i=1}^n \lambda e^{-\lambda x_i}\) with \(x_i > 0\) for \(i = 1, 2, ... n\) where \(\lambda >0\).
\(L_3(\mu, \sigma; \mathbf{x}) = \prod_{i=1}^n \frac{1}{\sqrt{2\pi\sigma^2}}e^{-\frac{(x_i-\mu)^2}{2\sigma^2}},\) where \(\mu\) is a real number and \(\sigma > 0\).
Answers
\(\ell_1(\lambda; \mathbf{x}) = \ln\left(\prod_{i=1}^n \frac{\lambda^{x_i}}{x_i!}e^{-\lambda}\right)\) with \(x_i = 0, 1, 2, 3, ...\) for \(i = 1, 2, ... n\) where \(\lambda > 0\).
\(\ell_2(\lambda; \mathbf{x}) = \ln\left(\prod_{i=1}^n \lambda e^{-\lambda x_i}\right)\) with \(x_i > 0\) for \(i = 1, 2, ... n\) where \(\lambda >0\).
\(\ell_3(\mu, \sigma; \mathbf{x}) = \ln\left(\prod_{i=1}^n \frac{1}{\sqrt{2\pi\sigma^2}}e^{-\frac{(x_i-\mu)^2}{2\sigma^2}}\right),\) where \(\mu\) is a real number and \(\sigma > 0\).
Remember: Logs can turn multiplication into addition.
How could you use this property of logarithms to rewrite each loglikelihood function with a sum rather than a product?
Regular Reminders
Skill Practice (KA Homework)
Begin Knewton Alta assignment 2 – Derivative Rules (Power Function, Sum/Difference, Constant Multiple)
Applied Practice (Project Work)
- Complete Project 1
- Begin Project 2 Task 1
- Read the instructions
- Write down a formula for residuals \(r_i = y_i - \hat{y_i} = y_i - f(t_i)\) for each general function listed in Project 2 Task 1 and points \((t_i, y_i)\). Write your formula so you can clearly see how the parameters \(a_1\) and \(a_2\) contribute to the calculation of \(r_i\) in each case. For example, given the model \(f_1\) the formula for the residuals will be \(r_i = y_i - f_1(t_i; a_1) = y_i - (100 + a_1t_i) = y_i - 100 - a_1t_i\).
During Class
Brain Gains
- Residuals (or errors) revisited. Given a measurement \((x_i, y_i)\), write down a formula for the residual, \(r_i=y_i - \hat{y_i} = y_i - f(x_i)\), for each of the following models.
- \(f(x) = 30 - 2x\)
- \(f(x) = 100 - 3\sqrt{x+4}\)
- \(f(x) = -0.0002x^2 + 100\)
- The probability model for one normal random variable with mean 0 and standard deviation 1 is \(p(r) = \frac{1}{\sqrt{2\pi}}e^{-\frac{r^2}{2}}\).
- Write down the loglikelihood function for \(n\) independent normal random variables, each with mean 0 and standard deviation 1 (so they all have the same probability model \(p(r)\)). What does the word independent allow us to do?
Summary (What is a derivative?)
- Many nonlinear functions look linear when we zoom in far enough at a location \(x=a\).
- We can make a guess for what the local rate of change (or slope) of a function is at \(x=a\) by constructing a table and looking at what happens when the \(x\)-values get close to the location of interest (\(x=a\)).
- With the slope (or a guess for the slope) and the point \((a, f(a))\) we can write the equation the linearization (or local linear approximation or “tangent line”), the line that the function looks like when we zoom in.
- The derivative of \(f\) at a point (\(x=a\)) is the local rate of change of \(f\) at that location.
- The derivative of \(f\) at \(x=a\) is the slope of the line that approximates \(f\) at \(x=a\).
- The derivative of \(f\) at \(x=a\) is the slope of the local linear approximation of \(f\) at \(x=a\).
- The derivative of \(f\) at \(x=a\) is the slope of the linearization of \(f\) at \(x=a\).
- The derivative of \(f\) at \(x=a\) is the slope of the “tangent line” of \(f\) at \(x=a\).
- The derivative at a point is calculated using a limit.
- Note: The derivative of \(f\) at \(x=a\) is a number.
- The collection of local rates of changes corresponding to each location, \(x\), is the derivative of \(f\), a function.
- By definition the derivative is a limit. In our class we will learn rules to compute the derivatives, we will not calculate derivatives using the definition directly.
- Some notation people use for the derivative function, or the derivative of \(f\), include: \(f'(x)\), \(\frac{df}{dx}\), \(D_xf\), and \(\frac{d}{dx}(f(x))\). We’ll use each of these notations throughout the semester.
- Note: The derivative of \(f\) is a function.
Class Discussion - The derivative is a function applet
We’ll open this graphical representation of the derivative applet. I’ll have a few volunteers help use the applet to discover the derivative, as a function, for each of the functions from the drop down menu. We will skip the sine and cosine functions (we won’t be using trigonometry in our class).
When we’re finished, we will have seen that the derivative of \(e^x\) is \(e^x\) itself. This is the only function whose derivative is itself. This is the reason we use base \(e\) when working with exponential and logarithmic functions.
Group Meeting
Start by giving each person a moment to share what they chose to prepare for class. Help each other address any questions. When each person has had a chance to share, move on the other activities.
Activity - Computing Derivatives Practice
Below is a list of derivative rules (most of which we have seen) that you are welcome to use as you complete this activity and any homework in Knewton Alta. It’s not crucial that you memorize all these rules. Some you will memorize from just using them each time.
- Are there any exercises from your homework you would like to revisit with your group? Take turns at the chalk board solving these problems.
- After you’ve discussed any problems from the homework, continue taking turns at the chalkboard to compute the derivative of each of the following functions (remember to pass the chalk after each problem). Explain which rules you used to complete each step. Whenever we work on problems at the chalk boards we are practicing our communication and use of mathematical notation.
For \(f(x) = 3x^2-7x+5\), find \(f'(x)\). Remember to identify which rules you used at each step (on this and each problem).
For \(g(x) = 4e^x-6\ln x\), find \(g'(x)\).
For \(h(x) = 5\sqrt{x}-\frac{3}{x}\), find \(\frac{dh}{dx}\).
For \(r(t) = 7\ln t - \frac{3}{t^2}\), find \(\frac{dr}{dt}\).
For \(f(p) = \sum_{j=3}^7 4^jp\), find \(f'(p)\).
For \(p(x) = ax^2+bx+c\), find \(\frac{dp}{dx}\) assuming that \(a,b,c\) are constants.
For \(h(r) = \sum_{n=1}^{40} n\ln(r)\), find \(h'(r)\).
For \(t(x) = \sum_{m=1}^{40} m x^m\), find \(\frac{dt}{dx}\).
Using a model (practice with Project 1)
Consider the following fitted models. These models were fit to the data obtained using seed=123.
- \(f_2(x) = 100 + 0.0011x - 0.00000015x^2\) where \(x \geq 0\)
- \(f_3(x) = 101.9 - 1.9e^{-0.00114x}\) where \(x \geq 0\)
- \(f_4(x) = 100 - 0.000181x + 0.83\ln(0.005x+1)\) where \(x \geq 0\)
- \(f_5(x) = (100 + 0.00623x)e^{-0.0000506x}\) where \(x \geq 0\)
Graphs of these Functions
rm(list=ls())
library(data4led)
bulb <- led_bulb(1,seed = 123)
t <- bulb$hours
y <- bulb$percent_intensity
f0 <- function(x,a0=100,a1=0){ a0 + a1*x }
f1 <- function(x,a0=100,a1=7e-4){ a0 + a1*x }
f2 <- function(x,a0=100,a1=1.1e-3,a2=-1.5e-7){ a0 + a1*x + a2*x^2 }
f3 <- function(x,a1=-1.9,a2=0.00114){ (100-a1) + a1*exp(-a2*x) }
f4 <- function(x,a0=100,a1=-1.81e-4,a2=0.83){a0+a1*x+a2*log(0.005*x+1)}
f5 <- function(x,a0=100,a1=6.23e-3,a2=5.06e-5){ (a0 + a1*x)*exp(-a2*x) }
x <- seq(-10,80001,2)
y0 <- f2(x)
y1 <- f2(x)
y2 <- f2(x)
y3 <- f3(x)
y4 <- f4(x)
y5 <- f5(x)
par(mfrow=c(1,2),mar=c(2,2,3,0.25),oma=rep(0.5,4))
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16,main='f0')
lines(x,y0,col=2)
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16, xlim = c(-10,80000),ylim = c(-10,120))
lines(x,y0,col=2)
par(mfrow=c(1,2),mar=c(2,2,3,0.25),oma=rep(0.5,4))
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16,main='f1')
lines(x,y1,col=2)
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16, xlim = c(-10,80000),ylim = c(-10,120))
lines(x,y1,col=2)
par(mfrow=c(1,2),mar=c(2,2,3,0.25),oma=rep(0.5,4))
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16,main='f2')
lines(x,y2,col=2)
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16, xlim = c(-10,80000),ylim = c(-10,120))
lines(x,y2,col=2)
par(mfrow=c(1,2),mar=c(2,2,3,0.25),oma=rep(0.5,4))
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16,main='f3')
lines(x,y3,col=2)
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16, xlim = c(-10,80000),ylim = c(-10,120))
lines(x,y3,col=2)
par(mfrow=c(1,2),mar=c(2,2,3,0.25),oma=rep(0.5,4))
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16,main='f4')
lines(x,y4,col=2)
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16, xlim = c(-10,80000),ylim = c(-10,120))
lines(x,y4,col=2)
par(mfrow=c(1,2),mar=c(2,2,3,0.25),oma=rep(0.5,4))
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16,main='f5')
lines(x,y5,col=2)
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16, xlim = c(-10,80000),ylim = c(-10,120))
lines(x,y5,col=2)Use the model \(f_4\) to answer the question, What is the intensity of the bulb after 12000 hours?
Use the model \(f_3\) to answer the question, When is the intensity of the bulb 90% of its original intensity?
Use the model \(f_2\) to answer the question, When is the intensity of the bulb 97% of its original intensity?
Use the model \(f_5\) to answer the question, When is the intensity of the bulb 95% of its original intensity?
Use the model \(f_5\) to answer the question, What is the intensity of the bulb after 25000 hours?
Solutions
Run the code below to obtain the solutions.
f4(12000)
uniroot(function(x){f3(x)-90},c(-10000,100))$root
uniroot(function(x){f2(x)-97},c(0,10000))$root
uniroot(function(x){f5(x)-95},c(0,80000))$root
f5(25000)Source: Class.17 on byuimath.com