-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsplinex.qmd
More file actions
36 lines (34 loc) · 788 Bytes
/
splinex.qmd
File metadata and controls
36 lines (34 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
---
title: "Spline Examples"
date: last-modified
format:
html:
self-contained: true
execute:
warning: false
message: false
major: regression modeling
minor: ordinary least squares
---
```{r}
require(rms)
require(ggplot2)
options(prType='html')
n <- 100
set.seed(1)
x <- runif(100)
y <- abs(x - 0.5) + runif(100, -.2, .2)
real <- annotate('line', x=c(0, .5, 1), y=c(.5, 0, .5), col='red', alpha=0.4)
# Need mapping= since no data before aes
ggplot(mapping=aes(x, y)) + geom_point() + real
# Could also do plot(x, y)
dd <- datadist(x); options(datadist='dd')
# Fit the true model
f <- ols(y ~ abs(x - 0.5))
ggplot(Predict(f)) + real
# Try various models: linear, polynomial, restricted cubic spline, linear spline
f <- ols(y ~ x)
ggplot(Predict(f)) + real
specs(f)
latex(f)
```