Sorry for not including enough information everyone.
I have quite a bit of code, so I will just enter relevant pieces...
This is how I call C from R:
The tstats are tstatistics (difference of mean, divided by sqrt of S1+S2)
from an unpermuted matrix. The c code is below...
dyn.load("testp.so")
obj<-.C("testp",ptests=as.array(permuted_ttests),as.integer(B),permuted1=as.array(permuted),matrix=as.array(Imatrix),
as.integer(ncols), as.integer(nrows),as.integer(g)*,as.array(abs(tstats)*
),pvalues=as.array(ps))
to test, I decided not to permute my matrix and just send it the original
matrix, Imatrix. Everything in C is a double, or if I use an integer, I cast
it to a double (to divide and get mean, etc). I then compare the values of
the tstats that I sent into C and the tsats I calculate within C...
The following is my C code:
void testp(double *permuted_ttests,int *B,double *permuted,double
*Imatrix,int *nc,int *nr,int *g,*double *Tinitial*,double *ps) {
after which, using the variable above I take the mean of certain elements
(currently the unpermuted matrix to test) via other functions using the same
double and pointers and I store them in C1 and C2 and solve for an absolute
T statistic - and print it (I erased the Ts earlier).
for (i=0; i<*nr; i++){
xbardiff = C1[i][0]-C2[i][0];
denom = sqrt(C1[i][2]+C2[i][2]);
* Ts[i]=fabs(xbardiff/denom);*
* Rprintf("%f Ts\n",Ts[i]);*
*
if (fabs(Ts[i])>fabs(Tinitial[i])){ //summing of permueted_ttests
counter[i]++;
Rprintf("ts %f and tinitial %f \n", Ts[i],Tinitial[i]);
}
*
etc...
The issue here - is that I get a few that when printed it appears that they
were rounded up - causing my counter[i] to ++ in some cases.
Should I send more code?
Sorry and thank you very much,
On Fri, Jul 9, 2010 at 6:18 AM, Duncan Murdoch <[email protected]>wrote:
> Joseph N. Paulson wrote:
>
>> Hi all!
>>
>> I am currently writing a C-module for a for loop in which I permute
>> columns
>> in a matrix (bootstrapping) and I send a couple of variables into C
>> initially. All of it is working, except the initial values I send to R are
>> rounded/truncated (I believe rounded).
>>
>> I am using a 32 bit machine to compile, I am using (I believe) 32 bit
>> R....
>>
>> While debugging I print the values I am sending to C, and then I print the
>> same values using Rprintf and the number gets rounded to 10^-6, which is
>> actually causing some errors for me. Is there any way to correct/prevent
>> the
>> error?
>>
>>
>> sample output from R
>>
>> [1,] 1.0000000
>> [2,] 1.0256242
>> [3,] 1.1826277
>> [4,] -0.6937246
>> [5,] 1.3633604
>>
>> sample output from C
>> 1.000000
>> 1.025624
>> 1.182628
>> 0.693725
>> 1.363360
>>
>>
>
> It looks as though you are confusing the display of numbers with their
> internal values. R is printing 7 decimal places, C is printing 6. As far
> as we can tell, that's the only difference.
>
> Duncan Murdoch
>
> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [email protected] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
- Joseph N. Paulson
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.