Guest User

Untitled

a guest
Mar 25th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.22 KB | None | 0 0
  1.  
  2. library(modeest)
  3. library(mice)
  4. getwd()
  5. setwd("/home/vantu/Thesis")
  6.  
  7.  
  8. data <- read.csv("insurance.csv")
  9. original <- data
  10. head(data)
  11.  
  12. # num of row and column
  13.  
  14. print(c("num of row ",nrow(data)))
  15.  
  16. print(c("num of row ",ncol(data)))
  17.  
  18. # count male and female
  19.  
  20. data$sex<- factor(data$sex,labels = c("female","male"))
  21. table(data$sex)
  22.  
  23. # mode of the target attribute
  24.  
  25. ux<-  unique(data$sex)
  26. ux<-ux[which.max(tabulate(match(data$sex,ux)))]
  27.  
  28. ux
  29.  
  30. # % of missing data
  31.  
  32. data[sample(1:nrow(data), 1000), "sex"] <- NA   # insert na
  33. sapply(data, function(x) sum(is.na(x)))        
  34. na_index=which(is.na(data$sex),arr.ind = TRUE)  # pop_out na index
  35. miss_data<- (length(na_index)/nrow(data))*100;  # count % of missing value
  36. print(miss_data)
  37.  
  38.  
  39. # normal distribution ...of age
  40.  
  41. # dnorm
  42.  
  43. x<-original$age
  44.  
  45. y<- dnorm(x,mean = mean(x),sd = sd(x))
  46. plot(x,y,main = "Normal distribution of age",xlab = "x",ylab = "probability Density",las=1)
  47. ##abline() use to draw a vertical line through mean of x
  48. abline(v=mean(x))
  49.  
  50. ##by pnorm()
  51.  
  52. y<- pnorm(x,mean = mean(x),sd = sd(x))
  53. plot(x,y)
  54.  
  55. ##by rnorm()
  56. y<- rnorm(x,mean = mean(x),sd = sd(x))
  57.  
  58. plot(x,y)
  59.  
  60. ##qnorm()
  61. y<- qnorm(x,mean = mean(x),sd = sd(x))
  62.  
  63. plot(x,y)
Advertisement
Add Comment
Please, Sign In to add comment