
Thank you so much Mr. William for writting back to me.
I apolorize about  my reply becuase i did not receive your mail until late of today because it is due to the mail server of my school but now they had fixed it.


Following your message, I corrected my program ny open a sinkfile and close it after you but i still getting another error. This time is related to

sinkFile <- open("comp.dat", open = "a")
Problem in open.connection: argument open= not matched: open.connection(object, open = "a")
Use traceback() to see the call stack


Attached is my program
#################################### Minh prgram after changed of open , close of sinkFile ###################################################################



remove(objects())
trace()

# set up sample size
n <- 30
## set up number of replication
numrep <- 100
# set up rho or correlation of bivariate variables x and y in an unrestriction of range
rho <- 0.2
## set up  mean of x
meanx <- 0
### set up variance of x
varx <- 0.2

### set up mean of y
meany <- 0
### set up variance of y
vary <- 0.2
## set up cut_off_point
cutoffpoint <- 0.2;

## reliability in Hunter-Schmidt
reliabilityhunterschmidt <- 0.5



################################################# End of printing services to output file #################################################
################################################# End of printing services to output file #################################################
################################################# End of printing services to output file #################################################
############################################################################################################################################
### Libraries of  functions and  subroutines for part I of the project
### Subroutines:
##  1. find max value of x
##  2. find min value of x
##  3. find max value of y
##  4. find min value of y
##  5. find standard devaiation of x
##  6. find standard deviation of y
##  7. find standard deviation in a restricted of x
##  8. find standard deviation in a restricted of y
##  9. find mean of restricted of x
## 10. find mean of restricted of y
## 11. find z score of x
## 12. find z score of y
## 13. find pnorm of z score
## 14. find area of pnorm which is qnorm
##15 standard deviation of sample x
##16  standard deviation of sample y
##
maxxscore <- function(x)
{
    return(max(x))
}
minxscore <- function(x)
{
    return(min(x))
}
maxyscore <- function(y)
{
    return(max(y))
}
minyscore <- function(y)
{
    return(min(y))
}

stdx <- function(x)
{
    return(sqrt(var(x)))
}

stdsamplex <- function(x,size)
{
n1 <- size
x1 <- x
tempx <- c(0,dim = c(n1,1))
    meanxx <- mean (x1)
    for (i in 1 :n1)
     {
      tempx[i] = (x1 [i] - meanxx) * (x1[i] - meanxx)
     }

     total <- 0
     for (i in 1:n1)
     {
      total <- total + tempx[i]
     }
    rm (x1, tempx, meanxx,i)
    return(sqrt(total/(n1-1)))
}
stdy <- function(y)
{
    return(sqrt(var(y)))
}


stdsamplecutx <- function(newx,size)
{
ncut <- size
tempcutx <- c(0,dim = c(ncut,1))
    meancutx <- mean (newx)
    for (i in 1 :ncut)
     {
      tempcutx[i] = (newx [i] - meancutx) * (newx[i] - meancutx)
     }

     totalcut <- 0
     for (i in 1:ncut)
     {
      totalcut <- totalcut + tempcutx[i]
     }
    rm (tempcutx,meancutx)
    return(sqrt(totalcut/(ncut-1)))
}


stdsampley <- function(newy,size)
{
ncut <- size
tempcuty <- rep (0,ncut)
    meancuty <- mean (newy)
    for (i in 1 :ncut)
     {
      tempcuty[i] = (newy [i] - meancuty) * (newy[i] - meancuty)
     }

     totalcut <- 0
     for (i in 1:ncut)
     {
      totalcut <- totalcut + tempcuty[i]
     }
    rm (tempcuty,meancuty)
    return(sqrt(totalcut/(ncut-1)))
}

stdsamplecuty <- function(cuty,size)
{


#cat ("\n\n=======================>>>>>> INSIDE SAMPLE CUT Y <<<<<<+++++++++++++++++++++\n\n")
n1 <- size
tempy <- rep (0,n1)
    meany <- mean (cuty)
#    cat ("\n Cut y = ", cuty)
#   cat ("\n size = ", size)
#    cat ("\nMean of y = ", meanY)

    for (i in 1 :n1)
     {
      tempy[i] = (cuty [i] - meany) * (cuty[i] - meany)
     }

     total <- 0
     for (i in 1:n1)
     {
      total <- total + tempy[i]
     }
    rm (tempy,meany)
    return(sqrt(total/(n1-1)))
}


meanrestrictedx <- function(x)
{
    return(mean(x))
}
stdrestrictedx <- function(x)
{
    return(sqrt(var(x)))
}
meanrestrictedy <- function(y)
{
    return(mean(y))
}
stdrestrictedy <- function(y)
{
    return(sqrt(var(y)))
}
zscoreforx <- function(x, meanx, stdx)
{
    return((x - meanx) / stdx)
}
zscorefory <- function(y, meany, stdy)
{
    return((y - meany) / stdy)
}
pnormz <- function(zscore)
{
    return(pnorm(zscore))
}
zscore <- function(area)
{
    return(qnorm(area))
}
isarealeftofcutpoint <- function(zscore, cutpointvaluearea)
{
    if (zscore >= cutpointvaluearea)
    {
        return(1)
    }
    else
    {
        return(0)
    }

}

findcorrelationofsamplesize  <- function (x,y,n)
{

  size <- n
  meanofx <- mean (x)
  stdx <- stdsamplex(x,size)
  meanofy <- mean (y)
  stdy <- stdsampley (y,size)
  ##totalX <- 0
  ##totalY <- 0
  totalxy <- 0
# cat ("\n\n Inside the sample correaltion")
# cat ("\n\n x is ", x, "\n\n")
# cat ("\n\n y is ", y, "\n\n")


  cat ("\n\n      Mean of sample x is ", meanofx)
    cat ("\n\n      Mean of sample y is ", meanofy)

    cat ("\n\n     Std of sample x is ", stdx)
    cat ("\n\n     Std of sample y is ", stdy)




    for (i in 1:size)
     {
    ## Wrong  totalX <- totalX + ((x [i] - meanX) / stdX)
    ## Wrong  totalY <- totalY + ((y[i] - meanY) / stdY)
      totalxy <- totalxy + ((x [i] - meanofx)* (y[i] - meanofy))

     }
   #   cat ("\n\nINside sample correlation numerator = " , totalXY, "\n\n")
     totalxy <- totalxy / ((size-1)* stdx * stdy)

   #  cat ("\n\nINside sample correlation denominator = " , (n - 1) * stdX * stdY, "\n\n")
   #   cat ("\n\n End Inside the sample correaltion")
     rm (size, meanofx, stdx,meanofy, stdy)
     return (totalxy)



}
findcorrelationofsamplesizetaftercut  <- function (newx,newy,cutsize)
{

 # cat ("\n\n New X = ",NewX)
 # cat ("\n\n New Y = ",NewY)
 # cat ("\n\n Size is  = ",cutSize)
  meanofx <- mean (newx)
  stdofx <- stdsamplecutx(newx,cutsize)
  meanofy <- mean (newy)
  stdofy <- stdsamplecuty (newy,cutsize)
  ##totalX <- 0
  ##totalY <- 0
  totalxy <- 0
# cat ("\n\n Inside the sample correaltion")
# cat ("\n\n x is ", x, "\n\n")
# cat ("\n\n y is ", y, "\n\n")


  cat ("\n\n      Mean of sample x is ", meanofx)
    cat ("\n\n      Mean of sample y is ", meanofy)

    cat ("\n\n     Std of sample x is ", stdofx)
    cat ("\n\n     Std of sample y is ", stdofy)




    for (i in 1:cutsize)
     {
    ## Wrong  totalX <- totalX + ((x [i] - meanX) / stdX)
    ## Wrong  totalY <- totalY + ((y[i] - meanY) / stdY)
      totalxy <- totalxy + ((newx [i] - meanofx)* (newy[i] - meanofy))

     }
   #   cat ("\n\nINside sample correlation numerator = " , totalXY, "\n\n")
     totalxy <- totalxy / ((cutsize-1)* stdofx * stdofy)

   #  cat ("\n\nINside sample correlation denominator = " , (n - 1) * stdofX * stdofY, "\n\n")
   #   cat ("\n\n End Inside the sample correaltion")
     rm (meanofx, stdofx, meanofy, stdofy)
     return (totalxy)



}


fishercorrelation <- function (correlationaftercutoff)
{
   fishercor <- 0.5 * log((1 + correlationaftercutoff) / (1 - correlationaftercutoff))
   return (fishercor)
}
###### end of library #####################









####################################################################################################################################################################
## Function return data frame of x and y where correlation equals to given correlation value
# target correlation in sample mean with given mean and variance
#This can be done using the orthogonal projection of the noise in the space orthogonal to that generated by A.
#In this way you are able to find an incorrelated noise with the variance that you want.
#The final vector B can be computed as ( B= A + Orthogonal noise ), and I use the variance of the noise to find the correlation that you want.
# by Horace Tso
#original variable -- random variable as you want
#x <- array(rnorm(n), dim = c(n,1)) *30 + 500
####################################################################################################################################################################

returndataframe <- function (dx,dy,nx,meanx,varx,rho) {

#cat ("\n\nVector dx in data frame is " , dx)
#cat ("\n\nVector dy in data frame is " , dy)
#cat ("\n\n Value dn in data frame is  " , nx)
mymeanx <- meanx
myvarx <- varx
myrho <- rho
dx <- array(rnorm(nx, mymeanx, myvarx), dim=c(nx, 1))
#hist(dx)
#cat("\n\n dx = ", dx)
# temporary variable with zero mean
xtemp <- dx
# mean x
# standard deviation = SQRT [Summation (X - mean x) ^ 2 / (n- 1)]
# variance = standard deviation ^ 2
xtemp <- xtemp - mean(dx)
#cat("Vector of different of x and mean of x = ", xtemp)
varxx <- var(xtemp)
# new random vector of noise
newvarx <- c(varxx)
#cat("New variance of X = ", newVarX)
temp <- sqrt(c(varxx)) * array(rnorm(nx, mymeanx, myvarx), dim=c(nx, 1))
#cat("new temp array = ", temp)
# noise orthogonal to x
# matrix multiplication %*% , solve function matrix inverse
epsilon <- temp - xtemp %*% solve(t(xtemp) %*% xtemp,
         t(xtemp) %*% temp)
# variance of noise othogonal
vare <- var(epsilon)
#alpha -- coefficient to find the correlation that you want
alpha <- sqrt((1 - myrho ^ 2) / (myrho ^ 2) * varxx / vare)
# new noise orthogonal and with the varianze required
eps1 <- epsilon * c(alpha)
#new vector target
dy <- dx + eps1
# if the target correlation shoud = 0 or <0 ...
if (myrho == 0)
{
    dy <- epsilon
}
if (myrho < 0)
{
    dy <- -dy
}
#cat ("y values = ", y)
vectorxy <- data.frame(dx,dy)
rm (mymeanx,myvarx,myrho,xtemp,newvarx,varxx,temp,epsilon,vare,alpha,eps1)
return (vectorxy)
}
# check the correlation between x and y,and scatter plot
####print(paste("correlation", cor(y, x)))
####title("Graph of X and Y")
####postscript("C:\\Dung\\original.ps", horizontal=F)
####paste("this S-plus graph was created on", date())
######################################################################################################################################################################

####### reliability coefficient in Hunter Schmidt
####################### Setting up global variables
#####      n   =  sample size , n = {30, 60, 120, 1000, 2000,3000}
#####     num_rep = number of replication , number of replication = {1000,2000, 3000}
#####     rho  = Correlation of bivariate variables x , and y in an unrestriction of  range, rho = {0.3, 0.5 , 0.8}
####      mean_X = mean of variable x
####      var_X  = variance of variable x
####      mean_Y = mean of variable y
####      var_Y = variance of y
#####     Cutting off point = cut off point in X , and x = {0.2, 0.5, 0.8}
#####     num_rep = number of replication , number of replication = {1000,2000, 3000}
#####     reliability_Hunter_Schmidt = reliability of Hunter Schmidt = {0.5,07}
#
###################################################################################################################################################################
### Store Fisher value, cut off size
fisherval <- rep (0,numrep)
cutoffsize <- rep (0,numrep)
##*************************************************################################################################################################
sinkFile <- open("comp.dat", open="a")

