Diferenças
Aqui você vê as diferenças entre duas revisões dessa página.
Ambos lados da revisão anteriorRevisão anteriorPróxima revisão | Revisão anterior | ||
cursos:ruel:sessao0 [2007/12/19 14:50] – uel | cursos:ruel:sessao0 [2008/10/28 11:39] (atual) – paulojus | ||
---|---|---|---|
Linha 1: | Linha 1: | ||
====== Sessão Inicial -- Fundamentos da Linguagem R ====== | ====== Sessão Inicial -- Fundamentos da Linguagem R ====== | ||
- | Ciando | + | Criando |
<code R> | <code R> | ||
getwd() | getwd() | ||
Linha 258: | Linha 258: | ||
+ | lm.h <- lm(time~dist, | ||
+ | ## linhas num gráfico | ||
+ | abline(h=100) | ||
+ | abline(h=c(50, | ||
+ | abline(v=10, | ||
+ | with(hills, plot(time ~ dist, ylim=c(0, 250))) | ||
+ | abline(coef(lm.h)) | ||
+ | |||
+ | with(hills, | ||
+ | x1=dist, y1=time, lty=2))) | ||
+ | title(" | ||
+ | text(2, 250, substitute(hat(beta)[1] == b1, | ||
+ | list(b1=round(coef(lm.h)[2], | ||
+ | | ||
+ | |||
+ | |||
+ | lm0.h <- lm(time ~ dist-1, data=hills) | ||
+ | lm0.h | ||
+ | |||
+ | with(hills, plot(time ~ dist, ylim=c(0, 250), xlab=" | ||
+ | abline(lm.h) | ||
+ | abline(lm0.h, | ||
+ | legend(" | ||
+ | |||
+ | ## mecanismo de ajuda | ||
+ | help(plot) | ||
+ | ## help no navegador | ||
+ | help.start(browser=" | ||
+ | help(plot) | ||
+ | ## procura no seu computador | ||
+ | help.search(" | ||
+ | # procura no site do R | ||
+ | RSiteSearch(" | ||
+ | ## procura um objeto | ||
+ | find(" | ||
+ | find(" | ||
+ | ## pedaco de palavra (nome do objeto) | ||
+ | apropos(" | ||
+ | |||
+ | ## de volta a regressão... | ||
+ | |||
+ | ## predizendo (valores preditos) usado objetos de ajuste de modelos | ||
+ | with(hills, plot(time~dist, | ||
+ | pred.df <- data.frame(dist=seq(0, | ||
+ | pred.h <- predict(lm.h, | ||
+ | pred.h | ||
+ | lines(pred.df$dist, | ||
+ | |||
+ | ## agora acrescentando intervalo de confiança... | ||
+ | predc.h <- predict(lm.h, | ||
+ | dim(predc.h) | ||
+ | head(predc.h) | ||
+ | matlines(pred.df$dist, | ||
+ | ## ... e o intervalo de predição... | ||
+ | predp.h <- predict(lm.h, | ||
+ | matlines(pred.df$dist, | ||
+ | |||
+ | legend(" | ||
+ | |||
+ | |||
+ | ## retirando o ponto mais influente | ||
+ | |||
+ | args(lm) | ||
+ | |||
+ | lmo.h <- lm(time ~dist, data=hills, subset=(dist< | ||
+ | summary(lmo.h) | ||
+ | predo.h <- predict(lmo.h, | ||
+ | |||
+ | with(hills, plot(time~dist, | ||
+ | lines(pred.df$dist, | ||
+ | lines(pred.df$dist, | ||
+ | names(hills) | ||
+ | points(hills[hills$dist> | ||
</ | </ | ||
+ | |||
+ | Mostrando os resultados dos modelos com e sem o ponto mais atípico em dois gráficos separados. | ||
+ | <code R> | ||
+ | par(mfrow=c(2, | ||
+ | with(hills, plot(time~dist, | ||
+ | lines(pred.df$dist, | ||
+ | matlines(pred.df$dist, | ||
+ | matlines(pred.df$dist, | ||
+ | |||
+ | with(hills, plot(time~dist, | ||
+ | points(hills[hills$dist> | ||
+ | lines(pred.df$dist, | ||
+ | matlines(pred.df$dist, | ||
+ | matlines(pred.df$dist, | ||
+ | |||
+ | hist(resid(lm.h)) | ||
+ | hist(resid(lmo.h)) | ||
+ | </ | ||
+ | |||
+ | Regressão múltipla, fórmulas, transformação e comparação e seleção de modelos. | ||
+ | <code R> | ||
+ | ## | ||
+ | head(hills) | ||
+ | |||
+ | lm2.h <- lm(time ~ dist + climb, data=hills) | ||
+ | anova(lm2.h) | ||
+ | summary(lm2.h) | ||
+ | par(mfrow=c(2, | ||
+ | plot(lm2.h) | ||
+ | |||
+ | shapiro.test(resid(lm2.h)) | ||
+ | |||
+ | par(mfrow=c(1, | ||
+ | boxcox(time ~dist+climb, | ||
+ | |||
+ | |||
+ | lm2r.h <- lm(sqrt(time) ~ dist + climb, data=hills) | ||
+ | coef(lm2r.h) | ||
+ | ## ou... aproveitando o modelo previamente definido... | ||
+ | lm2r.h <- update(lm2.h, | ||
+ | coef(lm2r.h) | ||
+ | |||
+ | summary(lm2r.h) | ||
+ | |||
+ | ## modelo retirando variavel climb | ||
+ | lm3r.h <- update(lm2r.h, | ||
+ | coef(lm3r.h) | ||
+ | |||
+ | anova(lm3r.h, | ||
+ | |||
+ | stepAIC(lm(time ~ dist*climb, data=hills)) | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Materiais apresentados e discutidos no curso: ===== | ||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// |