Giter VIP home page Giter VIP logo

rphylopars_tutorial's Introduction

Loading package

library(Rphylopars)

Simulating data

We start this tutorial by simulating 2 traits by Brownian motion (BM) model without missing values. We did not simulate missing values because Rphylopars::simtraits deletes values from all traits. There is not a constraint to delete values from one trait. Then, we assigned NA values randomly to 10 values of the first simulated trait.

set.seed(2345)
sim <- Rphylopars::simtraits(ntaxa = 100,
                             ntraits = 2,
                             nreps = 1,
                             nmissing = 0,,
                             #v = matrix(c(1, 0.6, 0.6, 1), nrow = 2),
                             model = "BM",
                             nsim = 1
                             )  

trait <- sim$trait_data

trait[sample(1:100, 10), 2] <- NA

Imputation

Here, missing values were imputed by a Brownian motion model.

phylopars_res <- Rphylopars::phylopars(trait_data = trait,
                                       tree = sim$tree,
                                       model = "BM",
                                       phylo_correlated = TRUE,
                                       pheno_error = FALSE,
                                       pheno_correlated = FALSE
                                       )

Imputed values are found in the anc_recon element from the phylopars object. phylopars estimate values to all tree nodes. Below, there were filtered the imputed missing values.

anc <- phylopars_res$anc_recon[1:100, ] 

obs_imput <- data.frame(imputed = anc[, 1], 
                        original = sim$trait_data[, 2], 
                        trait2 = sim$trait_data[, 3])  

obs_imput <- obs_imput[is.na(trait[, 2]), ]

This plot shows original (black points) and imputed (red circles) values. The red lines show the distance between the original and imputed values.

plot(x = sim$trait_data[, 3], 
     y = sim$trait_data[, 2],
     pch = 19,
     ylim = c(min(sim$trait_data[, 2]), max(sim$trait_data[, 2])),
     xlab = "trait2",
     ylab = "missing value trait"
     )

points(x = trait[is.na(trait[, 2]), 3],
       y = anc[is.na(trait[, 2]), 1],
       col = "red")

lapply(1:nrow(obs_imput), 
       FUN = function(i) segments(x0 = obs_imput[i, 3], 
                                  y0 = obs_imput[i, 2], 
                                  x1 = obs_imput[i, 3], 
                                  y1 = obs_imput[i, 1], col = "red"
                                  )
       )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.