{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook deals with categorical data support which is now added to Daru. With this Daru can handle categorical data." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/javascript": [ "if(window['d3'] === undefined ||\n", " window['Nyaplot'] === undefined){\n", " var path = {\"d3\":\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min\",\"downloadable\":\"http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable\"};\n", "\n", "\n", "\n", " var shim = {\"d3\":{\"exports\":\"d3\"},\"downloadable\":{\"exports\":\"downloadable\"}};\n", "\n", " require.config({paths: path, shim:shim});\n", "\n", "\n", "require(['d3'], function(d3){window['d3']=d3;console.log('finished loading d3');require(['downloadable'], function(downloadable){window['downloadable']=downloadable;console.log('finished loading downloadable');\n", "\n", "\tvar script = d3.select(\"head\")\n", "\t .append(\"script\")\n", "\t .attr(\"src\", \"http://cdn.rawgit.com/domitry/Nyaplotjs/master/release/nyaplot.js\")\n", "\t .attr(\"async\", true);\n", "\n", "\tscript[0][0].onload = script[0][0].onreadystatechange = function(){\n", "\n", "\n", "\t var event = document.createEvent(\"HTMLEvents\");\n", "\t event.initEvent(\"load_nyaplot\",false,false);\n", "\t window.dispatchEvent(event);\n", "\t console.log('Finished loading Nyaplotjs');\n", "\n", "\t};\n", "\n", "\n", "});});\n", "}\n" ], "text/plain": [ "\"if(window['d3'] === undefined ||\\n window['Nyaplot'] === undefined){\\n var path = {\\\"d3\\\":\\\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min\\\",\\\"downloadable\\\":\\\"http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable\\\"};\\n\\n\\n\\n var shim = {\\\"d3\\\":{\\\"exports\\\":\\\"d3\\\"},\\\"downloadable\\\":{\\\"exports\\\":\\\"downloadable\\\"}};\\n\\n require.config({paths: path, shim:shim});\\n\\n\\nrequire(['d3'], function(d3){window['d3']=d3;console.log('finished loading d3');require(['downloadable'], function(downloadable){window['downloadable']=downloadable;console.log('finished loading downloadable');\\n\\n\\tvar script = d3.select(\\\"head\\\")\\n\\t .append(\\\"script\\\")\\n\\t .attr(\\\"src\\\", \\\"http://cdn.rawgit.com/domitry/Nyaplotjs/master/release/nyaplot.js\\\")\\n\\t .attr(\\\"async\\\", true);\\n\\n\\tscript[0][0].onload = script[0][0].onreadystatechange = function(){\\n\\n\\n\\t var event = document.createEvent(\\\"HTMLEvents\\\");\\n\\t event.initEvent(\\\"load_nyaplot\\\",false,false);\\n\\t window.dispatchEvent(event);\\n\\t console.log('Finished loading Nyaplotjs');\\n\\n\\t};\\n\\n\\n});});\\n}\\n\"" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "true" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "require 'daru'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Initialization" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Initialize a vector whose data is categorical by specifying `type: :category`" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(5)
0a
11
2a
31
4c
" ], "text/plain": [ "#\n", " 0 a\n", " 1 1\n", " 2 a\n", " 3 1\n", " 4 c" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(3)
a2
12
c1
" ], "text/plain": [ "#\n", " a 2\n", " 1 2\n", " c 1" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.frequencies" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can initialize it with some predefined categories even though they do not exist using **`categories`** option." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(5)
0a
11
2a
31
4c
" ], "text/plain": [ "#\n", " 0 a\n", " 1 1\n", " 2 a\n", " 3 1\n", " 4 c" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new [:a, 1, :a, 1, :c], type: :category, categories: [:a, :b, :c, 1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**categories** option initalizes new categories and also specify the order in which they should occur. So now if you see the frequency table it would be ordered with the order you specified." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(4)
a2
b0
c1
12
" ], "text/plain": [ "#\n", " a 2\n", " b 0\n", " c 1\n", " 1 2" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.frequencies" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "Since categorical data can be ordered as well as unordered you can specify whether the vector is ordered or not using the `ordered: true` or `ordered: false` during initialization." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(5)
0a
11
2a
31
4c
" ], "text/plain": [ "#\n", " 0 a\n", " 1 1\n", " 2 a\n", " 3 1\n", " 4 c" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new [:a, 1, :a, 1, :c], categories: [:a, :b, :c, 1], ordered: false, type: :category" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "ename": "ArgumentError", "evalue": "Can not apply min when vector is unordered. To make the categorical data ordered, use #ordered = true", "output_type": "error", "traceback": [ "\u001b[31mArgumentError\u001b[0m: Can not apply min when vector is unordered. To make the categorical data ordered, use #ordered = true", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/daru-0.1.3.1/lib/daru/category.rb:383:in `assert_ordered'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/daru-0.1.3.1/lib/daru/category.rb:216:in `min'\u001b[0m", "\u001b[37m(pry):7:in `
'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:355:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:355:in `evaluate_ruby'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:323:in `handle_line'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:242:in `catch'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:242:in `block in eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:241:in `catch'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:241:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/backend.rb:65:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/backend.rb:12:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/kernel.rb:87:in `execute_request'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/kernel.rb:47:in `dispatch'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/kernel.rb:37:in `run'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/command.rb:70:in `run_kernel'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/command.rb:34:in `run'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/bin/iruby:5:in `'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.1/bin/iruby:23:in `load'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.1/bin/iruby:23:in `
'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `
'\u001b[0m" ] } ], "source": [ "dv.min" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you can see you can't do the comparision if vector is not ordered. Lets make it ordered." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(5)
0a
11
2a
31
4c
" ], "text/plain": [ "#\n", " 0 a\n", " 1 1\n", " 2 a\n", " 3 1\n", " 4 c" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new [:a, 1, :a, 1, :c], ordered: true, categories: [:a, :b, :c, 1], type: :category" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ ":a" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.min" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(5)
0a
2a
4c
11
31
" ], "text/plain": [ "#\n", " 0 a\n", " 2 a\n", " 4 c\n", " 1 1\n", " 3 1" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.sort!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### #categories= and #categories" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Beside during the initialization you can also set the categories after the vector has been initialized." ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[:a, :b, :c, 1]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new [:a, 1, :c, 1, :c], type: :category\n", "dv.categories = [:a, :b, :c, 1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also check all the categories associated with the vector." ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[:a, :b, :c, 1]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.categories" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### #ordered= and #ordered?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can specify if the vector has to be treated as ordered or not after initialization of vector.\n", "\n", "**Note:** By default the vector will be unordered" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "false" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new [:a, 1, :c, 1, :c], type: :category\n", "dv.ordered?" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "true" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.ordered = true\n", "dv.ordered?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### #summary" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here are a few measures to summarize categorical vector." ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(6)
size6
categories3
max_freq3
max_categorya
min_freq1
min_categoryc
" ], "text/plain": [ "#\n", " size 6\n", " categories 3\n", " max_freq 3\n", " max_category a\n", " min_freq 1\n", " min_category c" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new [:a, :a, :a, :b, :b, :c], type: :category\n", "dv.summary" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### #frequencies" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Gives the frequency of each category in the order they occur." ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(3)
first1
second2
third3
" ], "text/plain": [ "#\n", " first 1\n", " second 2\n", " third 3" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new ['third']*3 + ['second']*2 + ['first'], type: :category, categories: ['first', 'second', 'third']\n", "dv.frequencies" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### #min, #max and #sort!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Note:** These operations only apply if the vector is ordered." ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(6)
0third
1third
2third
3second
4second
5first
" ], "text/plain": [ "#\n", " 0 third\n", " 1 third\n", " 2 third\n", " 3 second\n", " 4 second\n", " 5 first" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "ename": "ArgumentError", "evalue": "Can not apply min when vector is unordered. To make the categorical data ordered, use #ordered = true", "output_type": "error", "traceback": [ "\u001b[31mArgumentError\u001b[0m: Can not apply min when vector is unordered. To make the categorical data ordered, use #ordered = true", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/daru-0.1.3.1/lib/daru/category.rb:383:in `assert_ordered'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/daru-0.1.3.1/lib/daru/category.rb:216:in `min'\u001b[0m", "\u001b[37m(pry):23:in `
'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:355:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:355:in `evaluate_ruby'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:323:in `handle_line'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:242:in `catch'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:242:in `block in eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:241:in `catch'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:241:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/backend.rb:65:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/backend.rb:12:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/kernel.rb:87:in `execute_request'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/kernel.rb:47:in `dispatch'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/kernel.rb:37:in `run'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/command.rb:70:in `run_kernel'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/command.rb:34:in `run'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/bin/iruby:5:in `'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.1/bin/iruby:23:in `load'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.1/bin/iruby:23:in `
'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `
'\u001b[0m" ] } ], "source": [ "dv.min" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "true" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.ordered = true" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "\"first\"" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.min" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "\"third\"" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.max" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(6)
5first
3second
4second
0third
1third
2third
" ], "text/plain": [ "#\n", " 5 first\n", " 3 second\n", " 4 second\n", " 0 third\n", " 1 third\n", " 2 third" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.sort!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### #add_category" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Associates new categories with the vector.\n", "\n", "**Note:** In order to insert a new categorical value you need to use `#add_category` to make sure this category is registered in the vector. For example -" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(6)
5first
3second
4second
0third
1third
2third
" ], "text/plain": [ "#\n", " 5 first\n", " 3 second\n", " 4 second\n", " 0 third\n", " 1 third\n", " 2 third" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv\n" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "ename": "ArgumentError", "evalue": "Invalid category fourth, to add a new category use #add_category", "output_type": "error", "traceback": [ "\u001b[31mArgumentError\u001b[0m: Invalid category fourth, to add a new category use #add_category", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/daru-0.1.3.1/lib/daru/category.rb:505:in `modify_category_at'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/daru-0.1.3.1/lib/daru/category.rb:144:in `[]='\u001b[0m", "\u001b[37m(pry):29:in `
'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:355:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:355:in `evaluate_ruby'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:323:in `handle_line'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:242:in `catch'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:242:in `block in eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:241:in `catch'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/pry_instance.rb:241:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/backend.rb:65:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/backend.rb:12:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/kernel.rb:87:in `execute_request'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/kernel.rb:47:in `dispatch'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/kernel.rb:37:in `run'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/command.rb:70:in `run_kernel'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/lib/iruby/command.rb:34:in `run'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/gems/iruby-0.2.9/bin/iruby:5:in `'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.1/bin/iruby:23:in `load'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.1/bin/iruby:23:in `
'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'\u001b[0m", "\u001b[37m/home/ubuntu/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `
'\u001b[0m" ] } ], "source": [ "dv[0] = 'fourth'" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(6)
5first
3second
4second
0fourth
1third
2third
" ], "text/plain": [ "#\n", " 5 first\n", " 3 second\n", " 4 second\n", " 0 fourth\n", " 1 third\n", " 2 third" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.add_category 'fourth'\n", "dv[0] = 'fourth'\n", "dv" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[\"first\", \"second\", \"third\", \"fourth\"]" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.categories" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### #rename_categories" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can rename subset of existing categories by passing a hash mapping old ones to new ones." ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(5)
01
12
2third
32
41
" ], "text/plain": [ "#\n", " 0 1\n", " 1 2\n", " 2 third\n", " 3 2\n", " 4 1" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new [1, 2, 'third', 2, 1], type: :category" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(5)
0first
1second
2third
3second
4first
" ], "text/plain": [ "#\n", " 0 first\n", " 1 second\n", " 2 third\n", " 3 second\n", " 4 first" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.rename_categories 1 => 'first', 2 => 'second'\n", "dv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Indexing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### #[], #[]=, #at, #at_set" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Indexing works similar to an ordinary vector, so you can expect these methods to do the same as with ordinary vector. Here are few examples:" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(6)
a1
b1
c2
d2
e3
f1
" ], "text/plain": [ "#\n", " a 1\n", " b 1\n", " c 2\n", " d 2\n", " e 3\n", " f 1" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new [1, 1, 2, 2, 3, 1], index: :a..:f, type: :category" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(3)
a1
b1
c2
" ], "text/plain": [ "#\n", " a 1\n", " b 1\n", " c 2" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv[0..2]" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.at -1" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(6)
a3
b3
c2
d2
e3
f1
" ], "text/plain": [ "#\n", " a 3\n", " b 3\n", " c 2\n", " d 2\n", " e 3\n", " f 1" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.set_at [0, 1], 3\n", "dv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Querying" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### #where\n", "\n", "Daru uses Arel-like syntax for querying data." ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(4)
I3
II2
III1
IV1
" ], "text/plain": [ "#\n", " I 3\n", " II 2\n", " III 1\n", " IV 1" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new ['I', 'II', 'I', 'III', 'IV', 'I', 'II'], type: :category, categories: ['I', 'II', 'III', 'IV']\n", "dv.ordered = true\n", "dv.frequencies" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(3)
0I
2I
5I
" ], "text/plain": [ "#\n", " 0 I\n", " 2 I\n", " 5 I" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.where(dv.eq('I'))" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::Vector(2)
3III
4IV
" ], "text/plain": [ "#\n", " 3 III\n", " 4 IV" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.where(dv.gt('II'))" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::DataFrame(7x3)
abc
01aI
12bII
23cI
34dIII
45eIV
56fI
67gII
" ], "text/plain": [ "#\n", " a b c\n", " 0 1 a I\n", " 1 2 b II\n", " 2 3 c I\n", " 3 4 d III\n", " 4 5 e IV\n", " 5 6 f I\n", " 6 7 g II" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = Daru::DataFrame.new({\n", " a: (1..7).to_a,\n", " b: ('a'..'g').to_a,\n", " c: ['I', 'II', 'I', 'III', 'IV', 'I', 'II']\n", " })" ] }, { "cell_type": "code", "execution_count": 41, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::DataFrame(7x3)
abc
01aI
12bII
23cI
34dIII
45eIV
56fI
67gII
" ], "text/plain": [ "#\n", " a b c\n", " 0 1 a I\n", " 1 2 b II\n", " 2 3 c I\n", " 3 4 d III\n", " 4 5 e IV\n", " 5 6 f I\n", " 6 7 g II" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.c = df.c.to_category\n", "df" ] }, { "cell_type": "code", "execution_count": 46, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::DataFrame(3x3)
abc
12bII
34dIII
67gII
" ], "text/plain": [ "#\n", " a b c\n", " 1 2 b II\n", " 3 4 d III\n", " 6 7 g II" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.where(df.c.gt('I') & df.c.lt('IV'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Contrast coding" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Categorical data supports 4 types of contrast coding schemes-\n", "1. Dummy Coding (Default)\n", "2. Simple Coding\n", "3. Helmert Coding\n", "4. Deviation Coding" ] }, { "cell_type": "code", "execution_count": 50, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::DataFrame(7x3)
Rank_IIRank_IIIRank_IV
0000
1100
2000
3010
4001
5000
6100
" ], "text/plain": [ "#\n", " Rank_II Rank_III Rank_IV\n", " 0 0 0 0\n", " 1 1 0 0\n", " 2 0 0 0\n", " 3 0 1 0\n", " 4 0 0 1\n", " 5 0 0 0\n", " 6 1 0 0" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new ['I', 'II', 'I', 'III', 'IV', 'I', 'II'], type: :category, categories: ['I', 'II', 'III', 'IV']\n", "dv.name = 'Rank'\n", "dv.contrast_code" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can set the base category using **#base_category=**" ] }, { "cell_type": "code", "execution_count": 51, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::DataFrame(7x3)
Rank_IRank_IIRank_III
0100
1010
2100
3001
4000
5100
6010
" ], "text/plain": [ "#\n", " Rank_I Rank_II Rank_III\n", " 0 1 0 0\n", " 1 0 1 0\n", " 2 1 0 0\n", " 3 0 0 1\n", " 4 0 0 0\n", " 5 1 0 0\n", " 6 0 1 0" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.base_category = 'IV'\n", "dv.contrast_code" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To use any other coding using **#coding_scheme**" ] }, { "cell_type": "code", "execution_count": 55, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "
Daru::DataFrame(7x3)
Rank_IRank_IIRank_III
0100
1010
2100
3001
4-1-1-1
5100
6010
" ], "text/plain": [ "#\n", " Rank_I Rank_II Rank_III\n", " 0 1 0 0\n", " 1 0 1 0\n", " 2 1 0 0\n", " 3 0 0 1\n", " 4 -1 -1 -1\n", " 5 1 0 0\n", " 6 0 1 0" ] }, "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv.coding_scheme = :deviation\n", "dv.contrast_code" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Ruby 2.2.1", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "2.2.3" } }, "nbformat": 4, "nbformat_minor": 0 }