for (minh in 1:numrep) {
sink (sinkFile)
x <- rep (0,n)
#for (cnt in 1:n) {
#cat ("\n\n x is ====>>>>", x[cnt])
#}
## initialize vector y
#y <- c(0,dim = c(n,1))
y <- rep (0,n)
## integrate vector x and y into dataframe
vectorxy_data.frame (x,y)

# Initialize newX
#NewX <- c(0, dim=c(n, 1))
newx <- rep (0,n)
#Initialize newY
#NewY <- c(0, dim=c(n, 1))
newy <- rep (0,n)





cat ("\n\n*** ****************************  Begin OF LOOP number =  ", minh, " ********************  \n\n")
cat ("\n\n*** *************************************************************************************  \n\n")

sink ()



######################### Begin of program
sink (sinkFile)
vectorxy <- returndataframe (x,y,length(x),meanx,varx,rho)
#cat ("\n\n x ====", x)
#cat ("vectorXy is ============= ", vectorXY, "\n")

cat ("\n\n","*** Step 1 : Unrestricted Population and Sample Correaltion \n\n ")
print (vectorxy)
##Printing (vectorXY)
retx <- vectorxy[,c(1)]
rety <- vectorxy[,c(2)]
#cat ("******************************************************************************* Normal distribution ******************************","\n")
#cat ("\n\nx values in normal program = ", x, "\n")
#cat ("\n\ny values in  normal program = ",y,"\n")
#cat ("******************************************************************************* Normal distribution ******************************","\n")
#plot (x,y)

#hist(x)
#hist(y)
#plot(x, y)
originalcorrvalue <- (cor (retx,rety))
cat ("\nThe population correlation value of sample size equaled to (",  n , ") is =   ", originalcorrvalue, "\n\n")
correlationvaluesamplesize <- findcorrelationofsamplesize (retx,rety,n)
#options(digits = 16)
cat ("\nThe sample correlation value of sample size equaled (", n , ") is =   ", correlationvaluesamplesize, "\n\n")
sink ()




###################################### Convert data frame into data matrix ###############################################
###################################### Convert data frame into data matrix ###############################################
###################################### Convert data frame into data matrix ###############################################
###################################### Convert data frame into data matrix ###############################################
sink (sinkFile)
cat ("\n\n*** Step 2 : Restricted population and sample correlation based on cut off point = ", cutoffpoint, " on x axis  \n\n")

# calculate sample mean of x
meanx1 = mean(retx)
stdx = stdsamplex(retx,length(retx))

# set first time through the loop equals to true
firstTime <- 1
newxindex <- 0;
for (i in 1:length(retx))
{
    zscoreofx = zscoreforx(retx[i], meanx1, stdx)

    #cat ("X ith = ", x[i])
    #cat ("ZScore for x = ", ZScoreofX)

    ###  transform the z score to Pnorm which will be used to compare with the left of the cut off point
    areaconfidenceinterval = pnormz(zscoreofx)

#################  Applied of cut off point on X ######################################################################################################
#cat ("Area of confident interval ", AreaConfidenceInterval)
    result <- isarealeftofcutpoint(areaconfidenceinterval,cutoffpoint)

########################  Getting result of new element in vector of x ,
######################### and new a new element in vector of y after applying cut off point on x axis ###################################
    #    cat ("Result is ", result)
    if (result == 1)
    {
        if (firstTime == 1)
        {
            index <- 1
            firstTime <- 0
        }

        tempx <- x[i]
        newx[index] <- tempx
        tempy <- y[i]
        newy[index] <- tempy
     #   cat("X = ", tempX, "  ; Y = ", tempY, "\n\n")
     #   cat("Index = ", index, " ,NewX = ", NewX[index],", NewY = ", NewY[index], "\n\n\n")
        index <- index + 1
        newxindex <- index
    }
      cat ("\n\n  Element = " , i, " ; value = ", x[i], " ; Zscore value = ", zscoreofx, "; Pnorm value = ", areaconfidenceinterval, " ; Included = ", result, "\n")
}


newxx <- rep (0, newxindex -1)
newyy <- rep (0, newxindex - 1)
for (mycnt in 1: newxindex - 1)
{
    newxx [mycnt] <- newx [mycnt]
    newyy [mycnt] <- newy [mycnt]

}

vectornewxy <- data.frame (newxx,newyy,newxindex - 1)
cutoffsize [minh] <- newxindex -1

cat ("\n\n")
print (vectornewxy)
# check the sample correlation between x and y,and scatter plot
##print(paste("correlation", cor(NewY, NewX)))
correlationsampleaftercutoff <- findcorrelationofsamplesizetaftercut(newxx,newyy,length(newxx))
cat("\n\ncorrelation of sample after cut off point is ", correlationsampleaftercutoff)
sink ()
#hist(newxx)
#hist(newyy)
#plot(newxx, newyy)
####dev.off()
fishercor <- fishercorrelation (correlationsampleaftercutoff)
sink (sinkFile)
cat ("\n\n*** Step 3 : Fisher  correlation applied to sample correlation of the  cut off point = ", " on x axis  \n\n")
cat ("\n\n Fisher correlation", fishercor,"\n")
fisherval [minh] <- fishercor
sink ()


sink (sinkFile)
cat ("\n\n*** ****************************  END OF LOOP =  ", minh, " ********************  \n\n")
cat ("\n\n*** ****************************  END OF LOOP =  ", minh, " ********************  \n\n")
sink ()
}
close(sinkFile)












