Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data("ChickWeight")
- Dieta_1 = ChickWeight[ChickWeight$Diet==1,c('Time','weight')]
- Dieta_2 = ChickWeight[ChickWeight$Diet==2,c('Time','weight')]
- Dieta_3 = ChickWeight[ChickWeight$Diet==3,c('Time','weight')]
- Dieta_4 = ChickWeight[ChickWeight$Diet==4,c('Time','weight')]
- #Esta funcion calcula el h optimo por GCV, y grafica las la regresion con sus
- #bandas de confianza.
- #Inputs:
- #vector y
- #vector x,
- #vector h: los distintos valores de h en donde evaluaremos
- #numeric deg: ??
- regressionPlot <- function(y, x, h, deg=1) {
- alphamat = matrix(0,ncol=2,nrow=length(h))
- alphamat[,2] = h
- gcvs = gcvplot(y~x, alpha=alphamat, deg=deg,maxk=1000)
- #h optimo por GCV:
- opth = max(gcvs$alpha[gcvs$values == min(gcvs$values),2])
- locfitopt = locfit(y ~ x, alpha=c(0,opth),deg=1,maxk=1000)
- # Bandas de confianza
- plot(locfitopt, newdata=NULL, tr=NULL, what="coef", band="global", get.data=FALSE, col="red")
- }
- par(mfrow=c(2,2)); #Que haga los 4 graficos en una misma ventana (grilla de 2x2)
- regressionPlot(Dieta_1$weight, Dieta_1$Time, seq(1,6,0.1));
- regressionPlot(Dieta_2$weight, Dieta_2$Time, seq(1,6,0.1));
- regressionPlot(Dieta_3$weight, Dieta_3$Time, seq(1,6,0.1));
- regressionPlot(Dieta_4$weight, Dieta_4$Time, seq(1,6,0.1));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement