SHARE
TWEET

Estatística UNIRIO

StevenDATAUNIRIO Sep 13th, 2019 (edited) 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Aula categórica vs quantitativa e quantitativa vs quantitativa
  2.  
  3. # local do arquivo
  4. #https://github.com/DATAUNIRIO/Base_de_dados
  5.  
  6. # CARREGAR O BANCO DE DADOS
  7. load("C:/Users/SEU_ENDERECO/Base_de_dados-master/Base_de_dados-master/CARROS.RData")
  8.  
  9. # MANIPULAR AS VARIÁVEIS
  10. CARROS$TipodeMarcha<-as.factor(CARROS$TipodeMarcha)
  11. CARROS$Tipodecombustivel<-as.factor(CARROS$Tipodecombustivel)
  12. levels(CARROS$Tipodecombustivel) <- c('Gasolina','Álcool')
  13. levels(CARROS$TipodeMarcha) <- c('Automático', 'Manual')
  14.  
  15. ###############################################################
  16. # QUALI vs QUALI
  17. ###############################################################
  18.  
  19. # GERAR A TABELA
  20. tabela<-table(CARROS$Tipodecombustivel,CARROS$TipodeMarcha)
  21. tabela
  22.  
  23. # GERAR O GRAFICO
  24. barplot(tabela,
  25.         col=c("red","blue"),
  26.         main = "Tipo de Marcha por tipo de combustível",
  27.         ylim = c(0,15),
  28.         legend.text = rownames(tabela),
  29.         beside=TRUE)
  30.  
  31. ##########################################################
  32. # VARIÁVEL QUALITATIVA Vs VARIÀVEL QUANTITATIVA
  33. ##########################################################
  34.  
  35. names(CARROS)
  36. boxplot(CARROS$Kmporlitro~CARROS$TipodeMarcha,
  37.         col=c("red","blue"),
  38.         main="Km/l por tipo de marcha")
  39.  
  40. par(mfrow=c(1,2))
  41. boxplot(CARROS$HP~CARROS$Tipodecombustivel,
  42.         col=c("red","blue"),
  43.         main="HP por tipo de combustível")
  44. boxplot(CARROS$Preco~CARROS$Tipodecombustivel,
  45.         col=c("green","yellow"),
  46.         main="Preço por tipo de combustível")
  47.  
  48. par(mfrow=c(1,1))
  49.  
  50. library(psych)
  51. describeBy(CARROS$Kmporlitro,
  52.            CARROS$Tipodecombustivel,
  53.            mat = TRUE)
  54.  
  55. describeBy(CARROS$Preco, CARROS$TipodeMarcha, mat = TRUE)
  56.  
  57. ##########################################
  58. # Subconjunto da base de dados
  59. ##########################################
  60.  
  61. CARROS_Gasolina <- subset(CARROS,
  62.                           subset=Tipodecombustivel=='Gasolina')
  63.  
  64. #####################################################
  65. # VARIÁVEL QUANTITATIVA Vs VARIÀVEL QUANTITATIVA
  66. #####################################################
  67.  
  68. par(mfrow=c(1,1))
  69. plot(CARROS$HP,CARROS$Preco,
  70.      col="blue",pch=16,
  71.      xlab = "Horse Power", ylab = "Preço do carro",
  72.      main="Diagrama de dispersão \n do preço por HP")
  73. abline(lm(CARROS$Preco~CARROS$HP),col="red")
  74.  
  75. plot(CARROS$Kmporlitro,CARROS$Preco,
  76.      col="blue",pch=16,
  77.      xlab = "Horse Power", ylab = "Preço do carro",
  78.      main="Diagrama de dispersão \n do preço por HP")
  79. abline(lm(CARROS$Preco~CARROS$Kmporlitro),col="red")
  80.  
  81.  
  82. MC<-cor(CARROS[,c("HP","Preco","Kmporlitro","Peso","RPM")])
  83. MC
  84. library(corrplot)
  85. corrplot(MC)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top