Tuesday, January 6, 2009

06Jan2008

Agenda:
New Venue
RubyRX
DabbleDB.com

New week
YW Logging
More RubyRX

Future
IO JG
Respect Test Unit
Method Missing

We are getting booted out of the library for a month. Glen will seek a new venue.

Check out DabbleDB.com you can up load your own spreadsheets and create forms and make tables and figures.

RubyRx

Demographics
Tables are a bunch of columns and a bunch of rows.
Columns are often dose groups and total.
Rows are often Race, Age, Height, Weight

The way to do it in SAS is to add variables, manipulate the data, and transpose. It can be a lot of work. It might be simpler to do it with objects.

Nested Hashes

Ruby has a feature called Embedded Ruby.
ERB allows you to insert ruby syntax into HTML. The variable resolves in the HTML.
You can also put Ruby (loops etc) code into HTML.

An object creates the frequency then passes it into an HTML template.

Demogarphics Trt1 Trt2 Trt3 Trt4
Age x x x
Sex x x x
Race x x x

Hashes are similar to array, curly braces,
h=hash.new
h={}
You always need a key in a hash {'x'=>1} or {'x'=>[]}, {'a'=>{}}

Disavantage is you can't sort but you can pull out/put in data out a a hash quickly.

Sex Placebo
Male @sex['Placebo']['M']
Female

{"Sex=>{"Placebo"=>{"M"=>X,"F"=>X}},"TRT1"=>{"M"=>Y,"F"=>Y}}}

If this was on Rails these hashes would collapse to the value as the hashes resolve.

Adverse events might be a little bit more complicated, because the number of rows will be dynamic, where as in demograhics you already know.

Class DM_Table
def <<(obj) #@a<"M","trtgrp"=>"Placebo"}

create an output class

class Output
def initialize(sdtm_data)
@sdtm_data=sdtm_data
end
end

#You'd use it like this
#0=Output.new(dt)
#Create an object that contains my demographic data

#So you make a object that does the frequencies:

def freq_by_trtgrp(*args)
args.each do arg

0.freq_by_trtgroup(:sex,:trtgrp)
:sex and :trtgrp are symbols

*args allows you to pass a parameter of any size
and it will put it into an array

# we need to create a hash in a funky way
#Glenn refuses to explain why :)
# but he got a bunch of code that defines this method

h=nested_hash(3)
#h[:a][:b][:c] +=1;
#Allows you fill all three levels of the hash at once at create the default value

#You'd use it like this:
h['Frequency']['Placebo']['M']+=1

{:frequency=>{"Placebo"=>{"M"=>}}}

Now you iterate through the instance variable

#stdm data is an array
@stdm_data. each do e
h[:frequency][@trtgrp][e.instance_variable_get("@#{arg}")]+=1
end

#inject the h into the object
self.add_instance_variable(:"#arg)",h)
end
#go into the object a grab the instance variable that I am refering to in quotes

No comments: