[R] Help with Book example of Matrix application

2012-04-09 Thread James Lenihan
I found this example in an Introductory R book in the chapter on Matrices and 
Arrays

The array is 
 m
 [,1] [,2] [,3] [,4] [,5]
[1,]0   12   138   20
[2,]   120   15   28   88
[3,]   13   15069
[4,]8   2860   33
[5,]   20   889   330

The code is  

#returns the minimum value of d[i,j], i !=j and the row attaining 
#the minimum, for square symmetric d; no special policy on ties  
mind  - function(d) {
 n  - nrow(d)
 # add a column to identify row number for apply()
 dd  - cbind(d,1:n)
 wmins - apply(dd[-n,],1,imin)
 # wins will be 2 X n, 1st row being indices and 2nd being values
 i - which.min(wmins[2,])
 j - wmins[1,i]
 return(c(d[i,j],i,j))
}

#this finds the location, value of the minimum in a row x
imin  - function(x) {
   lx  - length(x)
i  - x[lx] # original row number
j -which.min(x[(x+1):(lx-1)]) 
k - i+j
return(c(k,x[k]))
}
The result s/b
[1] 6 3 4

I am getting:

Warning messages:
1: In (x + 1):(lx - 1) :
  numerical expression has 6 elements: only the first used
2: In (x + 1):(lx - 1) :
  numerical expression has 6 elements: only the first used
3: In (x + 1):(lx - 1) :
  numerical expression has 6 elements: only the first used
4: In (x + 1):(lx - 1) :
  numerical expression has 6 elements: only the first used

I have check my typing a number of times. 

Does anyone see an error?

Thanks,

Jim L.
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] BUGS

2009-08-19 Thread James Lenihan

I am running a BUGS function with following
 
schools.sim -bugs(data,inits,
 parameters,
 model.file=schools.txt,
 n.chains=3,
 n.iter=1000,
 bugs.directory=E:/Rprograms)
 
My model.file IS in the directory =E:/Rprograms and the code is: 
 
model{
    for (j in 1:J){
    y[j] ~ dnorm (theta[j], tau.y[j])
    theta[j] ~ dnorm (mu.theta, tau.theta)
    tau.y[j] - pow(sigma.y[j], -2)
    }
    mu.theta ~ dnorm (0.0, 1.0E-6)
    tau.theta - pow(sigma.theta, -2)
    sigma.theta ~ dunif (0, 1000) 
 
I am getting the following error which I can't understand.   
 
Error in bugs(data, inits, parameters, model.file = schools.txt, n.chains = 
3,  : 
  schools.txt does not exist.

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Bayesian data analysis - help with sampler function

2009-08-18 Thread James Lenihan
I have downloaded the Umacs (Universal Markov chain sampler) and submitted the 
following sample code from Kerman and Gelman.
 
s -Sampler(
J=8,
sigma.y  =c(15,10,16,11,9,11,10,18),
  y  =c(28, 8,-3,7,-1,1,18,12),
 theta =Gibbs(theta.update,theta.init),
  V =Gibbs(V.update,mu.init),
    mu =Gibbs(mu.update,mu.init),
    tau =Gibbs(tau.update,tau.init),
   Trace(theta[1])
)
 
Error: could not find function Sampler
 
Is there anything else I need to download.
 
Thanks,
 
 
Jim L.
  
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] a loop for boxplot graphs

2009-03-29 Thread James Lenihan

Dear Colleagues
 
I have the following code that generates a boxplot for one specific labtest:
 
boxplot.n(LBSTRESN~COHORT, main=Boxplot of laboratory data for XLXXX-XXX 
test=Creatinine, 
subset = LBTEST==Creatinine,
xlab = Cohort Number,
ylab = Units = umol/L,
varwidth=TRUE
 
I would like to know if there is a way to loop through the dataset and produce 
the boxplot for a number of specific labtest.
 
Looking at the documentation for loops I can't see how I would change the 
ylab,mainand subset  
 
Can someone refer me to a similar example in the online documentation?
 
Thanks,
 
 
Jim L 
[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] sm.density.compare

2009-03-03 Thread James Lenihan
I am running the sm.density.compare function amd I am getting the following 
error:
 
my code is   sm.density.compare(LBSTRESN,COHORT,xlab=Units = umol/Lsubset = 
LBTEST==Creatinine)
 
Error in if (from == to) rep.int(from, length.out) else as.vector(c(from,  : 
  missing value where TRUE/FALSE needed
 
I do not understand the error and I have had no help when searching the WEB or 
the R documentation.
 
I have tried the sample program in the R doc:y - rnorm(100)
g - rep(1:2, rep(50,2))
sm.density.compare(y, g, model=equal)
 and it works fine.   The only difference with my data is that I have some 
missing values that show as NA. I have checked that theseare numbered values by 
using the is.nan function. Any ideas? Thank You Jim L. 


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.