Health knowledge made personal
Join this community!
› Share page:
Go
Search posts:

I recently posted that flaxseed ...

Posted Sep 12 2008 6:23pm

I recently posted that flaxseed oil affected how fast I did simple arithmetic problems (a way to measure brain function). Someone asked to see the R programs I used. Here they are.

> arithmetic.add
function (trials=100, condition = “test2″, procedure = “no mistake correction”,note=”")
{# collect new arithmetic data
#
invisible()
start.time=Sys.time()
condition=new.condition()
start.expt()
trls=sample(rep(c(”+”,”-”,”*”),times=c(34,34,34)),size=trials)#determine trial sequence
t=arithmetic[1,]
for (tr in 1:trials){
t2=c(current(),condition=condition,procedure=procedure,trial=tr,arithmetic.new.l
t=rbind(t,t2)
}
arithmetic < <-rbind(arithmetic,t[-1,])
save.ws()
arithmetic.plot()
cat("total time",round(difftime(Sys.time(),start.time, unit="mins")),"minutes\n")
}

> new.condition
function (conditions.so.far = arithmetic$condition)
{# get new condition name
#
# conditions.so.far vector of conditions so far
#
cat(”most recent condition”,last(conditions.so.far),”\nthis condition”)
condition=scan(nlines=1,what=”character”,quiet=TRUE, sep=”!”)
condition
}

> start.expt
function ()
{#wait for Enter to start data collection
#
cat(”press Enter to start “); scan(quiet=TRUE)
}

> arithmetic.new.line
function (func=”+”)
{# give addition, subtraction, or multiplication problem
#
# func function
#
b=sample(0:9,2)
if(func==”+”) answ=b[1]+b[2]
if(func==”-”) {b[1]=b[1]+b[2];answ=b[1]-b[2]}
if(func==”*”) answ=b[1]*b[2]
start.time=Sys.time()
cat(b[1],func,b[2],”= “)
a=scan(n=1, what = “integer”, quiet = TRUE)
msec=as.integer(1000*difftime(Sys.time(),start.time,unit=”sec”))
correct=a==answ
if(!correct) print(correct)
list(type=func,first.num=b[1],second.num=b[2], msec=msec, answer=as.integer(a),correct=correct)
}

function (vec, n = 1, drop = 0)
{#return last n elements of vec
#
# vec vector
# n number of elements
# drop elements at end to drop before taking n elements
#
le=length(vec)
okay.le=le-drop
vec=vec[1:okay.le]
le=length(vec)
ind=(1+le-n):le
vec[ind]
}

If you would like help using these programs, please contact me.

Post a comment
Write a comment:

Related Searches