Add Polynomial Regression Line to Plot in R (2 Examples) | Base R & ggplot2 | lm() & stat_smooth()

  Рет қаралды 3,598

Statistics Globe

Statistics Globe

Күн бұрын

Пікірлер: 15
@johneagle4384
@johneagle4384 2 жыл бұрын
Joachim, you must have a crystal ball or the universe is more magical than we imagine. Right now I am working on this same subject. Is is unbelieavable, your last videos on R were able to answer my questions on the spot.Thank you so very much!!
@StatisticsGlobe
@StatisticsGlobe 2 жыл бұрын
This is amazing John! It's great to hear that my tutorials are useful to you, and that I have a good timing with them! :)
@AdrianGrieve-u1f
@AdrianGrieve-u1f 9 күн бұрын
Hey Joachim, re: the line 8 and 9 data- my_mod <- lm(y ~ poly(x, 4), # Estimate polinomial regression model data = data) what is the significance of the 4 in the brackets? Thankyou
@StatisticsGlobe
@StatisticsGlobe 9 күн бұрын
Hey, the 4 in the brackets specifies the degree of the polynomial used in the regression model. In this case, it fits a 4th-degree polynomial to the relationship between x and the target variable y.
@alessandrorosati969
@alessandrorosati969 Жыл бұрын
to build a simulation in the case of polynomial regression I need the true signal, but where should I get the data from training or test data?
@cansustatisticsglobe
@cansustatisticsglobe Жыл бұрын
Hello Alessandro, In general, you should create the true signal based on the underlying relationship you want to model in the simulation. This could be a mathematical formula or a theoretical understanding of the relationship between variables. If your goal is to evaluate the performance of your polynomial regression model, you should use something other than the true signal from either the training or test data directly. Instead, you should generate a new set of data points that follow the true signal you've defined for the simulation. This way, you can avoid overfitting and obtain an unbiased estimate of your model's performance. Once you have the true signal, you can generate synthetic data by adding noise or other factors that mimic real-world data. Then, you can split this synthetic data into training and test sets, just as you would with any other dataset. Train your polynomial regression model on the training set and evaluate its performance on the test set to understand how well it generalizes to unseen data. In summary, the true signal for your simulation should come from a theoretical understanding of the underlying relationship rather than directly from your training or test data. This will allow you to create a more realistic simulation and obtain a more accurate assessment of your model's performance. Regards, Cansu
@alessandrorosati969
@alessandrorosati969 Жыл бұрын
@@cansustatisticsglobe thanks
@alessandrorosati969
@alessandrorosati969 Жыл бұрын
@@cansustatisticsglobe i can use this function for generate a sample :fs
@cansustatisticsglobe
@cansustatisticsglobe Жыл бұрын
@@alessandrorosati969 As said before, your data tru signal generation should be based on a mathematical formula or a theoretical understanding of the relationship between variables. But if you are interested in an arbitrary sample generation, then you can use the data you defined in the comment. Regards, Cansu
@xb2856
@xb2856 Жыл бұрын
I am just getting loads of vertical red lines, like a barcode or something.
@cansustatisticsglobe
@cansustatisticsglobe Жыл бұрын
Hello, Could you please share your code? Best, Cansu
@tilmannstrepp4287
@tilmannstrepp4287 Жыл бұрын
Hi Joachim, danke für dein Video, sehr hilfreich! Wie müsste man den Code anpassen, wenn man einen fixen Intercept von (0/0) hat? LG
@cansustatisticsglobe
@cansustatisticsglobe Жыл бұрын
Hello Tilmann, I'm sorry for not getting back to you sooner. Would you like to add a smooth line with an intercept at (0,0)? If so, I found this thread: stackoverflow.com/questions/65716693/forcing-an-intercept-with-geom-smooth that might help you. Regards, Cansu
@RebeccaEbersole-g9d
@RebeccaEbersole-g9d Жыл бұрын
Love the video! Can you do a video that's like this one but has a few dummy variables so that there's multiple lines plotted? Thanks!
@cansustatisticsglobe
@cansustatisticsglobe Жыл бұрын
Hello Rebecca, We are happy to hear that you liked it. You can see our tutorial: statisticsglobe.com/r-draw-multiple-lines-to-same-ggplot2-plot if you are interested in plotting multiple lines by a variable. There you'll also find the link to the respective video. If you are interested in adding another stat_smooth function. Regards, Cansu
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
Principal Component Analysis in R
6:55
Matthew Peterson
Рет қаралды 10 М.
Why Your Brain Sabotages Your Goals (and How to Fix It)
11:56
Productive Peter
Рет қаралды 33 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН