1

I know the state of some object at a given time. Let's assume that the state is temperature. At each time, I also know the mean and variance of that temperature. I would like to obtain a probability estimate of when the temperature of that object crosses a particular threshold $T_t$.

Here are some simple examples to work with:

Linear: $T(t) = kt \pm ct$ where $k$ is the slope of the line and $c$ is the uncertainty in the measurement, which grows as time moves further from zero.

Nonlinear: $T(t) = kt^2 \pm ct$ where only the main data and not the errors have a nonlinear dependence on time.

Questions: How do I find the probability that the line passed $T_t$ at each time? Or is there a better way to state this?

These two equations are not regressions, but forward models that account for unmodelled effects. That is where the uncertainties come in. If I need to provide more detail on what I mean, please let me know.

NOTE: IF THERE IS NOT ENOUGH INFORMATION HERE, PLEASE ADD A COMMENT STATING WHAT YOU WOULD LIKE CLARIFIED WHEN TEMPORATILY CLOSING THE QUESTION AND PLEASE ONLY DO SO IF YOU ARE WILLING TO RESPOND TO THE COMMENTS I MAKE IN RETURN.

js16
  • 49
  • 5
  • 1
    We certainly don't want anyone to do unnecessary work to ask their question here. At the same time, *you don't get to establish the rules.* (They are here for reasons, many of them good ones but perhaps not obvious ones.) If the community votes to close your question, then please respond to their suggestions for improvement. – whuber Apr 16 '20 at 18:51
  • @whuber My problem is not with questions being shutdown. My problem is with people like you shutting them down and then people like me responding in hopes of satisfying you. The goal here is learning and improving. If we as askers are shutdown, do our best to update but the closing gods such as yourself, which are oh so powerful, never take the time nor care to take the time to respond to our attempt, how can we learn? Think about that next time before you randomly throw out a chide response to someone just trying to learn. – js16 Apr 16 '20 at 19:03
  • 1
    We *close* questions but we don't "shut them down." One reason for that is if we didn't close them, many questions would accumulate answers that *after clarification of the question* turn out to be irrelevant or misleading, and usually that is far worse than waiting a short time for the community to reopen a question after you have improved it. Reading our [help] will help you understand how we work and use our site effectively. In particular, please read our code of conduct. Your accusations about "never take the time or care" and "chide response" are blatantly wrong and offensive. – whuber Apr 16 '20 at 19:24
  • If I were you, I would review how you have and have not followed up on my posts in particular. To be clear I have read them. You suggesting that if I read "it would help [me] understand" is just as simply blatantly wrong and offensive if I choose to take it that way. I simply ask that you hold true to the rules as well rather than chide others. If someone asks what is needed to clarify their question, take the time to answer. I have had multiple moderators not do so and it is time each of you are called out for it. – js16 Apr 16 '20 at 20:42
  • Perhaps it is time to add an associted rule for moderators to the code of concut. If you need help drafting it, let me know. Now I'll return to the kind participant below that actually is helping to steer the question in the right direction. – js16 Apr 16 '20 at 20:42
  • By all means, call us out if you think we could be doing something better! We have a place for that: https://stats.meta.stackexchange.com/. But please follow our code of conduct: SE does not tolerate any posts that are aimed at insulting or hurting *anyone,* whether intentionally or not. – whuber Apr 16 '20 at 21:54
  • Thank you for the suggestion. Perhaps at some point you could make a suggestion to make this problem more clear rather than dwelling on the rules. I think it is clear that both of us have been in the wrong hear, including your twice lobbed vailed threat to remove me. That is a direct insurlt, whether you intended it or not. Now, let's move on to helping me handle this problem. Any ideas? – js16 Apr 16 '20 at 22:03
  • @js16: It can be frustrating for new users to learn to frame their questions in the clearest way to get a response. The reason we have experienced users like whuber moderating the questions is that they have very good judgment on what posts meet the requirements for an open question. Immediately going off on a diatribe about the "closing gods" who are "oh so powerful" is not helpful; we in the SE.CV community have nominated and voted to appoint outstanding users like whuber for these positions precisely because they have shown excellent commitment and judgement on these matters. – Ben Apr 17 '20 at 01:29
  • @Ben I appreicate moderators, but you missed my point. This was not "immeditely going off." I requested that if someone close my question they respond to how I attempted to clarify. That is common courtesy and the primary way "new users ... learn to frame their questions in the clearest way to get a response." It is hypocritical that we must respond to your demands but you are not held to the same standard. I don't think I'm being unreasonable in asking that if I take the effort to reframe my question, the person who closed it should be obligated to reopen or state what is still unclear. – js16 Apr 17 '20 at 03:49
  • That may seem unreasonable to you, but moderators are busy dealing with a lot of questions, and they cannot always do those things. Users must respond to the demands of moderators because they are moderators, with specific powers; this is an asymmetric relationship. – Ben Apr 17 '20 at 07:28

1 Answers1

0

So, after thinking this my own question over, I have come up with the following solution. I first list the steps I took, the output figure, and the python code I used to generate that figure. I look forward to anyone's feedback on whether this is a legitimate method for solving the problem.

Steps:

  1. Calculate $T(t)$ for linear and nonlinear models.
  2. Calculate the probability that the model is above the threshold at every time step. This provides the cumulative mass function for whether the model has crossed the threshold.
  3. Calculate the probability mass function from the CMF.

Figure: **strong text** Code:

import numpy as np
import matplotlib.pyplot as plt
import scipy.stats

# set time domain
t0 = 0
tf = 4
ts = 0.01
tnum = int((tf-t0)/ts+1)
t = np.linspace(t0, tf, tnum, endpoint=True)

# params
k = 10
c = 4
threshold = 20

# linear function
T_linear = np.zeros(tnum)
T_linear_h = np.zeros(tnum)
T_linear_l = np.zeros(tnum)
T_linear = k*t
T_linear_h = k*t+c*t
T_linear_l = k*t-c*t

# nonlinear function
T_nlinear = np.zeros(tnum)
T_nlinear_h = np.zeros(tnum)
T_nlinear_l = np.zeros(tnum)
T_nlinear = k*t**2
T_nlinear_h = k*t**2+c*t
T_nlinear_l = k*t**2-c*t

# compute cdf
cdf_linear = np.zeros(tnum)
cdf_nlinear = np.zeros(tnum)
for i in range(tnum):
    iL_mu = T_linear[i]
    iL_sig = (T_linear_h[i]-T_linear[i])/2
    inL_mu = T_nlinear[i]
    inL_sig = (T_nlinear_h[i]-T_nlinear[i])/2
    cdf_linear[i]=1-scipy.stats.norm(iL_mu, iL_sig).cdf(threshold)
    cdf_nlinear[i]=1-scipy.stats.norm(inL_mu, inL_sig).cdf(threshold)

# compute pmf
pmf_linear = np.zeros(tnum)
pmf_linear[0] = cdf_linear[0]
pmf_nlinear = np.zeros(tnum)
pmf_nlinear[0] = cdf_nlinear[0]
for i in range(1,tnum):
    pmf_linear[i] = cdf_linear[i]-cdf_linear[i-1]
    pmf_nlinear[i] = cdf_nlinear[i]-cdf_nlinear[i-1]

# visualize functions
fig = plt.figure(figsize=[15,5])
ax1 = fig.add_subplot(1,3,1)
ax1.plot(t,T_linear, 'b', label='Linear')
ax1.plot(t,T_linear_h, 'b-.')
ax1.plot(t,T_linear_l, 'b-.')
ax1.plot(t,T_nlinear, 'r', label='nonlinear')
ax1.plot(t,T_nlinear_h, 'r-.')
ax1.plot(t,T_nlinear_l, 'r-.')
ax1.axhline(threshold, color='k', label='threshold')
ax1.set_xlim([t0,tf])
ax1.set_ylim([0, np.max(T_nlinear_h)])
ax1.set_xlabel('Time')
ax1.set_ylabel('T')
ax1.set_title('Data')
ax1.legend()

# visualize cdf
ax2 = fig.add_subplot(1,3,2)
ax2.plot(t,cdf_linear, 'b')
ax2.plot(t,cdf_nlinear, 'r')
ax2.set_xlim([t0,tf])
ax2.set_ylim([0, 1])
ax2.set_xlabel('Time')
ax2.set_ylabel('Cumulative Probability')
ax2.set_title('CMF')

# visualize pmf
ax3 = fig.add_subplot(1,3,3)
ax3.plot(t,pmf_linear, 'b')
ax3.plot(t,pmf_nlinear, 'r')
ax3.set_xlim([0,4])
ax3.set_ylim([0, 0.045])
ax3.set_xlabel('Time')
ax3.set_ylabel('Probability')
ax3.set_title('PMF')

fig.tight_layout()
js16
  • 49
  • 5