knitr::opts_chunk$set(echo = TRUE)
library(mfdata)
pois<-round(rpois(1000,2), 2)
norm<-rnorm(1000,5)
gamm<-round(rgamma(1000, 3),0)

hist(runif(1000))
hist()
names(df)

median(pois)

df<- data.frame(gamm=as.integer(gamm), norm, pois)

nrow(df)


df2<-mcar(df, .5)
df3<-data.df2[1]
ggplot(df, aes(x=norm))+ geom_histogram(fill="green3")

y<-ggplot(df2, aes(x=norm))+ geom_histogram()

library(ggplot2)
library(naniar)
gg_miss_var(df2_miss, show_pct = T)

my_list<-list(df,df2,x,y)


iris_missing<- mar(iris)
LOGIC <- function(data, phi){
  FD <- data
  e2 <- rbinom(NROW(FD), 1, phi)
  FD$y4[e2 == 1] <- 0
  FD$y5[e2 == 1] <- 1
  return(FD)
}
LOGIC <- function(data, phi, var_choice){
  FD <- data
  e2 <- rbinom(NROW(FD), 1, phi)

  var_comma <- str_split(var_choice, ", ")

  for(i in 1:length(var_choice))
  {
    var_equal <- str_split(var_comma[[i]], " = ")
    var1<-which(colnames(df) == var_equal[[1]][1] )
    var2<-which(colnames(df) == var_equal[[2]][1] )

    FD[,var1][e2 == 1] <- var_equal[[1]][2]
    FD[,var2][e2 == 1] <- var_equal[[2]][2]

    type1<- class(data[ ,var1])
    type2<- class(data[ ,var2])

    if(type1 == "integer")
    {
      FD[,var1]<- as.integer(as.character(FD[ ,var1]))
    }else 
    if(type1 == "numeric")
    {
      FD[,var1]<- as.numeric(as.character(FD[ , var1]))
    }

    if(type2 == "integer")
    {
      FD[,var1]<- as.integer(as.character(FD[ ,var1]))
    }else 
    if(type2 == "numeric")
    {
      FD[,var1]<- as.numeric(as.character(FD[ , var1]))
    }

  }
  return(FD)
}
median(norm)
which(colnames(df)== "norm")

error<-("gamm = 100, norm = 100")

log_df<-LOGIC(df, .5, error )
typeof(log_df[,3])
str(log_df)
df_error <- balance(df , pi.fcar, 1:3)

df - df_error
df_miss<-mar(df, .7, .7)

for(i in 1:NCOL(df_miss))
{

  ggplot() + geom_histogram(data = df_miss, aes(x = df_miss[,i]))

}

ggp<-ggplot() + geom_density(data = df_miss, aes(x = df_miss[,3])) + geom_density(data = df, aes(x=df[,3]))
df2<- data.frame(norm, as.integer(gamm) , pois)

df2_miss<- nmar(df2, .1, .8)

vec2 <- vector("list", NCOL(df2))


#for (i in 1:ncol(df2)) {

a <- ggplot() + geom_density(data = df2_miss, aes(x = df2_miss[,i]), fill= "blue1", alpha=.3) + 
                        geom_density(data = df2, aes(x=df2[,i]), fill= "green1", alpha = .2)  

#}


vec[[2]]

gg_miss_var(df2_miss, show_pct = T)

library(visdat)

vis_dat(df2_miss)

ncol(df2)
ggplot() + geom_density()

str(iris)
iris_miss<- mar(iris, .1 , .9)

library(dplyr)
df_wide <- rbind( df2, df2_miss) %>% mutate( ds = c(rep("df", NROW(df2)), rep("df_miss", NROW(df2_miss))  ))

library(reshape2)
  long<- melt(df_wide, id.vars = "ds")


  ggplot(long, aes(x=value, fill = ds)) + geom_density(alpha=.4) + facet_wrap(~variable, ncol=2, scales = "free_x")
library(mfdata)
iris_miss<- nmar(iris2, .5, .7)

head(iris_miss[[2]] )


JerryTucay/mfdata documentation built on May 7, 2019, 6:56 p.m.