Linear regression in “The Man who counted”
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Recently, I got a book by Brasilian writer Júlio César de Mello e Souza (published under pen name Malba Tahan), titled The Man who counted. Book is a collection of mathematical stories very similar to Scheherazada’s 1001 Nights, where mathematical story-telling is the center of book.
In story 5“In so many words”, Malba describes a simple algebraic problem of proportion between price for lodging offered and price of jewel sold.
This man,” old Salim said pointing to the jeweler “came from Syria to sell precious stones in Baghdad. He promised he would pay 20 dinars for his lodgings if he sold all of his jewels for 100 dinars and 35 dinars if he sold them for 200. After several days of wandering about, he ended up selling all of them for 140 dinars. How much does he owe me according to our agreement?”
Both, jeweler and lodge owner, calculate the result each using percent proportion problem, both ending with wrong results, that was each to favor each:
- Jeweler:
200 : 35 :: 140 : x x = (35 x 140) / 200 = 24.5
2. Lodge Owner:
100 : 20 :: 140 : x x = (20 x 140) / 100 = 28
With two different results, both would end up in argument, so the third needed to be calculated:
Sale Price Price of Lodgings 200 35 -100 -20 ----- ------- 100 15
So the difference between both calculations forms a proportion to calculate the new case, when Sale price for jewel is 140, the price of lodging would be 26.
100: 15:: 40: x x = (15 x 40) / 100 = 6
Mathematically speaking, problem is very interesting to be solved also using Linear Regression, since the two pair of points [200, 35] and [100, 20] form a linear prediction function and we would need to predict what would be the price of lodging, when sale price for jewel is 140.
diamond <- c(100, 200) sleep <- c(20, 35) # regression sleep_model <- lm(sleep ~ diamond) plot(x=diamond, y=sleep) abline(lm(sleep ~ diamond))
Now, we can call this a prediction, what actually Beremiz does by heart.
predict_data <- data.frame(diamond=140) fit <- predict(sleep_model, predict_data, interval = "predict") #new value for diamond=140 fit[1]
Result is 26, which is strictly algebraic and R-prediction speaking correct result.
In this case, linear regression does same as proportion calculation, but what strikes me is which calculation – not mathematically speaking – does make more sense? 26 or 24,5 or 28 ? And which method for calculating next price lodge should satisfy both jeweler and lodge owner.
Happy reading!
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.