rm(list=ls()) ## df <- read.table("df02.txt", header=TRUE) df with(df, plot(Y1 ~ x)) nd <- data.frame(x = seq(0, 2, length=201)) ## ## ## fit01 <- lm(Y1 ~ x, data=df) nd$pred01 <- predict(fit01, new=nd) with(nd, lines(pred01 ~ x)) ## ## ## ## (x-1.7)+ df$x1.7 <- ifelse(df$x < 1.7, 0, df$x-1.7) nd$x1.7 <- ifelse(nd$x < 1.7, 0, nd$x-1.7) fit02 <- lm(Y1 ~ x + x1.7, data=df) nd$pred02 <- predict(fit02, new=nd) with(nd, lines(pred02 ~ x, col=2)) ## parametrização alternativa df$x1.7a <- ifelse(df$x >= 1.7, 0, df$x-1.7) nd$x1.7a <- ifelse(nd$x >= 1.7, 0, nd$x-1.7) fit02a <- lm(Y1 ~ x1.7a + x1.7, data=df) nd$pred02a <- predict(fit02a, new=nd) with(nd, lines(pred02a ~ x, col=4, lty=2)) logLik(fit02) logLik(fit02a) summary(fit02) summary(fit02a) with(df, plot(Y1 ~ x)) nd$pred01 <- predict(fit01, new=nd, interval="pred") with(nd, matlines(x,pred01, col=1, lty=2)) nd$pred02 <- predict(fit02, new=nd, interval="pred") with(nd, matlines(x, pred02, col=2, lty=2)) nd$pred02a <- predict(fit02a, new=nd, interval="pred") with(nd, matlines(x,pred02a, col=4, lty=2)) ## ## Dois pontos de corte ## df$x0.5 <- ifelse(df$x < 0.5, 0, df$x-0.5) nd$x0.5 <- ifelse(nd$x < 0.5, 0, nd$x-0.5) fit03 <- lm(Y1 ~ x + x0.5 + x1.7, data=df) nd$pred03 <- predict(fit03, new=nd) with(nd, lines(pred03 ~ x, col=3)) ## ## Comparando ajustes ## logLik(fit01) logLik(fit02) logLik(fit03) anova(fit01, fit02, fit03) ## ## Definindo vários nõs ## k <- seq(0, 1.6, by=0.4) xk.f <- function(x, c) ifelse(x