Created
August 29, 2024 08:20
-
-
Save abikoushi/b0d5b3c873485026447503e5629f1911 to your computer and use it in GitHub Desktop.
linear model with "change point"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x <- seq(-1,1, length.out=100) | |
x2 <- 1*(x>0) | |
X <- cbind(x, x2, x*x2) | |
B <- c(0.5,2,-1) | |
mu <- c(X%*%B) | |
set.seed(2024);y <- mu + rnorm(100,0,0.1) | |
fit <- lm.fit(X,y) | |
muhat <- c(X%*%c(fit$coefficients)) | |
png("cplm.png") | |
plot(x,y) | |
lines(x,mu, lty=2, col="royalblue") | |
lines(x,muhat) | |
legend("topleft", c("estimates","true"),lty=2:1,lwd=1.5, | |
col=c("royalblue","black")) | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment