#Plot voor price - carat
plot(training_diamanten$carat,training_diamanten$price, xlim=c(0,4.5),
+ ylim=c(0,20000), pch=1, las=1, bty='l', col='dark blue',
+ xlab = 'Hoeveelheid karaat in gewicht',
+ ylab='De prijs in US dollars',
+ main = 'Hoeveelheid karaat in gewicht vs de prijs in US dollars')
abline(model_carat, col='red', lwd=5)
Warning message:
In abline(model_carat, col = "red", lwd = 5) :
only using the first two of 263 regression coefficients
Asked
Active
Viewed 89 times
0

MrFlick
- 195,160
- 17
- 277
- 295
-
2Where is `model_carat` defined? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. It's unclear how you would plot a line with more than 2 coefficients on a 2D plot. – MrFlick Feb 09 '22 at 19:02
-
I defined my model for carat with this formule: model_carat <- lm(price ~ carat, data = training_diamanten) summary(model_carat) – Teun van Herwijnen Feb 09 '22 at 19:15
-
1It seems like `carat` is categorical, can you check its class? What is `class(training_diamanten$carat)`? – Rui Barradas Feb 09 '22 at 19:24
-
> class(training_diamanten$carat) [1] "character" Does it need to be a numeric? – Teun van Herwijnen Feb 09 '22 at 19:28
1 Answers
0
Here is what I get when splitting the diamonds
dataset 70:30:
Splitting in train and test dataset:
dt = sort(sample(nrow(diamonds), nrow(diamonds)*.7))
training_diamanten <- diamonds[dt,]
test_diamanten <- diamonds[dt,]
Your provided code:
model_carat <- lm(price ~ carat, data = training_diamanten)
summary(model_carat)
plot(training_diamanten$carat,training_diamanten$price, xlim=c(0,4.5),
ylim=c(0,20000), pch=1, las=1, bty='l', col='dark blue',
xlab = 'Hoeveelheid karaat in gewicht',
ylab='De prijs in US dollars',
main = 'Hoeveelheid karaat in gewicht vs de prijs in US dollars')
abline(model_carat, col='red', lwd=5)

TarJae
- 72,363
- 6
- 19
- 66
-
I have run the exact code you provided @TarJae but I still get the same warning Warning message: In abline(model_carat, col = "red", lwd = 5) : only using the first two of 267 regression coefficients Is it possible im just missing a package in R? – Teun van Herwijnen Feb 09 '22 at 19:56
-
Hmmh. Try: `model_carat <- lm(price ~ as.numeric(as.character(carat)), data = training_diamanten) ` – TarJae Feb 09 '22 at 20:00