{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Simulation of data using Julia\n", "\n", "### Rohan L. Fernando\n", "\n", "### June 2015" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Julia Packages \n", "* [List of registered Julia packages](http://docs.julialang.org/en/release-0.1/packages/packagelist/#available-packages) \n", "* Will use [Distributions Package](http://distributionsjl.readthedocs.org/en) to simulate data. \n", "* It can be added to your system with the command:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "#Pkg.add(\"Distributions\")" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "* This needs to be done only once. \n", "\n", "* But, to access the functions in the Distributions package the \"using\" command has to be invoked as:\n" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "collapsed": true, "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "using Distributions" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Simulate matrix of ``genotype\" covariates" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "scrolled": true, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "10x5 Array{Int64,2}:\n", " 1 2 1 1 0\n", " 0 0 0 1 1\n", " 1 0 1 2 2\n", " 2 1 0 0 2\n", " 1 1 1 0 2\n", " 1 0 0 0 1\n", " 0 2 2 1 2\n", " 2 1 2 2 1\n", " 1 0 2 2 0\n", " 2 1 0 2 0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nRows = 10\n", "nCols = 5\n", "X = sample([0,1,2],(nRows,nCols))" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Each element in $\\mathbf{X}$ is sampled from the array [0,1,2]. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Other methods of the function ``sample\"" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "scrolled": false, "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/html": [ "7 methods for generic function sample: