Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Budget constraint graph #1

Open
jvdiblasi opened this issue Nov 16, 2020 · 1 comment
Open

Budget constraint graph #1

jvdiblasi opened this issue Nov 16, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@jvdiblasi
Copy link

Hello, your initiative is excellent.

It would be possible to add that a basic graph could be added that joins the budget constraint with the indifference curve.

Thanks.

@R-CoderDotCom R-CoderDotCom added the enhancement New feature or request label Nov 16, 2020
@R-CoderDotCom
Copy link
Owner

R-CoderDotCom commented Nov 16, 2020

I also thought about this. Right now the function I developed (not published yet) allows creating budget constraint as in the image below, but not the corresponding indifference curves. The problem is that I can't add the indifference curve from a line in an automatic manner, but add a tanget to a indifference curve, so I'm not sure if this functionality should be added within the indifference function.

budget(rect1, rect2, x = c(3, 5), labels = c("A", "B"))

imagen

What I've tried so far is the following:

# Data
curve2 <- data.frame(Hmisc::bezier(c(1, 3, 9),
                                   c(9, 3, 1)))
x <- curve2$x
y <- curve2$y
plot(x, y)
spl <- smooth.spline(y ~ x)
lines(spl, col = 2)

newx <- 4
pred0 <- predict(spl, x = newx, deriv = 0)
pred1 <- predict(spl, x = newx, deriv = 1)

yint <- pred0$y - (pred1$y * newx)
xint <- -yint / pred1$y

ggplot(curve2, aes(x = x, y = y)) +
  geom_line(data = data.frame(x = x, y = yint + pred1$y * x), color = "red", lwd = 2) +
  geom_line(lwd = 2) + 
  geom_point(data = data.frame(x = pred0$x, y = pred0$y), size = 3, color = "green")

imagen

The previous code can be used to add the tangent of a curve. What do you think? If you have any other suggestions or ideas please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants