Hi Mike,
Try this. The variables x and y are return-delimited. This also assumes that
no empty lines are present. You could do the checking for empty lines in
another routine. The following is my best correlation function.
function corr x,y
put average(replaceText(x,return,comma)) into meanx
put average(replaceText(y,return,comma)) into meany
repeat with i = 1 to the number of lines of x
put (line i of x - meanx) into errx
put (line i of y - meany) into erry
add errx * erry to Serrxy
add errx*errx to Serrxsq
add erry*erry to Serrysq
end repeat
return Serrxy/sqrt(Serrxsq*Serrysq)
end mouseUp
> --------------- MESSAGE metacard.v004.n163.2 ---------------
>
> From: [EMAIL PROTECTED]
> Subject: Re: statistics
> Date: Sat, 27 Jan 2001 21:30:31 EST
> MIME-Version: 1.0
> Content-Type: text/plain; charset="UTF-8"
> Content-Transfer-Encoding: 8bit
>
> I want to determine the correlation(relationship) between 2 groups ie. lines
> of data in 2 separate fields. My best attempt is as below. Can anyone help
> me improve the following script ?
> on mouseUp
> repeat with i = 1 to number of lines in fld "X"
> if line i of bg fld "X" â� empty then put line i of bg fld "X" &
> return after a
> if line i of bg fld "Y" â� empty then put line i of bg fld "Y" &
> return after b
> if line i of bg fld "X" â� empty then put (line i of bg fld "X")
> *(line i of bg fld "Y") & return after c
> if line i of bg fld "X" â� empty then put (line i of bg fld "X")^2 &
> return after x
> if line i of bg fld "Y" â� empty then put (line i of bg fld "Y")^2 &
> return after y
> end repeat
> put replacetext( a,return,comma) into a1
> delete last char of a1
> put sum(replacetext( a1,return,comma)) into Ex
> put replacetext( b,return,comma) into b1
> delete last char of b1
> put sum(replacetext( b1,return,comma)) into Ey
> put replacetext( c,return,comma) into c1
> delete last char of c1
> put sum(replacetext( c1,return,comma)) into Exy
> put replacetext( x,return,comma) into x2
> delete last char of x2
> put sum(replacetext( x2,return,comma)) into Ex2
> put replacetext( y,return,comma) into y2
> delete last char of y2
> put sum(replacetext( y2,return,comma)) into Ey2
> put (number of lines in fld "X")*Exy-(Ex*Ey) into num
> put (number of lines in fld "X")*(Ex2)-Ex^2 into denom1
> put (number of lines in fld "Y")*(Ey2)-Ey^2 into denom2
> put num/(sqrt(denom1*denom2)) into bg fld "answer"
> end mouseUp
> Thanks,
> mike
> [EMAIL PROTECTED]
>
Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.