#################################### Minh prgram after changed of open , close of sinkFile ###################################################################
















________________________________________
From: William Dunlap [via R] [ml-node+2331833-526419113-138281@n4.nabble.com]
Sent: Thursday, August 19, 2010 1:33 PM
To: Dung Tran
Subject: Re: Can't read/write to _nonfi

Min,

For S+-specific questions the S-news mailing list
would be better.
   [hidden email]</user/SendEmail.jtp?type=node&node=2331833&i=0>

Unlike R, S+ stores its data objects in files, one file
per object.  The ___nonfi (___nonfiles) file contains
a mapping for object names to file names, for those
objects whose names cannot be unambiguously used as
file names.

The copies of the error messages look garbled to me.
They are definitely missing some characters and I don't
see the "Can't access to ..." message in the S+ source
code, but perhaps I'm not looking in the right version
  > Can' access to file _nonfi
  > Can't create file for assigning "last.dump"
  > ("C:/WORKSPACE/DUNG/.Data/___bd40"
What version of S+ are you using and what are the precise
error messages?

Do you own the C:/WORKSPACE/DUNG directory or is
it someone else's?  If it is someone else's and it
is sufficiently protected, you may not be able write
files into it.  Can you create any other data objects?
E.g., can you successfully execute the following?
    qaz <- 1:10
    print(qaz)
and
    Q.A.Z. <- log(qaz)
    print(Q.A.Z)


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

> -----Original Message-----
> From: [hidden email]</user/SendEmail.jtp?type=node&node=2331833&i=1>
> [mailto:[hidden email]</user/SendEmail.jtp?type=node&node=2331833&i=2>] On Behalf Of minh
> Sent: Thursday, August 19, 2010 11:48 AM
> To: [hidden email]</user/SendEmail.jtp?type=node&node=2331833&i=3>
> Subject: [R] Can't read/write to _nonfi
>
>
> Good afternoon,
>    Hope you all have a wonderful day. I am glad to be here.
> Hope you could
> help me with the  following errors that i have been trying to
> figure it  all
> out since last week.
>
>   I am using Splus from Insightful, and as i read, R and
> Splus are very
> similar. So hope you could help me.
>
>
>  I have been continously received these error messages after
> i ran my small
> program for couple of times.
>
>
>
> Can' access to file _nonfi
> Can't create file for assigning "last.dump"
> ("C:/WORKSPACE/DUNG/.Data/___bd40"
>
>
>
> It is frustrating since the program is so small , and as i
> look into my
> project, the _nonfi is there under the data folder. So i
> don't know what the
> compiler is complained about. Since i am new to Splus
> language, I have no
> clue what i need to do.
>
> for (i in 1: 1)
>
> {
>
> x <- rnorm (1000);
>
> y <- rnorm (1000)
>
> newx <- x
>
> newy <- y
>
> hist (newx)
>
> hist (newy)
>
>
> }
>
>
>
>
>
>
>
> If you happen to know what i need to do, please help me.
>
> Thank you so much,
> Min
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Can-t-read-write-to-nonfi-tp2331<http://r.789695.n4.nabble.com/Can-t-read-write-to-nonfi-tp2331?by-user=t>
707p2331707.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email]</user/SendEmail.jtp?type=node&node=2331833&i=4> 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.
>

______________________________________________
[hidden email]</user/SendEmail.jtp?type=node&node=2331833&i=5> 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.


________________________________
View message @ http://r.789695.n4.nabble.com/Can-t-read-write-to-nonfi-tp2331707p2331833.html
To unsubscribe from Can't read/write to _nonfi, click here<http://r.789695.n4.nabble.com/template/NodeServlet.jtp?tpl=unsubscribe_by_code&node=2331707&code=ZHRyYW43QHN0dWRlbnQuZ3N1LmVkdXwyMzMxNzA3fC0xNTY1ODk3NDUw>.


-- 
View this message in context: http://r.789695.n4.nabble.com/Can-t-read-write-to-nonfi-tp2331707p2332727.html
Sent from the R help mailing list archive at Nabble.com.

	[[alternative HTML version deleted]]

