Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
R (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Modeling and plotting === [[File:Plots from lm example.svg|right|thumb|200px|Diagnostic plots from plotting "model" (q.v. "plot.lm()" function). Notice the mathematical notation allowed in labels (lower left plot).]] The R language has built-in support for [[data modeling]] and graphics. The following example shows how R can generate and plot a [[linear model]] with residuals. <syntaxhighlight lang="r"> # Create x and y values x <- 1:6 y <- x^2 # Linear regression model y = A + B * x model <- lm(y ~ x) # Display an in-depth summary of the model summary(model) # Create a 2 by 2 layout for figures par(mfrow = c(2, 2)) # Output diagnostic plots of the model plot(model) </syntaxhighlight> Output: <syntaxhighlight lang="rout"> Residuals: 1 2 3 4 5 6 7 8 9 10 3.3333 -0.6667 -2.6667 -2.6667 -0.6667 3.3333 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -9.3333 2.8441 -3.282 0.030453 * x 7.0000 0.7303 9.585 0.000662 *** --- Signif. codes: 0 β***β 0.001 β**β 0.01 β*β 0.05 β.β 0.1 β β 1 Residual standard error: 3.055 on 4 degrees of freedom Multiple R-squared: 0.9583, Adjusted R-squared: 0.9478 F-statistic: 91.88 on 1 and 4 DF, p-value: 0.000662 </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)