rnorouzian
rnorouzian

Reputation: 7517

solving one equation with 2 unknowns to obtain a specific range of possible answers in R

Suppose in equation (1) below, d = .99. Also, sd = 1.2. Desirably, 5+(.1*5) <= m1 <= 5+(.5*5), and 5 <= m2 <= 5+(.3*5)

Equation (1): d = (m1-m2) / sd

Question

There surely are many possible answers for m1 and m2. But in R, how can I obtain the possible answers for m1 and m2 that fall within the range of m1 and m2 that I specified above (This is why I used "Desirably" above)?

Upvotes: 0

Views: 626

Answers (2)

John Coleman
John Coleman

Reputation: 52008

Solving your equation for m1 yields that m1 = m2 + d*sd, so:

m1 = m2 + 1.188

Your inequalities are

5.5 <= m1 <= 7.5
5.0 <= m2 <= 6.5

If we replace m1 in the first inequality by m2 + 1.188 and simplify, we get the two inequalities:

4.312 <= m2 <= 6.312
  5.0 <= m2 <= 6.5

To have them both true we need

max(4.312,5.0) <= m2 <= min(6.312,6.5)

so:

5.0 <= m2 <= 6.312

In R you could do e.g.

> m2 <- seq(5.0,6.312,length.out = 10)
> m1 <- m2 + 1.188
> cbind(m1,m2)
            m1       m2
 [1,] 6.188000 5.000000
 [2,] 6.333778 5.145778
 [3,] 6.479556 5.291556
 [4,] 6.625333 5.437333
 [5,] 6.771111 5.583111
 [6,] 6.916889 5.728889
 [7,] 7.062667 5.874667
 [8,] 7.208444 6.020444
 [9,] 7.354222 6.166222
[10,] 7.500000 6.312000 

Upvotes: 1

IRTFM
IRTFM

Reputation: 263481

I'll attempt some data visualization to see if the points in comments can be clarified:

> d = .99; sd = 1.2; png();   plot(x=seq(-10,10), -10:10 )
> abline(h= c( 5+(.1*5), 5+(.5*5) ))
> abline(v=c(5+(.1*5) , 5+(.5*5)))

enter image description here

(I do know this is not an answer .. feel free to downvote or throw tomatoes. I won't care.)

Upvotes: 2

Related Questions