Consider the model f6(t;a1,a2)=100+a1t+a2(1−e−0.0003t) where t≥0. The function f6 models the brightness of a lightbulb, measured as a percent of the original intensity of the lightbulb, given the number of hours the lightbulb as been on, t.
In order to fit f6 to a list of 44 measurements, (ti,yi) we need to find the first and second partial derivatives of the loglikelihood function for the residuals. Assuming the residuals (or errors) are independent and normally distributed (with mean 0 and standard deviation 1), the loglikelihood function for these errors is ℓ6(a1,a2;t,y)=44ln(1√2π)+∑44i=1(−12)(yi−100−a1ti−a2(1−e−0.0003ti))2.
We compute ∂ℓ6∂a1 by treating a2 as a constant and differentiate with respect to a1 using the derivative rules.
∂ℓ6∂a1=∂∂a1(44ln(1√2π))+44∑i=1∂∂a1((−12)(yi−100−a1ti−a2(1−e−0.0003ti))2)(sum/difference rule)=0+44∑i=1(−12)∂∂a1((yi−100−a1ti−a2(1−e−0.0003ti))2)(constant and constant multiple rules)=44∑i=1(−12)(2(yi−100−a1ti−a2(1−e−0.0003ti))(−ti))(chain rule)=44∑i=1ti(yi−100−a1ti−a2(1−e−0.0003ti))(simplify; multiply −12, 2, and −ti)
We can simplify ∂ℓ6∂a1 using the properties of sums.
∂ℓ6∂a1=44∑i=1ti(yi−100−a1ti−a2(1−e−0.0003ti))=44∑i=1ti(yi−100)−a1t2i−a2ti(1−e−0.0003ti)(distribution inside the sum)=44∑i=1ti(yi−100)+44∑i=1−a1t2i+44∑i=1−a2ti(1−e−0.0003ti)(break the sum into three sums)=44∑i=1ti(yi−100)−a144∑i=1t2i−a244∑i=1ti(1−e−0.0003ti)(pull constant multiples out of the sums)
We see ∂ℓ6∂a1 is of the form a constant, subtract a constant multiple of a1, subtract a constant multiple of a2. ∂ℓ6∂a1=(44∑i=1ti(yi−100))−a1(44∑i=1t2i)−a2(44∑i=1ti(1−e−0.0003ti))
These constants depend on our data and can be computed in R. Let A=∑44i=1ti(yi−100)≈83738.9, B=∑44i=1t2i≈328767530, and C=∑44i=1ti(1−e−0.0003ti)≈59520.5.
library(data4led)
bulb <- led_bulb(1,seed=2021)
t <- bulb$hours
y <- bulb$percent_intensity
A <- sum((y-100)*t)
A
## [1] 83738.93
B <- sum(t^2)
B
## [1] 328767530
C <- sum((1-exp(-0.0003*t))*t)
C
## [1] 59520.54
C4.6 <- -sum((y-100)*(1-exp(-0.0003*t)))
C5.6 <- sum((1-exp(-0.0003*t))^2)
We compute ∂ℓ6∂a2 by treating a1 as a constant and differentiate with respect to a2 using the derivative rules.
∂ℓ6∂a2=∂∂a2(44ln(1√2π))+44∑i=1∂∂a2((−12)(yi−100−a1ti−a2(1−e−0.0003ti))2)(sum/difference rule)=0+44∑i=1(−12)∂∂a2((yi−100−a1ti−a2(1−e−0.0003ti))2)(constant and constant multiple rules)=44∑i=1(−12)(2(yi−100−a1ti−a2(1−e−0.0003ti))(−(1−e−0.0003ti)))(chain rule)=44∑i=1(1−e−0.0003ti)(yi−100−a1ti−a2(1−e−0.0003ti))(simplify; multiply −12, 2, and −(1−e−0.0003ti))
We can simplify ∂ℓ6∂a2 using the properties of sums.
∂ℓ6∂a2=44∑i=1(1−e−0.0003ti)(yi−100−a1ti−a2(1−e−0.0003ti))=44∑i=1(1−e−0.0003ti)(yi−100)−a1ti(1−e−0.0003ti)−a2(1−e−0.0003ti)2(distribution inside the sum)=44∑i=1(1−e−0.0003ti)(yi−100)+44∑i=1−a1ti(1−e−0.0003ti)+44∑i=1−a2(1−e−0.0003ti)2(break the sum into three sums)=44∑i=1(1−e−0.0003ti)(yi−100)−a144∑i=1ti(1−e−0.0003ti)−a244∑i=1(1−e−0.0003ti)2(pull constant multiples out of the sums)
We see ∂ℓ6∂a2 is of the form a constant, subtract a constant multiple of a1, subtract a constant multiple of a2. ∂ℓ6∂a2=(44∑i=1(1−e−0.0003ti)(yi−100))−a1(44∑i=1ti(1−e−0.0003ti))−a2(44∑i=1(1−e−0.0003ti)2)
These constants depend on our data and can be computed in R. Let D=∑44i=1(1−e−0.0003ti)(yi−100)≈−15.691, C=∑44i=1ti(1−e−0.0003ti)≈59520.5, and E=∑44i=1(1−e−0.0003ti)2≈10.998. Notice that C is a constant in ∂ℓ6∂a2 and ∂ℓ6∂a1.
D <- -sum((y-100)*(1-exp(-0.0003*t)))
D
## [1] -15.6911
C <- sum((1-exp(-0.0003*t))*t)
C
## [1] 59520.54
E <- sum((1-exp(-0.0003*t))^2)
E
## [1] 10.99773
We will use the first partials of ℓ6 to calculate the second partials of ℓ6. We only need to compute ∂2ℓ6∂a21, ∂2ℓ6∂a22 and ∂2ℓ6∂a1a2 since the mix partials are equal for ℓ6.
We compute ∂2ℓ6∂a21 by taking the derivative of ∂ℓ6∂a1 with respect to a1. ∂2ℓ6∂a21=∂∂a1((44∑i=1ti(yi−100))−a1(44∑i=1t2i)−a2(44∑i=1ti(1−e−0.0003ti)))=0−(44∑i=1t2i)−0 We see ∂2ℓ6∂a21=−∑44i=1t2i≈−99542.
-B
## [1] -328767530
We compute ∂2ℓ6∂a22 by taking the derivative of ∂ℓ6∂a2 with respect to a2. ∂2ℓ6∂a22=∂∂a2((44∑i=1(1−e−0.0003ti)(yi−100))−a1(44∑i=1ti(1−e−0.0003ti))−a2(44∑i=1(1−e−0.0003ti)2))=0−0−44∑i=1(1−e−0.0003ti)2 We see ∂2ℓ6∂a22=−∑44i=1(1−e−0.0003ti)2≈−10.998.
-E
## [1] -10.99773
We compute ∂2ℓ6∂a1a2 by taking the derivative of ∂ℓ6∂a2 with respect to a1. ∂2ℓ6∂a1a2=∂∂a1((44∑i=1(1−e−0.0003ti)(yi−100))−a1(44∑i=1ti(1−e−0.0003ti))−a2(44∑i=1(1−e−0.0003ti)2))=0−44∑i=1ti(1−e−0.0003ti)−0 We see ∂2ℓ6∂a22=−∑44i=1ti(1−e−0.0003ti)≈−59520.5.
-C
## [1] -59520.54