[R] print elements' placings from vector

2011-05-04 Thread derek
Dear R,

Here is a code:
z=c(1,3,0.5,6,8,10,2,2,3,4,7,3)
z[z>2]

I dont want print the elements, but theirs placings in vector.




--
View this message in context: 
http://r.789695.n4.nabble.com/print-elements-placings-from-vector-tp3496645p3496645.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] print elements' placings from vector

2011-05-04 Thread derek
Yes, thank you.

--
View this message in context: 
http://r.789695.n4.nabble.com/print-elements-placings-from-vector-tp3496645p3497080.html
Sent from the R help mailing list archive at Nabble.com.

__
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] plot generates graph with coordinantes written over it

2011-03-12 Thread derek
Hello R users, Im having this strange problem.
http://r.789695.n4.nabble.com/file/n3350024/bad2.png 

I have txt file of this format (X.X, Y.Y - random numbers, ...) with data
points:
nm A nm A nm A
X.X Y.Y X.X XX X.X
X.X Y.Y Y.Y Y.Y Y.Y

My script looks like this:

require(graphics)
require(stats)
par(mfrow=c(1,1))
HMF=read.table("D:/BIOTECHLAB1/DATA-zprac/10mg 1-7cp.txt", header = FALSE,
sep = "", dec = ".",fileEncoding = "", encoding = "unknown", skip=19)
attach(HMF)
plot(x=V1,y=V2,type = "l",main = HMF,xlab = substitute(lambda (nm)), ylab
=substitute(A))

R version 2.12.1 x64 (WIN7 x64)


--
View this message in context: 
http://r.789695.n4.nabble.com/plot-generates-graph-with-coordinantes-written-over-it-tp3350024p3350024.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] plot generates graph with coordinantes written over it

2011-03-12 Thread derek
Solution:
main=HMF -> main="HMF"

--
View this message in context: 
http://r.789695.n4.nabble.com/plot-generates-graph-with-coordinantes-written-over-it-tp3350024p3350163.html
Sent from the R help mailing list archive at Nabble.com.

__
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] how to label lines

2011-03-12 Thread derek
Hello R
I can not figure out, how to add text string or number to lines like on this
image:
http://r.789695.n4.nabble.com/file/n3350452/graph.png 
I have some data series in text file.

My script:

require(graphics)
require(stats)
graf=read.table("file",header =FALSE,sep = "", dec = ",",fileEncoding = "",
encoding = "unknown", skip=19,nrows=400)
attach(graf)
plot(V1,V2,type = "l",main = "name",xlab = substitute(lambda (nm)), ylab
=substitute(A))
lines(V3,V4)
lines(V5,V6)
lines(V7,V8)
lines(V9,V10)
lines(V11,V12)
lines(V13,V14)
lines(V15,V16)
lines(V17,V18)
lines(V19,V20)
lines(V21,V22)


--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-label-lines-tp3350452p3350452.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] how to label lines

2011-03-12 Thread derek
Thank you for reply. I think, in script you posted, I have to manually add
coordinates for label. I don't want do it manually. I would like to add
labels at the points, where the lines are maximally separated. (points of
maximum separation). Graphic representation of my data looks very similar to
image I posted earlier. The legend is unnecessary, because each line
represents same substance at different concentration. I would like to have
the lines labeled with numeric value (e.g.. "0.9 mg/l", 0.8 mg/l)

Example of my data in graph.txt file:
V1  V2 V3 V4   V5   V6
200 0.100 200 0.110 200  0.120
210 0.130 210 0.150 210  0.170
230 0.100 230 0.100 230  0.120

odd numbered columns (e.g.. V1) represents x axis
even numbered columns (e.g.. V2) represents y axis

Package hmisc and function labcurve should do trick, but I barely understand
from manual how to do it.
Probably something like this:

graph=read.table("graph.txt",header =FALSE,sep = "", dec = ",",fileEncoding
= "", 
> encoding = "unknown", skip=19,nrows=400) 
> attach(graf) 
a=data.frame(V1,V2)
b=data.frame(V3,V4)
c=data.frame(V5,V6)

label(a) <- 0.1 mg/l
label(c) <- 0.2 mg/l
label(c) <- 0.3 mg/l




--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-label-lines-tp3350452p3350942.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] how to label lines

2011-03-12 Thread derek
Problem solved:
require(graphics)
require(stats)
require(hmisc)
HBA=read.table("file",header =FALSE,sep = "", dec = ",",fileEncoding = "",
encoding = "unknown", skip=60,nrows=210)
attach(HBA)
labcurve( list( One=  list( V1,V2), Two=  list( V3,V4), 
   Three=list( V5,V6), Four= list( V7,V8), Five= list( V9,V10),Six= list(
V11,V12),Seven= list( V13,V14),Eight= list( V15,V16),Nine= list(
V17,V18),Ten= list( V19,V20)), 
   keys=c('10','9','7','6','5','4','3','2','1','0,5'),  keyloc="none",
pl=TRUE,  xlab="lambda",  ylab="Abs" ) 

Sadly its not clearly written in manual or maybe Im just extremely dull.

--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-label-lines-tp3350452p3351039.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] how to label lines

2011-03-13 Thread derek
Nice, thank you.

--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-label-lines-tp3350452p3351605.html
Sent from the R help mailing list archive at Nabble.com.

__
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] pdf device - different page orientation and different plot sizes

2011-03-13 Thread derek
Hello R,

I would like make single pdf file in which the the pages are are of mixed
format. 
Manual states this code (down). The problem is the second "{}" overwrites
the first "{}", but I want to append them.

require(graphics)
require(stats)
HBA=read.table("file.txt",header =FALSE,sep = "", dec = ",",fileEncoding =
"", encoding = "unknown", skip=19,nrows=400)
attach(HBA)

{
pdf(file ="file.pdf",width=3.2,height=2.5,paper="A4")
par(mfrow=c(4,2))
plot(V1,V2,type = "l")
lines(V29,V30)
plot(V3,V4,type = "l")
lines(V5,V6)   dev.off()
dev.off()
}

{
pdf(file ="file.pdf",width=11,height=7,paper="A4r")
par(mfrow=c(1,1))
plot(V1,V2,type = "l")
lines(V29,V30)
plot(V3,V4,type = "l")
lines(V5,V6)   dev.off()
dev.off()
}



--
View this message in context: 
http://r.789695.n4.nabble.com/pdf-device-different-page-orientation-and-different-plot-sizes-tp3351881p3351881.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Finding coordinates for maximum of a function

2011-03-15 Thread derek
Hello R,

I have data in txt file of n columns like this:
x  y1 .yn
1  100
2  50
3  10
4  200
5  20


I need to find coordinates for each maxima e.g.: [x,y1],[x,y2]...[x,yn]

a=read.table()
attach(a)
b=y1<-x
max(b) returns only value of y but no corresponding x value



--
View this message in context: 
http://r.789695.n4.nabble.com/Finding-coordinates-for-maximum-of-a-function-tp3355369p3355369.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Finding coordinates for maximum of a function

2011-03-15 Thread derek
It occured to me:
x[max(y)] simple isn't it?

--
View this message in context: 
http://r.789695.n4.nabble.com/Finding-coordinates-for-maximum-of-a-function-tp3355369p3356117.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Finding coordinates for maximum of a function

2011-03-15 Thread derek
I must have mixed it up. Thank you.

--
View this message in context: 
http://r.789695.n4.nabble.com/Finding-coordinates-for-maximum-of-a-function-tp3355369p3357460.html
Sent from the R help mailing list archive at Nabble.com.

__
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] adding linear regression data to plot

2011-03-15 Thread derek
Hello R,

I would like to print regression data in graph. I mean the output from:
k=lm(formula,data)
summary(k)

Or somehow extract and print only coefficients and R-squared.



--
View this message in context: 
http://r.789695.n4.nabble.com/adding-linear-regression-data-to-plot-tp3357946p3357946.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] adding linear regression data to plot

2011-03-16 Thread derek
I know I can add line to graph with abline(), but I would like to print
R-squared, F-test value, Residuals  and other statistics from lm() to a
graph. I don't know how to access the values from summary(), so that I can
use them in a following code or print them in a graph.

--
View this message in context: 
http://r.789695.n4.nabble.com/adding-linear-regression-data-to-plot-tp3357946p3382135.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] adding linear regression data to plot

2011-03-16 Thread derek
Thank you that is very helpful.

--
View this message in context: 
http://r.789695.n4.nabble.com/adding-linear-regression-data-to-plot-tp3357946p3382615.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Strange R squared, possible error

2011-03-16 Thread derek
k=lm(y~x)
summary(k)
returns R^2=0.9994

lm(y~x) is supposed to find coef. a anb b in y=a*x+b

l=lm(y~x+0)
summary(l)
returns R^2=0.9998
lm(y~x+0) is supposed to find coef. a in y=a*x+b while setting b=0

The question is why do I get better R^2, when it should be otherwise?

Im sorry to use the word "MS exel" here, but I verified it in exel and it
gives: 
R^2=0.9994 when y=a*x+b is used
R^2=0.99938 when y=a*x+0 is used

--
View this message in context: 
http://r.789695.n4.nabble.com/Strange-R-squared-possible-error-tp3382818p3382818.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Strange R squared, possible error

2011-03-16 Thread derek
It states summary.lm:

r.squared   R^2, the ‘fraction of variance explained by the model’,

R^2 = 1 - Sum(R[i]^2) / Sum((y[i]- y*)^2),

where y* is the mean of y[i] if there is an intercept and zero otherwise.

Why to use different formula when intercept is set to zero?

I tried to compute R^2 from sk=summary(lm(y~x+0))
t=sum(for(i in 1:10) (sk$residuals[i])^2)) # but it doesn't work 

--
View this message in context: 
http://r.789695.n4.nabble.com/Strange-R-squared-possible-error-tp3382818p3383023.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Strange R squared, possible error

2011-03-16 Thread derek
1) In my very humble opinion R^2 can't be negative, at least for data for
which it sound to use linear model.
Or the data would have to be utterly wrong to fit them with linear model.

2) I don't want to fit data with linear model of zero intercept.
3) I dont know if I understand correctly. Im 100% sure the model for my data
should have zero intercept. 
The only coordinate which Im 100% sure is correct. If I had measured quality
Y of a same sample X0 number of times I would get E(Y(X0))=0.

Basically what I need to compute is R^2=1- (sum(residue^2))/(sum(Y[i])) both
for model with and without intercept. I don't want to consider null model
(model with zero intercept) at all.

I don't know why to use y* in  R^2 = 1 - Sum(R[i]^2) / Sum((y[i]- y*)^2)

--
View this message in context: 
http://r.789695.n4.nabble.com/Strange-R-squared-possible-error-tp3382818p3383277.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Strange R squared, possible error

2011-03-17 Thread derek
Exuse me, I don't claim R^2 can't be negative. What I say if I get R^2
negative then the data are useless.
I know, that what Thomas said is true in general case. But in my special
case of data, using nonzero intercept is nonsense, and to get R^2 less than
0.985 is considered poor job (standard R^2>0.995). (R^2 given by R^2 = 1 -
Sum(R[i]^2) / Sum((y[i])^2) )

Because lm() uses two differrent formulas for computing R^2,
it is confusing to get R^2 closer to 1 when linear model with zero intercept
y=a*x (a = slope) is used, rather than in case with model y=a*x+b (a=slope,
b= nonzero intercept).

I think R^2 is only measure of good fit for least squares optimization and
it doesn't matter which formula is used: (R^2 = 1 - Sum(R[i]^2) /
Sum((y[i])^2) or R^2 = 1 - Sum(R[i]^2) / Sum((y[i])^2-y*)), but using both
is confusing.

So I would like to know why two different formulas for R^2 are used? 



--
View this message in context: 
http://r.789695.n4.nabble.com/Strange-R-squared-possible-error-tp3382818p3383992.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Strange R squared, possible error

2011-03-17 Thread derek
Thank you for your very comprehensible answer. 
I a priori know that model y=a*x+0 is right and that I can't get x=constant
nor y=constant. 
I'm comparing performance of data gathering in my data set to another data
sets in which performance gathering is characterized by R-squared . The data
in data sets are not random but have random error with normal distribution.
The error in my data is composed of human and equipment error (normal
distribution), appliance error (probably skewed normal distribution) and
some other interferences. So I compare model y = a*x + b and y = a*x + 0 to
know the magnitude of interferences which I can't influence - the difference
of R^2's.

--
View this message in context: 
http://r.789695.n4.nabble.com/Strange-R-squared-possible-error-tp3382818p3385009.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Strange R squared, possible error

2011-03-17 Thread derek
Yes they are. I had edited the reply, but It didn't help.
Correction:
2)I meant zero slope, no zero intercept.


--
View this message in context: 
http://r.789695.n4.nabble.com/Strange-R-squared-possible-error-tp3382818p3384648.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Strange R squared, possible error

2011-03-17 Thread derek
Thats exactly what I would like to do. Any idea on good text? I've consulted
severel texts, but no one defined R^2 as R^2 = 1 - Sum(R[i]^2) /
Sum((y[i])^2-y*)) still less why to use different formulas for similar model
or why should be R^2 closer to 1 when y=a*x+0 than in general model y=a*x+b.

from manual:
r.squared R^2, the ‘fraction of variance explained by the model’, 
R^2 = 1 - Sum(R[i]^2) / Sum((y[i]- y*)^2), 
where y* is the mean of y[i] "if there is an intercept" and zero otherwise. 

I don't need explaining what R^2 does nor how to interpret it, because I
know what it means and how it is derived. I don't need to be told which
model I should apply. So the answers from Thomas weren't helpful. 

I don't claim it is wrong, otherwise wouldn't be employed, but I want to see
the reason behind using two formulas.

Control questions:
1) Statement "if there is an intercept" means intercept including zero
intercept?

2) If I use model y = a*x+0 which formula for R^2 is used: the one with Y*
or the one without?

--
View this message in context: 
http://r.789695.n4.nabble.com/Strange-R-squared-possible-error-tp3382818p3384844.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Strange R squared, possible error

2011-03-17 Thread derek
Thank you for our reply. It's a pity, that 2 variables defined by different
formula have same name. If the variables had been named differently, I
wouldn't have problem at all and it looks like it's done on purpose.
Because I test a quality of data (performance of collecting data) not a
model which I know a priori, R^2 gives me simple information of that quality
even for nonlinear model.

Still when testing different models R^2 shows nothing important. I didn't
stated that negative R^2 is meaningless. It has meaning that the model or
the data are wrong.

--
View this message in context: 
http://r.789695.n4.nabble.com/Strange-R-squared-possible-error-tp3382818p3385837.html
Sent from the R help mailing list archive at Nabble.com.

__
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] ploting continuos function

2011-04-22 Thread derek
Hello R,

I would like to plot continuos function (e.g. y=x^2) without creating a
sequence for x.
Is there a possibility to somehow specify the range - x belongs to
<-100,100>?

--
View this message in context: 
http://r.789695.n4.nabble.com/ploting-continuos-function-tp3467533p3467533.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] Odp: ploting continuos function

2011-04-22 Thread derek
Nice. Thank you

--
View this message in context: 
http://r.789695.n4.nabble.com/ploting-continuos-function-tp3467533p3467816.html
Sent from the R help mailing list archive at Nabble.com.

__
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] filling array with functions

2011-04-22 Thread derek
Hello R,

I would like to find out how to generate array full of functions. I tried it
like this:

fv=array(,dim=c(1,10))
V=c(1:10)
for (i in 1:10){
fv[i]<-function(x)(V[i]-b*a*x) # b, x are constants.
}

But it returns:
"incompatible types (from closure to logical) in subassignment type fix"


--
View this message in context: 
http://r.789695.n4.nabble.com/filling-array-with-functions-tp3468313p3468313.html
Sent from the R help mailing list archive at Nabble.com.

__
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] random typing over text

2011-04-23 Thread derek
Dear R,

When I'm writing script I probably hit accidently some hot key and then the
text in script is being overwritten  
by subsequent typing. Please what is the hot key or how can I disable it?

--
View this message in context: 
http://r.789695.n4.nabble.com/random-typing-over-text-tp3470428p3470428.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] random typing over text

2011-04-23 Thread derek
Thank you very much. It was the Insert key. It was very annoying. Actually is
this owerwrite function of any use?

--
View this message in context: 
http://r.789695.n4.nabble.com/random-typing-over-text-tp3470428p3470749.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] filling array with functions

2011-04-24 Thread derek
Thats not exactly what I hoped for. But for now it has to suffice. More
transparent  syntax would be nicer.

Exactly what I would like to do is:

for (i in 1:9){
f[i]<-function(x){
a*x+b)
}
curve(f[i],  0,  8)
sol[i]<-uniroot(f[i],c(0,  8))$root
points(sol[i],0,pch=16,cex=1,col="red")
}

Perhaps is item for a wish list?

--
View this message in context: 
http://r.789695.n4.nabble.com/filling-array-with-functions-tp3468313p3471463.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] filling array with functions

2011-04-25 Thread derek
Richard,

that way I will have to write functions manually and that is not possible
for large number of functions.

derek

--
View this message in context: 
http://r.789695.n4.nabble.com/filling-array-with-functions-tp3468313p3472885.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] filling array with functions

2011-04-25 Thread derek
Still I haven't had any luck yet.
How about defining new function and its domain, is it somehow possible?
Like this:
a<-function(x) x beolongs to natural numbers <0,100>

--
View this message in context: 
http://r.789695.n4.nabble.com/filling-array-with-functions-tp3468313p3473300.html
Sent from the R help mailing list archive at Nabble.com.

__
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] How to extract smoothed plot data?

2011-08-20 Thread derek
Dear R,

I have this script which from my data points creates smoothed plot:

require(graphics)
require(stats)
A=read.table("some.txt",header =FALSE,sep = "", dec = ",",fileEncoding = "",
encoding = "unknown", skip=18,nrows=400)
attach(A)
plot(A$V1, A$V2,col="white")
lines(smooth.spline(A$V1, A$V2,spar=0.4),col="green",lwd=3)

I would like to export points coordinates from smoothed plot to file, so
that I can then use new data for further analysis. In other words to pipe
defined sequence of x coordinates and corresponding y values to file.


--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-extract-smoothed-plot-data-tp3756894p3756894.html
Sent from the R help mailing list archive at Nabble.com.

__
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] limit windows() rescale/resize options

2018-07-03 Thread Derek Ogle
I am developing an application that opens an image in a new window using, at 
times, windows(). I don't want the user to be able to resize the window (and 
distort the image). The new window contains a menu item called "resize" that 
contains three options - "R mode", "Fit to window", and "Fixed size". The 
default can be set with rescale= (i.e., rescale="fixed" for my use). However, 
the user can still select one of the other options. Is there a way to either 
remove the "Resize" menu from this window or remove the "R mode" and "Fit to 
window" options from this menu item?

Use the following, on a Windows machine, to see what I describe above.

windows(rescale="fixed")

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Evaluating an expression

2016-04-04 Thread Janszen, Derek
Hi,

I want to create a data frame similar to the following, but greatly scaled up:
df <- data.frame(aaa= c("a","b","c"), integer(3), integer(3))
names(df)[2:3] <- paste("var",1:2,sep="")
which yields
  aaa  var1  var2
1   a 0 0
2   b 0 0
3   c 0 0

I would not relish having to paste 'integer(3)' 5000 times :(

So (I figure) there must be a way to do this programmatically, something akin to
exp1 <- paste(rep("integer(3)",2),collapse=',')
which looks like it might work: "integer(3),integer(3)" , as in the 
following
df <- data.frame(aaa=xxx, eval(parse(text=exp1)))
but this yields

Error in parse(text = exp1) : :1:11: unexpected ','

1: integer(3),

  ^


Not sure just why this doesn't work (?parse does not help), but it's not 
important right now.

I have used eval and parse in the past, but not in a way similar to what I'm 
trying to do now.



exp1 <- rep("integer(3)",2) gives "integer(3)" "integer(3)"

and upon parse(text=exp1) gives expression(integer(3), integer(3))

which appears to be promising, and does not give an error in the following

df <- data.frame(aaa=xxx, eval(parse(text=exp1)))

but alas, does not give the desired result
  aaa eval.parse.text...exp1..
1   a0
2   b0
3   c0




I'm guessing that only the last evaluation of the expression is being 
evaluated, which I can understand.

I feel certain that what I want to accomplish can be done programmatically, but 
am at a loss as to just how to do that.
Chances are this has been covered before. If so, apologies.
If not, can anyone point me to references with more info than the help pages, 
or suggest a solution? :)

Thanks,
Derek

Derek Janszen, PhD
Statistician, Analytics

Precision for Medicine<http://www.precisionformedicine.com/>
8425 Progress Drive, Suite M | Frederick, MD 21701
+1 240 415 6004 office



The information contained in this email and any attachments is confidential and 
may be subject to copyright or other intellectual property protection. If you 
are not the intended recipient, you are not authorized to use or disclose this 
information, and we request that you notify us by reply mail or telephone and 
delete the original message from your mail system.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Help with shading a polygon below a segment of a curve (normaldistribution)

2008-08-28 Thread Derek Ogle
Bertolt,

The points you send to polygon() do not fully enclose the area you desire.  Try 
adding one more point as such

xt <- c(x[(length(x)-cutpoint):length(x)],linepos)
yt <- c(y[(length(y)-cutpoint):length(y)],0)
polygon(xt, yt, density = 10 )


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bertolt Meyer
Sent: Thursday, August 28, 2008 9:03 AM
To: r-help@r-project.org
Subject: [R] Help with shading a polygon below a segment of a curve 
(normaldistribution)

Dear R users,

I still feel new to R so please apologize if I am doing something stupid 
here. My use of the polygon() function produces a result that I cannot 
comprehend: In a plot, I would like to shade the area below a normal 
distribution. However, I do not want the entire area to be shaded, but 
just the area on the right side of a vertical line that I draw through 
the distribution (in order to illustrate the function of a t-test). Here 
is what I do:

scale <- 0.1
x <- seq(-4, 6, scale)
y <- dnorm(x)
plot(x, y, type = "l", main="t-Test, t = 2.2")

linepos <- 2.2
abline(v = linepos)

# I try to fill a polygon right of the vertical line:
# max(x) - linepos (in this case, 2.2) / scale (0.1)
# results in the last 38 elements of x and y.
# so I take the last 38 elements of x and y and try to
# draw a polygon underneath:

cutpoint <- (max(x) - linepos) / scale

xt <- x[(length(x)-cutpoint):length(x)]
yt <- y[(length(y)-cutpoint):length(y)]

# draw the polygon

polygon(xt, yt, density = 10 )

As you can see in the result, this is not what I want; some area above 
the line gets shaded, but not below. Can someone tell me what I am missing?

Thank you very much,
Bertolt

-- 
Bertolt Meyer
Oberassistent
Sozialpsychologie, Psychologisches Institut der Universität Zürich
Binzmühlestr. 14, Box 15
CH-8050 Zürich

[EMAIL PROTECTED]
tel:   +41446357282
fax:   +41446357279
mob:   +41788966111

__
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-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] contourLines() documentation

2009-08-26 Thread Derek Lacoursiere

Hello, 

I have searched for documentation on the function contourLines's algorithm
but cannot find a thing.  I am about to submit a paper to a journal but
cannot yet do so because I need to provide some reference for this function. 
Does anyone know what algorithm is used for this function?

Thanks,

Derek Lacoursiere
-- 
View this message in context: 
http://www.nabble.com/contourLines%28%29-documentation-tp25151467p25151467.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Converting from "date strings" to internal POSIX format?

2009-09-03 Thread Derek Eder
I need to convert a date-style string:  "2009-06-16 09:28:17.746"
To its POSIX representation: 1245137297746


The function below converts my POSIX date to a string ... now I need to go 
backwards!


render.t32 <- function(t32, tz = "CET")
  {
   timez <- ISOdatetime(1970,1,1,0,0,0, tz ="UTC")+t32/1000
   return(format(timez,"%Y-%m-%d %H:%M:%OS3",tz="CET"))
  }


> render.t32(1245137297746)
[1] "2009-06-16 09:28:17.746"


Have not succeeded in my attempts to understand POSIX
and I thank you for your attention.

~Derek


Derek N. Eder
Gothenburg University
Vigilance and Neurocognition Laboratory
Medicinaregatan 8B
Box 421
Gothenburg Sweden
SE 405 30

tlf (031) 342-8261
mobil 0704 915 714
 
"The most dangerous thing in the jungle is not the snakes, the spiders, the 
tigers, ...
The most dangerous thing in the jungle is your mind!"

__
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] How to convert numbers to words?

2009-09-14 Thread Derek Norton
I am trying to convert numbers to English words, e.g. 123 -> One
hundred twenty three.  After some searching, I have been unable to
find any info on this.  I could certainly write code to do it, but my
question is this: Does anyone know of a function that does this?

Thanks,
Derek McCrae Norton

__
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] Iteratively Reweighted Least Squares of nonlinear regression

2009-07-01 Thread Derek An
Dear all,


When doing nonlinear regression, we normally use nls if e are iid normal.

  i learned that if the form of the variance of e is not completely known,
we can use the IRWLS (Iteratively Reweighted Least Squares )

algorithm:

for example, var e*i =*g0+g1*x*1

1. Start with *w**i = *1

2. Use least squares to estimate b.

3. Use the residuals to estimate g, perhaps by regressing e^2 on *x*.

4. Recompute the weights and goto 2.

Continue until convergence

i was wondering whether there is a instruction of R to do this?

[[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] maximum/minimum value of a function

2009-07-10 Thread Derek An
Dear All,

Does anyone know how to get the maximum/minimum value of a function using R,

I think there should be an instruction, but i can not find it in help files

Thank you in advance for your help :)

[[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] re ference

2009-07-13 Thread Derek Lacoursiere

Hello R users,

I have developed code in R that generates populations of non-overlapping
random polygons ("polygonal maps") for testing certain stereological
estimation methods.  I have tried to look for articles or papers online on
the generation of random polygonal maps and have found very little.  There
seems to be a much greater concern with generating single random polygons
rather than whole maps of random polygons.  Does anyone have an idea of
where I should look or what keywords to use in my search?

I really appreciate your patience with R novices like myself.
-- 
View this message in context: 
http://www.nabble.com/reference-tp24467408p24467408.html
Sent from the R help mailing list archive at Nabble.com.

__
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] piecewise nls?

2010-04-16 Thread Derek Ogle
I am looking into fitting a so-called double von Bertalanffy function to fish 
length-at-age data.  Attempting to simplify the situation, the model looks like 
this ...

Y ~ f(X; a,b,c) if x <  Z
Y ~ g(X; a,d,e) if x >= Z

where

* f and g are non-linear functions (the "traditional" "single" von Bertalanffy 
growth function),
* Y (length) and X (age) are observed variables,
* a,b,c,d,e are parameters to be estimated, and
* Z is not a parameter but is a constant computed from b,c,d,e.

I usually fit the "traditional" "single" model with nls() but am unsure of how 
to fit this model with the "if" statement.  I tried search the archives with 
"piecewise" and either "nls", "nonlinear", or "regression" but did not find 
anything that seemed to fit this situation.  One thought I had was to do 
something like this (mostly pseudo-code) ...

nls(Y~ifelse(X=Z,1,0)*g(X;a,d,e), ...)

but am unsure if this makes sense.

If anyone can offer some help I would be very appreciative.  Thank you in 
advance.

__
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.


Re: [R] piecewise nls?

2010-04-18 Thread Derek Ogle
Christian,

Thank you for the response and hint.  This is essentially what I ended up doing 
but I ran into several problems using nls().  I have since switched to optim() 
and seem to be having better luck.  Again, thank you for your help.

> -Original Message-
> From: Christian Ritz [mailto:r...@life.ku.dk]
> Sent: Saturday, April 17, 2010 2:45 PM
> To: Derek Ogle
> Cc: r-help@r-project.org
> Subject: Re: [R] piecewise nls?
> 
> Hi Derek,
> 
> have a look at the following made-up example:
> 
> f1 <- function(x){2*x}
> f2 <- function(x){-10*x+1}
> 
> x<-rnorm(10)
> x
> (x<0)*f1(x)
> (x>=0)*f2(x)
> (x<0)*f1(x) + (x>=0)*f2(x)
> 
> 
> 
> Therefore I suggest you should specify the model as follows:
> 
> yourNLSmodel <- nls(Y ~ (X=Z) * g(X,a,d,e), data
> = myData, ...)
> 
> 
> 
> Christian

__
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.


Re: [R] data frame's column names not the same as in CSV

2009-09-28 Thread Derek Foo
Thank you all. I would like to say that it was my first time posting on the
r-help mailing list. I am very impressed and grateful that I got the answer
to my problem so quickly.

Back to the issue, using read.csv (instead of read.csv) and turning off the
check.names flag solved my problem.


Derek


On Sat, Sep 26, 2009 at 5:17 PM, Don MacQueen  wrote:

> At 1:58 AM -0400 9/26/09, Derek Foo wrote:
>
>> Hello,
>>
>> I am trying to read in a csv file with column such as
>> "\\LS01\Processor(_Total)\% Processor Time" with the command
>> read.csv("file"). However, the column name in the resulted data frame is
>> changed to "X..LS01.Processor._TotalProcessor.Time".
>>
>> Strangely,
>>
>
> Not so strange. Data can be anything, but column names are names of
> variables. In R, as in most (all? many?) computer languages, variable names
> have rules they must follow. Yours don't follow R's rules.
>
> See Gabor's response to learn how to tell R to ignore the rules (in this
> particular instance). You will find, however, that later on, when you want
> to use those variables, it will be more difficult to use variables whose
> names do not follow the rules.
>
>
>   when I experimented with just reading the csv with the "head"
>> flag set to false, the text was read correctly as the same to the raw
>> file.
>> I am wondering if anyone has encountered a similar problem. If so, I would
>> really appreciate if you can share your insight.
>>
>>
>> Best Regards,
>> Derek
>>
>>[[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.
>>
>
>
> --
> --
> Don MacQueen
> Environmental Protection Department
> Lawrence Livermore National Laboratory
> Livermore, CA, USA
> 925-423-1062
> --
>

[[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] Saving interactive modified latttice plots?

2009-11-30 Thread Derek Eder
The lattice function panel.identify() allows the labeling of mouse-selected 
plot points. 

But ... how does one save the resulting plot? E.g., to png() or pdf()

Thank you! 



# example code
library(lattice)
xyplot(rnorm(10,0,1)~rnorm(10,0,1))
trellis.focus() # left click on plot panel to select 
panel.identify() # left click on selected points.  Right click to exit process
trellis.unfocus()



Derek N. Eder
Gothenburg University

"The most dangerous thing in the jungle is not the snakes, the spiders, the 
tigers, ...
The most dangerous thing in the jungle is your mind!"

__
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] Citing R/Packages Question

2009-05-08 Thread Derek Ogle
I used R and the quantreg package in a manuscript that is currently in
the proofs stage.  I cited both R and quantreg as suggested by
citation() and noted the version of R and quantreg that I used in the
main text as

 

  "All tests were computed with the R v2.9.0 statistical programming
language (R Development Core 2008).  Quantile regressions were conducted
with the quantreg v4.27 package (Koenker 2008) for R."

 

The editor has asked me to also "provide the date when the webpage was
accessed" for both R and quantreg.

 

This does not seem like an appropriate request to me as both R and the
quantreg package are versioned.  This request seems to me to be the same
as asking someone when they purchased commercial package X version Y
(which I don't think would be asked).

 

Am I thinking about this correctly or has the editor made a valid
request?

 

I would be interested in any comments or opinions.

 

Dr. Derek H. Ogle

Associate Professor of Mathematical Sciences and Natural Resources

Northland College

1411 Ellis Avenue

Box 112

Ashland, WI 

715.682.1300

www.ncfaculty.net/dogle/

 


[[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] interactive file choosing in Linux?

2009-05-26 Thread Derek Eder
I am used to using the [R] function choose.files() for interactive file 
selection in MS-Windows.

What is the comparable function in Linux?   I expected the function 
file.choose() to display similar behavior, i.e., a graphical interface 
diplaying a file listing, but all I seem to get is a "text input prompt".   
This does not seem correct.

> file.choose()
Enter file name: 

I have seen gfile() function in the gWidgets library - but isn't there anything 
native? 

Thank you!


Derek Eder





Linux:  Ubuntu 9.04,  Gnome, [R] running in terminal or ESS GTK_Emacs (doesn't 
make any difference to the above).


> version   _  
platform   i486-pc-linux-gnu  
arch   i486   
os linux-gnu  
system i486, linux-gnu
status
major  2  
minor  8.1
year   2008   
month  12 
day    22 
svn rev    47281  
language   R  
version.string R version 2.8.1 (2008-12-22)



Derek N. Eder
Gothenburg University
Vigilance and Neurocognition Laboratory
Medicinaregatan 8B
Gothenburg Sweden
SE 405 30

tlf (031) 342-8261
mobil 0704 915 714
 

"All created things are impermanent — Strive diligently."

__
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] Error: argument is of length zero

2009-05-28 Thread Derek Lacoursiere
Hi,

I have the following:

for(j in (y.raw+1):(rownum-1)){
valsum<-tstfframed[min.x,j]+tstfframed[min.x,j+1]
if(valsum == 1){
cat("valsum loop")
int.num<-int.num+1
}

}

but I get the error message: "Error in if (valsum == 1) { : argument is of 
length zero".  I checked whether to see if all the stated variables have 
associated values (and are not NAs) and every variable (even valsum!) has a 
value.  I have no idea where my error is. Can you help me?

__
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] gpc.poly datatype

2009-06-10 Thread Derek Lacoursiere

I have a list of polygons generated by the contourLines() command (each
object of the list is a list in itself with two objects: a vector of x
values, and a vector of y values for each vertex).  I wish to convert that
list into a gpc.poly object of multiple contours.  How do I do this?  gpclib
apparently has no method of coercing lists into the gpc.poly object type.  
As well, when I have a gpc.poly object, I can view the points using the
get.pts() command, but cannot find a way of only extracting the x values of
a polygon (or the y values, for that matter).  How do I do this?
Any help would be greatly appreciated
-- 
View this message in context: 
http://www.nabble.com/gpc.poly-datatype-tp23967664p23967664.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Coefficient of determination

2009-06-16 Thread Derek An
Dear all,

Is there a instruction that can help me obtain the coefficient of
determination R^2 after doing linear/nonlinear regression using lm/nls?

[[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] driver file

2009-06-23 Thread Derek Lacoursiere

Hi,

How can I, from a single "driver" file, source other files in such a way
that I can access their functions with parameters defined in my "driver"
file?  I wish to do this to avoid creating a single, self-contained but
clunky piece of code.  I have searched and found functions such as file(),
pipe(), open(), found manuals on creating my own packages, etc. but I become
increasingly aware that I don't know exactly what I am looking for (that I
am a "neophyte").  

Help would be appreciated

Derek
-- 
View this message in context: 
http://www.nabble.com/driver-file-tp24171201p24171201.html
Sent from the R help mailing list archive at Nabble.com.

__
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] help with formula and data= argument

2009-04-04 Thread Derek Ogle
Sorry for posting this twice, but I still have not solved this problem
and am hoping for some assistance.

 

I am attempting to write a function that is flexible enough to respond
to the user providing a formula (with a data= argument) or not (similar
to plot(x,y) versus plot(y~x,data=data)).  I have found a method to work
with this in a simple case but am having trouble determining how to
"find" a variable from within the data= argument that is not part of the
formula.  The following code illustrates (I know that
plotrix::thigmophobe.labels() does what this function does) my problem
...

 

 

myplot <- function(x,y=NULL,data=NULL,label=NULL) {

  if (class(x)=="formula") {

mf <- model.frame(x,data=data)

x <- mf[,2]

y <- mf[,1]

  }

  if (is.null(y)) stop("Y-axis variable is missing")

  plot(x,y)

  if (!is.null(label)) text(x,y,label)

}

 

# dummy data

df <-
data.frame(x=runif(10),y=runif(10),grp=factor(rep(c("Yes","No"),each=5))
)

 

# both calls work as expected

with(df,myplot(x,y))

myplot(y~x,data=df)

 

# only first works as I would hope

with(df,myplot(x,y,label=grp))

myplot(y~x,data=df,label=grp)

 

# this works but is clumsy

myplot(y~x,data=df,label=df$grp)

 

 

Any help with how to make this function recognize the "grp" variable in
"df" when using the formula without having to type "df$grp" when
supplying it to the "label=" argument would be greatly appreciated.
Thank you in advance.

 

 


[[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] plotCI (plotrix) problem

2009-04-19 Thread Derek Ogle
I am attempting to create a plot with intervals "stretched" in the
x-direction using plotCI() in the plotrix package.  The same data
provides an appropriate set of intervals when "stretched" in the
y-direction but I only get a lower interval when "stretched" in the
x-direction.

 

The data are as follows

 

mns <-
c(-0.00584,-0.00458,-0.00934,-0.00969,-0.01007,0.01146,-0.00261,-0.00287
,0.00035,-0.00248,0.00084,0.01183,-0.00617,-0.00789,-0.00405,-0.01076,0.
00285,0.01464,0.01665,0.00179,-0.00038,-0.00046,0.00388,0.00501,0.00237,
-0.00488,-0.00081,-0.00432,-0.00172,0.00574,0.00853,0.00869,-0.00551,-0.
00069,0.00047)

ses <-
c(0.001552,0.001341,0.001442,0.001511,0.001794,0.001735,0.001288,0.00136
4,0.001826,0.00196,0.001037,0.9,0.00153,0.00147,0.002195,0.001189,0.
002442,0.001293,0.000803,0.001359,0.001936,0.001431,0.001962,0.002132,0.
001879,0.002846,0.003047,0.003176,0.003178,0.00328,0.001725,0.003523,0.0
03681,0.002316,0.002367)

 

This plot works as expected ...

 

require(plotrix)

plotCI(1:length(mns),mns,ses)

 

... but this one does not ...

 

plotCI(mns,1:length(mns),ses,err="x")

 

If I multiply the ses values by successively larger values then more of
the points are plotted with the upper portion of the interval, e.g., ...

 

plotCI(mns,1:length(mns),10*ses,err="x")

 

which implies that this is a scaling issue.  >From this, I suspect (am
guessing) that the issue arises somewhere in this part of the plotCI()
code ...

 

nz <- abs(li - pmax(x - gap, li)) * x.to.in > 0.001

...

nz <- abs(ui - pmin(x + gap, ui)) * y.to.in > 0.001

 

but I don't quite understand what is going on here (and elsewhere in
plotCI()) and my "guesses" at corrections did not work.  My searches on
R-help were not fruitful.

 

So, does anyone have any suggestions?  Thanks in advance for any help.

 

 

Note my session information below ...

 

> sessionInfo()

R version 2.8.0 (2008-10-20) 

i386-pc-mingw32 

 

locale:

LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

 

attached base packages:

[1] stats graphics  grDevices datasets  tcltk utils methods
base 

 

other attached packages:

[1] plotrix_2.5-4  svSocket_0.9-5 TinnR_1.0.2R2HTML_1.59
Hmisc_3.5-2   

 

loaded via a namespace (and not attached):

[1] cluster_1.11.12 grid_2.8.0  lattice_0.17-20 svMisc_0.9-5
tools_2.8.0

 

 

 


[[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.


Re: [R] Buglet in plotCI

2009-04-20 Thread Derek Ogle
Jim and Dieter,

Thank you for the quick reply and precise fix.  My plot now works as
expected.  Thanks again.


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Jim Lemon
> Sent: Monday, April 20, 2009 4:21 AM
> To: dieter.me...@menne-biomed.de; r-help@r-project.org
> Subject: Re: [R] Buglet in plotCI
> 
> Dieter Menne wrote:
> > Hi, Jim,
> >
> > there is a typo at the bottom of plotCI: there is an y.to.in which
> should be
> > x.to.in.
> >
> > See list for an example.
> >
> > http://article.gmane.org/gmane.comp.lang.r.general/147103
> >
> > Should be:
> > nz <- (abs(ui - pmin(x + gap, ui)) * x.to.in) > 0.001
> >
> > Dieter
> >
> >
> Hi Dieter,
> Thanks for the fix. I have changed the source code and it will be in
> the
> next version. For the benefit of those who can't wait:
> 
> 1) make a copy of the source code like this:
> 
> sink("newplotCI.R")
> cat("plotCI<-")
> plotCI
> sink()
> 
> 2) Open "newplotCI.R" in Your Favorite Editor.
> 
> 3) Edit line 75 as above.
> 
> 4) Save "newplotCI.R"
> 
> 5) Overwrite the plotCI function in plotrix (temporarily):
> 
> library(plotrix)
> source("newplotDI.R")
> 
> Jim
> 
> __
> 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-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] RweaveHTML (R2HTML) Help

2009-04-28 Thread Derek Ogle
I have found Sweave() to be great for producing PDF documents.  I have
been experimenting with RweaveHTML (from the R2HTML) package and have
had moderate success.  My main issue has been that I simply want the R
output to be shown verbatim in the HTML document but RweaveHTML tends to
convert most output to a table, for example.  So, is there a way to
force the RweaveHTML driver to simply provide the output of a function
exactly as it would appear in the R console window?  Thanks in advance
for any help.

 

A minimal reproducible example of my .rnw file is below ...

 





This is an example

<<>>=

data(iris)

summary(iris)

@





 

 which if I saved as test.rnw I would use ...

 

library(R2HTML)

sweave(test.rnw,driver=RweaveHTML())

 

... which will produce test.html which looks like ...

 



 



This is an example





> data(iris)

 

> summary(iris)

 









  
Sepal.Length Sepal.Width Petal.Length
Petal.Width  Species 

 Min.   :4.300
Min.   :2.000  Min.
:1.000  Min.   :0.100  setosa:50  

 1st Qu.:5.100
1st Qu.:2.800  1st
Qu.:1.600  1st Qu.:0.300  versicolor:50  

 Median :5.800
Median :3.000  Median :4.350  Median :1.300
virginica :50  

 Mean   :5.843
Mean   :3.057  Mean
:3.758  Mean   :1.199  NA 

 3rd Qu.:6.400
3rd Qu.:3.300  3rd
Qu.:5.100  3rd Qu.:1.800  NA 

 Max.   :7.900
Max.   :4.400  Max.
:6.900  Max.   :2.500  NA 

 





 

 

 



 





 

 

 

Session Info

R version 2.8.0 (2008-10-20) 

i386-pc-mingw32 

 

locale:

LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

 

attached base packages:

[1] stats graphics  grDevices datasets  tcltk utils methods
base 

 

other attached packages:

 [1] pda_1.2-3  MASS_7.2-46lme4_0.999375-28
Matrix_0.999375-22 lattice_0.17-20car_1.2-12 NCStats_0.1-1


 [8] sciplot_1.0-4  plotrix_2.5-4  nortest_1.0
svSocket_0.9-5 TinnR_1.0.2R2HTML_1.59Hmisc_3.5-2


 

loaded via a namespace (and not attached):

[1] cluster_1.11.12   gdata_2.4.2   gplots_2.6.0  grid_2.8.0
gtools_2.5.0-1svMisc_0.9-5  TeachingDemos_2.3 tools_2.8.0  

 


[[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] Suppress getOptions() in Stangle

2010-01-06 Thread Derek Ogle
Hello,

I am creating PDF handouts using Sweave for a beginner's R workshop.  I want to 
include the R code for the handout in an appendix as described (using the 
listings LaTeX package) as described in ...

http://n4.nabble.com/including-Sweave-tangled-code-in-Rnw-document-tp875112p875112.html

Whenever a graphic is created in this code the resulting Stangle code precedes 
the plotting code with a getOptions() call.  For example, this code in my RNW 
file ...

<>=
plot(logWT~logTL,data=dA)
@
\includegraphics[width=3in]{Figs/reg1-transLW}
produces the following lines in the Stangle "code" file


getOption("SweaveHooks")[["fig"]]()

plot(logWT~logTL,data=dA)



In hopes of getting the cleanest code possible for this beginner class I was 
wondering if anyone knew of a way to suppress the getOptions() code in the 
Stangle results.



Thanks in advance for any help.

__
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.


Re: [R] Inappropriate color name

2020-11-17 Thread Derek Ogle
I agree with, support, and appreciate this message. Thank you Ryan for the 
courage to write this, and Lainey for your courage to persist with your 
question.

-Original Message-
From: R-help  On Behalf Of Ryan Novosielski
Sent: Tuesday, November 17, 2020 9:40 AM
To: r-help mailing list 
Cc: Lainey Gallenberg 
Subject: Re: [R] Inappropriate color name

*** [EXTERNAL EMAIL] https://www.northland.edu/about/external-email";>What does this mean? 
***

> On Nov 16, 2020, at 5:46 PM, Rolf Turner  wrote:
> 
> On Tue, 17 Nov 2020 07:54:01 +1100
> Jim Lemon  wrote:
> 
>> Hi Elaine,
>> There seems to be a popular contest to discover offence everywhere. I 
>> don't think that it does anything against racism, sexism or 
>> antidisestablishmentarianism. Words are plucked from our vast lexicon 
>> to comfort or insult our fellows depending upon the intent of the 
>> user. It is the intent that matters, not the poor word. Chasing the 
>> words wastes your time, blames those who use the words harmlessly, 
>> and gives the real offender time to find another epithet.
> 
> Jim:  This is superbly expressed.  I wish that I could have said that! 
> Your posting should go down in the annals of brilliant rhetoric, 
> alongside Dr. Johnson's "Letter to Lord Chesterfield".
> 
> cheers,
> 
> Rolf

You know, I wouldn’t have continued this thread (which has now wandered off 
topic from the original somewhat-more-technical question), but I feel now like 
it’s necessary to do so (and only fair, if anyone is considering moderating me 
after letting these posts by):

That is a view commonly held by white people, and even more overwhelmingly by 
white men. Our field is already not as diverse as it should be for a variety of 
reasons, and this “pretending no one else on earth exists” kind of stuff is at 
least some part of the reason. The question at issue here aside, white men 
complaining about people finding racism or sexism everywhere they look doesn’t 
pass the sniff test. Most or all of these things that people are reporting as 
offensive are being reported by people you’re clearly not listening to.

Further, impact is what matters. If I step on your foot, I apologize, 
regardless of whether or not it was intentional, because it’s the right thing 
to do. If someone tells you “that thing you’re saying is offensive or is 
hurting me” and you say “I didn’t mean it,” and then keep right on doing it, 
what does it say to the person on the receiving end of it? All anyone that is 
being “blamed,” as you put it, is being asked to do is to try to do better next 
time. 

--
#BlackLivesMatter

|| \\UTGERS, |---*O*---
||_// the State  | Ryan Novosielski - novos...@rutgers.edu
|| \\ University | Sr. Technologist - 973/972.0922 (2x0922) ~*~ RBHS Campus
||  \\of NJ  | Office of Advanced Research Computing - MSB C630, Newark
 `'

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] RGB -> CYMK, with consistent colors

2020-11-29 Thread Derek Jones

All,

I used the very useful colorspace package for the plots in my book
(pdf available here): http://knosof.co.uk/ESEUR/

The color makes the plots look great, on screen.
To get lots printed, the printer requires converting the images to use cmyk
(a common requirement for larger  printers, I'm told).  See page 11 here:
https://www.ingramspark.com/hubfs/downloads/file-creation-guide.pdf

No problem, the script below uses ghostscript to achieve this:

gs -o ESEUR-cmyk.pdf \
-sDEVICE=pdfwrite \
-sProcessColorModel=DeviceCMYK \
-sColorConversionStrategy=CMYK \
-sColorConversionStrategyForImages=CMYK \
 ESEUR.pdf

the problem is that the converted colors don't look nearly as
good.  For instance the cyan now looks blue, and prints as pure blue.

I can regenerate the images, and explicitly specify cmyk.  But using:

pdf.options(colormodel="cymk")

does not change anything.  The colors look remarkably similar to
those produced via the ghostview route.

I have been looking at color profiles and trying to find a
way of modifying an ICC profile (yes, it looks difficult).

Does anybody have any ideas for producing cmyk images that have
the same (or close enough) look as the RGB?

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] RGB -> CYMK, with consistent colors

2020-11-29 Thread Derek Jones

Martin,


Have you tried printed a few pages in CMYK?

A monitor is based on mixing light using Red-Green-Blue. So it is not
possible for the monitor to show
CMYK which must be printed on paper to view correctly.


Yes, I have printed some 'CMYK' pages.

The blue is very obviously not cyan, as compared to printing the
RGB version.


Let me correct the last sentence.
The printed blue is obviously not cyan when printing 'rgb' and 'cmyk'
pages.

Somebody pointed out in an email that probably I am the only one who
is going to notice the difference, and he may be right.

My frustration is that the printer supports cyan as a base color.
I understand that rgb->cmyk involves lots of variables, and I'm hoping
that somebody will point me at one that allows me to tweak the output.

library("colorspace")

two_c=rainbow(2)

x=runif(20)
y=runif(20)

plot(x, y, col=two_c[2])


pdf(file="cmyk.pdf", colormodel="cmyk")
plot(x, y, col=two_c[2])
dev.off()

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] RGB -> CYMK, with consistent colors

2020-11-30 Thread Derek Jones

Martin,


However after some testing.
I totally agree that CMYK handling in R using pdf(..., colormodel = "cmyk")
is not correct.


I thought the issue may be OS specific, but I get similar behavior on a Mac.

I have discovered the Cyan tool: http://cyan.fxarena.net/
and will try it out.

As various people have pointed out, RGB -> CMYK conversion is never going
to be perfect.  It just so happens that my book contains many plots that use
red and cyan, and a good conversion to cyan is most of what I am after.

> One solution:
> Output in tiff or png instead and then convert to CMYK using external tools.

There are 600+ figures.  There are png versions here:
http://knosof.co.uk/ESEUR/figures/index.html

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] RGB -> CYMK, with consistent colors

2020-12-02 Thread Derek Jones

Martin,


However after some testing.
I totally agree that CMYK handling in R using pdf(..., colormodel = "cmyk")
is not correct.


Looking at the source code of the function PostScriptSetCol
in file src/librarygrDevices/src/devPS.c
the conversion to CMYK looks correct.

Looking at the generated pdf (qpdf: https://github.com/qpdf/qpdf is
needed to uncompress the pdf)
the numeric color values look correct, although the pdf contents don't exactly
match those generated by PostScriptSetCol

It is possible the problem is in the conversion that occurs when
displaying/printing a pdf.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] bgroup not rendering properly

2022-12-12 Thread Derek Ogle
bgroup() from plotmath does not render properly for me. For example

plot(0,xlim=c(0,1),ylim=c(0,1))
text(0.3,0.5,expression(bgroup('(',atop(x,y),')')))
text(0.7,0.5,expression(group('(',atop(x,y),')')))

and

library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
  annotate("text", x=2.5, y=25, label="bgroup('(',atop(x,y),')')",
parse=TRUE) +
  annotate("text", x=3.5, y=25, label="group('(',atop(x,y),')')",
parse=TRUE)

both show a proper (though ugly) result from group() (the second text() or
annotation()) but unrecognizable characters (rather than large parentheses)
from bgroup().

This problematic result occurred for me when using v4.2.2, but not when
using 4.2.0, 4.1.2, 4.1.0, or 4.0.5. My sessionInfo is further below.

I did ask this on stackoverflow

where the resulting figures can be seen.



R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_4.2.2 tools_4.2.2

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] bgroup not rendering properly

2022-12-13 Thread Derek Ogle
Thank you all for your help. I am using Windows. I ran the following both
in R 4.2.2 using RStudio and not using RStudio (but using the R GUI). In
both runs, plots within the GUI/RStudio and in the PNG output exhibited the
same issue that I reported originally., whereas plots in the PDF output
were perfect (no issue).

As asked, the first dev.cur() or .Device says "null device" whereas the
second says "Windows" when using the R GUI and "RStudioGD" when using
RStudio.

It sounds like this is likely a windows-related bug that will be fixed in
the next version. I can wait for that.


dev.cur()
.Device
plot(0,xlim=c(0,1),ylim=c(0,1))
text(0.5,0.5,expression(bgroup('(',atop(x,y),')')))

png("bgroup_R422.png")
plot(0,xlim=c(0,1),ylim=c(0,1))
text(0.5,0.5,expression(bgroup('(',atop(x,y),')')))
dev.off()

pdf("bgroup_R422.pdf")
plot(0,xlim=c(0,1),ylim=c(0,1))
text(0.5,0.5,expression(bgroup('(',atop(x,y),')')))
dev.off()

dev.cur()
.Device
plot(0,xlim=c(0,1),ylim=c(0,1))
text(0.5,0.5,expression(bgroup('(',atop(x,y),')')))


On Tue, Dec 13, 2022 at 5:48 AM Jinsong Zhao  wrote:

>
>
> On 2022/12/13 18:02, Martin Maechler wrote:
> >>>>>> Jinsong Zhao
> >>>>>>  on Tue, 13 Dec 2022 17:07:00 +0800 writes:
> >  > I don
> >
> >  >  On 2022/12/13 10:13, Derek Ogle wrote:
> >  >> bgroup() from plotmath does not render properly for
> >  >> me. For example
> >  >>
> >  >> plot(0,xlim=c(0,1),ylim=c(0,1))
> >  >> text(0.3,0.5,expression(bgroup('(',atop(x,y),')')))
> >  >> text(0.7,0.5,expression(group('(',atop(x,y),')')))
> >
> > Almost surely a  Windows-only problem i.e. bug,
> > See also the bug fixed yesterday, PR#18440,
> > https://bugs.r-project.org/show_bug.cgi?id=18440
> >
> >
> I do not observe the problem in that bug report. All works fine.
>
> Best,
> Jinsong
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] coplot question

2013-02-06 Thread derek@nemac

In R I have 3 variables x,y and z that contain:

| x  y   z
[1,]  1  12  122
[2,]  1  13  113
[3,]  1  11  111
[4,]  3  13  123
[5,]  4  14  134
[6,]  5  15  155|

I am creating a coplot with the following syntax:

|given.depth<-  co.intervals(z,  number=3,  overlap=.1)
coplot(x~y|z,pch=19,col="red",cex=1.5,given.values=given.depth)|

The resulting plot however has has bars in the conditional variable that 
don't cover all of the values of x and y at x=4, 7=14, and z=134


Thanks,
Derek

<>__
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.


Re: [R] coplot question

2013-02-07 Thread derek@nemac

Hi José

Yes indeed that does help.

Thanks,
Derek
On 2/7/2013 5:01 AM, Jose Iparraguirre wrote:

Hi, Derek,

Try and modify the value for the overlap argument.
Hope this helps,

José


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of derek@nemac
Sent: 07 February 2013 03:49
To: r-help@r-project.org
Subject: [R] coplot question

In R I have 3 variables x,y and z that contain:

| x  y   z
[1,]  1  12  122
[2,]  1  13  113
[3,]  1  11  111
[4,]  3  13  123
[5,]  4  14  134
[6,]  5  15  155|

I am creating a coplot with the following syntax:

|given.depth<-  co.intervals(z,  number=3,  overlap=.1)
coplot(x~y|z,pch=19,col="red",cex=1.5,given.values=given.depth)|

The resulting plot however has has bars in the conditional variable that don't 
cover all of the values of x and y at x=4, 7=14, and z=134

Thanks,
Derek

Wrap Up and Run 10k is back!

Also, new for 2013 – 2km intergenerational walks at selected venues. So recruit 
a buddy, dust off the trainers and beat the winter blues by
signing up now:

http://www.ageuk.org.uk/10k

  Milton Keynes | Oxford | Sheffield | Crystal Palace | Exeter 
| Harewood House, Leeds |
  Tatton Park, Cheshire | Southampton | Coventry



Age UK Improving later life

http://www.ageuk.org.uk


  


---
Age UK is a registered charity and company limited by guarantee, (registered 
charity number 1128267, registered company number 6825798).
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

For the purposes of promoting Age UK Insurance, Age UK is an Appointed 
Representative of Age UK Enterprises Limited, Age UK is an Introducer
Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth 
Access for the purposes of introducing potential annuity and health
cash plans customers respectively.  Age UK Enterprises Limited, JLT Benefit 
Solutions Limited and Simplyhealth Access are all authorised and
regulated by the Financial Services Authority.
--

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are
addressed. If you receive a message in error, please advise the sender and 
delete immediately.

Except where this email is sent in the usual course of our business, any 
opinions expressed in this email are those of the author and do not
necessarily reflect the opinions of Age UK or its subsidiaries and associated 
companies. Age UK monitors all e-mail transmissions passing
through its network and may block or modify mails which are deemed to be 
unsuitable.

Age Concern England (charity number 261794) and Help the Aged (charity number 
272786) and their trading and other associated companies merged
on 1st April 2009.  Together they have formed the Age UK Group, dedicated to 
improving the lives of people in later life.  The three national
Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help 
the Aged in these nations to form three registered charities:
Age Scotland, Age NI, Age Cymru.












__
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] Need help with installing gplots

2013-06-12 Thread Derek Serianni
Hi,

I am new to linux so please bear with me.

OS is CentOS 5.9  - This cannot be changed

I am following a guide given to me to setup a server.

I am told to do the following:

To Install R:

sudo yum install gcc
sudo yum install make
sudo yum install telnet
sudo rpm -Uvh
http://download.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
sudo yum install  R

sudo R CMD INSTALL ~/APX.X.X/Rserve_0.6-2.tar.gz
This does not work  what should I be doing here?


sudo R

install.packages("gplots")
--- This is where I run into problems.   When I run this, I am presented
with the message:  gplot is not available for R version 2.15.2
--- How can I get a version of gplot that will work with R version 2.15.2
--- I am okay with going to another version of R if this will help



install.packages("chron")

install.packages("party")

install.packages("RColorBrewer")

q("default",1,TRUE) to exit




If anyone could help me I would really appreciate it.


Thanks,

D.


-- 
--
The Original Soylent Geek - It's Nerds!

[[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.


Re: [R] Need help with installing gplots

2013-06-13 Thread Derek Serianni
Thank you for the reply,   I appreciate it very much.

I have the following responses:

sudo R CMD INSTALL ~/APX.X.X/Rserve_0.6-2.tar.gz

Explaining what 'does not work' means.

When I type this in.  It says that the package is not found.   Can you
guide me as to what I need to do here?


What version of gplots will work with version 2.15.2 from the archive at
http://cran.r-project.org/src/contrib/Archive/gplots/


On 13 June 2013 03:19, Prof Brian Ripley  wrote:

> On 13/06/2013 05:09, Derek Serianni wrote:
>
>> Hi,
>>
>> I am new to linux so please bear with me.
>>
>> OS is CentOS 5.9  - This cannot be changed
>>
>> I am following a guide given to me to setup a server.
>>
>> I am told to do the following:
>>
>> To Install R:
>>
>> sudo yum install gcc
>> sudo yum install make
>> sudo yum install telnet
>> sudo rpm -Uvh
>> http://download.fedoraproject.**org/pub/epel/5/x86_64/epel-**
>> release-5-4.noarch.rpm<http://download.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm>
>> sudo yum install  R
>>
>> sudo R CMD INSTALL ~/APX.X.X/Rserve_0.6-2.tar.gz
>> This does not work  what should I be doing here?
>>
>
> Explaining what 'does not work' means.  Why do you need Rserve: very few
> other packages rely on it?
>
>
>>
>> sudo R
>>
>> install.packages("gplots")
>> --- This is where I run into problems.   When I run this, I am presented
>> with the message:  gplot is not available for R version 2.15.2
>> --- How can I get a version of gplot that will work with R version 2.15.2
>>
>
> From the archive at http://cran.r-project.org/src/**
> contrib/Archive/gplots/<http://cran.r-project.org/src/contrib/Archive/gplots/>(assuming
>  you mean 'gplots').
>
>  --- I am okay with going to another version of R if this will help
>>
>
> That is what the posting guide asked you to do.
>
>
>>
>>
>> install.packages("chron")
>>
>> install.packages("party")
>>
>> install.packages("**RColorBrewer")
>>
>> q("default",1,TRUE) to exit
>>
>>
>>
>>
>> If anyone could help me I would really appreciate it.
>>
>>
>> Thanks,
>>
>> D.
>>
>>
>>
>
> --
> Brian D. Ripley,  rip...@stats.ox.ac.uk
> Professor of Applied Statistics,  
> http://www.stats.ox.ac.uk/~**ripley/<http://www.stats.ox.ac.uk/~ripley/>
> University of Oxford, Tel:  +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UKFax:  +44 1865 272595
>



-- 
--
The Original Soylent Geek - It's Nerds!

[[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] optim() not finding optimal values

2010-06-26 Thread Derek Ogle
I am trying to use optim() to minimize a sum-of-squared deviations function 
based upon four parameters.  The basic function is defined as ...

SPsse <- function(par,B,CPE,SSE.only=TRUE)  {
  n <- length(B) # get number of years of data
  B0 <- par["B0"]# isolate B0 parameter
  K <- par["K"]  # isolate K parameter
  q <- par["q"]  # isolate q parameter
  r <- par["r"]  # isolate r parameter
  predB <- numeric(n)
  predB[1] <- B0
  for (i in 2:n) predB[i] <- predB[i-1]+r*predB[i-1]*(1-predB[i-1]/K)-B[i-1]
  predCPE <- q*predB
  sse <- sum((CPE-predCPE)^2)
  if (SSE.only) sse
else list(sse=sse,predB=predB,predCPE=predCPE)
}

My call to optim() looks like this

# the data
d <- data.frame(catch= 
c(9,113300,155860,181128,198584,198395,139040,109969,71896,59314,62300,65343,76990,88606,118016,108250,108674),
 
cpe=c(109.1,112.4,110.5,99.1,84.5,95.7,74.1,70.2,63.1,66.4,60.5,89.9,117.0,93.0,116.6,90.0,105.1))

pars <- c(80,100,0.0001,0.17)   # put all parameters 
into one vector
names(pars) <- c("B0","K","q","r")  # name the parameters
( SPoptim <- optim(pars,SPsse,B=d$catch,CPE=d$cpe) )# run optim()


This produces parameter estimates, however, that are not at the minimum value 
of the SPsse function.  For example, these parameter estimates produce a 
smaller SPsse,

parsbox <- c(732506,1160771,0.0001484,0.4049)
names(parsbox) <- c("B0","K","q","r")
( res2 <- SPsse(parsbox,d$catch,d$cpe,SSE.only=FALSE) )

Setting the starting values near the parameters shown in parsbox even resulted 
in a movement away from (to a larger SSE) those parameter values.

( SPoptim2 <- optim(parsbox,SPsse,B=d$catch,CPE=d$cpe) )# run optim()


This "issue" most likely has to do with my lack of understanding of 
optimization routines but I'm thinking that it may have to do with the 
optimization method used, tolerance levels in the optim algorithm, or the shape 
of the surface being minimized.

Ultimately I was hoping to provide an alternative method to fisheries 
biologists who use Excel's solver routine.

If anyone can offer any help or insight into my problem here I would be greatly 
appreciative.  Thank you in advance.

__
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.


Re: [R] optim() not finding optimal values

2010-06-27 Thread Derek Ogle
Ravi,

Thank you very much for the pointer to parscale.  This is extremely useful -- 
in this and some other problems that I am working on.  Thanks again for the 
valuable help.

> -Original Message-
> From: Ravi Varadhan [mailto:rvarad...@jhmi.edu]
> Sent: Saturday, June 26, 2010 11:52 PM
> To: Ravi Varadhan
> Cc: Derek Ogle; R (r-help@R-project.org)
> Subject: Re: [R] optim() not finding optimal values
> 
> A slightly better scaling is the following:
> 
> par.scale <- c(1.e06, 1.e06, 1.e-05, 1)  # "q" is scaled differently
> 
> > SPoptim <- optim(pars, SPsse, B=d$catch, CPE=d$cpe,
> control=list(maxit=1500, parscale=par.scale))
> > SPoptim
> $par
>   B0Kqr
> 7.320899e+05 1.159939e+06 1.485560e-04 4.051735e-01
> 
> $value
> [1] 1619.482
> 
> $counts
> function gradient
>  585   NA
> 
> $convergence
> [1] 0
> 
> $message
> NULL
> 
> 
> Note that the Nelder-Mead converges in half the number of iterations
> compared to that under previous scaling.
> 
> Ravi.
> 
> 
> Ravi Varadhan, Ph.D.
> Assistant Professor,
> Division of Geriatric Medicine and Gerontology
> School of Medicine
> Johns Hopkins University
> 
> Ph. (410) 502-2619
> email: rvarad...@jhmi.edu
> 
> 
> - Original Message -
> From: Ravi Varadhan 
> Date: Sunday, June 27, 2010 0:42 am
> Subject: Re: [R] optim() not finding optimal values
> To: Derek Ogle 
> Cc: "R (r-help@R-project.org)" 
> 
> 
> > Derek,
> >
> >  The problem is that your function is poorly scaled.   You can see
> > that the parameters vary over 10 orders of magnitude (from 1e-04 to
> > 1e06).   You can get good convergence once you properly scale your
> > function.  Here is how you do it:
> >
> >  par.scale <- c(1.e06, 1.e06, 1.e-06, 1.0)
> >
> >  SPoptim <- optim(pars, SPsse, B=d$catch, CPE=d$cpe,
> > control=list(maxit=1500, parscale=par.scale))
> >
> >  > SPoptim
> >  $par
> >B0Kqr
> >  7.329553e+05 1.160097e+06 1.484375e-04 4.050476e-01
> >
> >  $value
> >  [1] 1619.487
> >
> >  $counts
> >  function gradient
> >  1401   NA
> >
> >  $convergence
> >  [1] 0
> >
> >  $message
> >  NULL
> >
> >
> >  Hope this helps,
> >  Ravi.
> >
> >  
> >
> >  Ravi Varadhan, Ph.D.
> >  Assistant Professor,
> >  Division of Geriatric Medicine and Gerontology
> >  School of Medicine
> >  Johns Hopkins University
> >
> >  Ph. (410) 502-2619
> >  email: rvarad...@jhmi.edu
> >
> >
> >  - Original Message -
> >  From: Derek Ogle 
> >  Date: Saturday, June 26, 2010 4:28 pm
> >  Subject: [R] optim() not finding optimal values
> >  To: "R (r-help@R-project.org)" 
> >
> >
> >  > I am trying to use optim() to minimize a sum-of-squared deviations
> >
> >  > function based upon four parameters.  The basic function is
> defined
> > as
> >  > ...
> >  >
> >  >  SPsse <- function(par,B,CPE,SSE.only=TRUE)  {
> >  >n <- length(B) # get number of
> years
> > of
> >  > data
> >  >B0 <- par["B0"]# isolate B0
> parameter
> >  >K <- par["K"]  # isolate K
> parameter
> >  >q <- par["q"]  # isolate q
> parameter
> >  >r <- par["r"]  # isolate r
> parameter
> >  >predB <- numeric(n)
> >  >predB[1] <- B0
> >  >for (i in 2:n) predB[i] <- predB[i-1]+r*predB[i-1]*(1-predB[i-
> 1]/K)-B[i-1]
> >  >predCPE <- q*predB
> >  >sse <- sum((CPE-predCPE)^2)
> >  >if (SSE.only) sse
> >  >  else list(sse=sse,predB=predB,predCPE=predCPE)
> >  >  }
> >  >
> >  >  My call to optim() looks like this
> >  >
> >  >  # the data
> >  >  d <- data.frame(catch=
> >  >
> >
> c(9,113300,155860,181128,198584,198395,139040,109969,71896,59314,62
> 300,65343,76990,88606,118016,108250,108674),
> >
> >  >
> cpe=c(109.1,112.4,110.5,99.1,84.5,95.7,74.1,70.2,63.1,66.4,60.5,89.9,11
> 7.0,93.0,116.6,90.0,105.1))
&

Re: [R] when all I have is a contingency table....

2010-07-07 Thread Derek Ogle
A.Z.,

You could recreate the data (I assumed that the values are discrete integers 
and not a bin for a continuous variable) ...

value <- 1:6
count <- c(10,8,12,9,14,7)
d <- rep(value,count)
table(d)

... and then do what you want with the data in the d vector ...

summary(d)
hist(d)



> On 07-Jul-10 20:39:32, Andrei Zorine wrote:
> > Hello,
> > I just need a hint here:
> > Suppose I have no raw data, but only a frequency table I have, and I
> > want to run basic statistical procedures with it, like histogram,
> > descriptive statistics, etc. How do I do this with R?
> > For example, how do I plot a histogram for this table for a sample of
> > size 60?
> >
> > Value   Count
> > 1   10
> > 2   8
> > 3   12
> > 4   9
> > 5   14
> > 6   7
> >
> > Thanks,
> > A.Z.

__
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] Repeating values in a list

2010-09-18 Thread Derek Ogle
I have a list that looks like this ...

> have <- list(a=7,b=3,c=1)
> have
$a
[1] 7

$b
[1] 3

$c
[1] 1

and I want to have a simple way to change it to the following without re-typing 
the values ...

> desire <- list(a=c(7,7),b=c(3,3),c=c(1,1))
> desire
$a
[1] 7 7

$b
[1] 3 3

$c
[1] 1 1

In other words, I need to create the list in desire from the list in have.

In my "real" work the number of items in the list may be more than three and 
the number of times to repeat the numbers may be greater than two.

Thank you in advance for any help you can offer.

__
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.


Re: [R] Repeating values in a list

2010-09-18 Thread Derek Ogle
Thanks to Dennis for solving my first question and also pointing me in the 
right direction.

To complete the thread ... there are times when I need to have different 
numbers of repeats for each object in the list.  This can be accomplished with 
mapply() as follows ...

> mapply(rep,x=have,c(1,1,2))
$a
[1] 7

$b
[1] 3

$c
[1] 1 1





From: Dennis Murphy [mailto:djmu...@gmail.com] 
Sent: Saturday, September 18, 2010 8:25 PM
To: Derek Ogle
Cc: R (r-help@R-project.org)
Subject: Re: [R] Repeating values in a list

Hi:

How about

> have <- list(a=7,b=3,c=1)
> lapply(have, rep, 2)
$a
[1] 7 7

$b
[1] 3 3

$c
[1] 1 1


HTH,
Dennis
On Sat, Sep 18, 2010 at 6:19 PM, Derek Ogle  wrote:
I have a list that looks like this ...

> have <- list(a=7,b=3,c=1)
> have
$a
[1] 7

$b
[1] 3

$c
[1] 1

and I want to have a simple way to change it to the following without re-typing 
the values ...

> desire <- list(a=c(7,7),b=c(3,3),c=c(1,1))
> desire
$a
[1] 7 7

$b
[1] 3 3

$c
[1] 1 1

In other words, I need to create the list in desire from the list in have.

In my "real" work the number of items in the list may be more than three and 
the number of times to repeat the numbers may be greater than two.

Thank you in advance for any help you can offer.

__
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-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.


Re: [R] fitting model to resampled data

2010-09-29 Thread Derek Ogle
Mike,

Without completely knowing your end game with these questions and this 
procedure it does seem like you are "re-inventing the wheel" here.  If that is 
true and given the nls() fit that you are using I would suggest that you look 
at boot.case() in the alr3 package or nlsBoot() in the nlstools package.  I 
have used both of those functions with success when fitting the von Bertalanffy 
growth model to fish length-age data.

Some general help for fitting von Bertalanffy growth models to fish data can be 
found at

http://www.ncfaculty.net/dogle/fishR/gnrlex/gnrlex.html



> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Michael Larkin
> Sent: Wednesday, September 29, 2010 2:57 PM
> To: r-help@r-project.org
> Subject: [R] fitting model to resampled data
> 
> I apologize if this comes across as confusing.  I will try to explain
> my
> situation as best I can.
> 
> 
> 
> I have R bootstrapping my growth data for fish.  It's resampling my
> database
> of age and length data and then produces several new datasets for me.
> In
> this case, it's resampling my data to create three new datasets of age
> and
> length data.  Here is my code with my original data called growth:
> 
> 
> 
> replicate(3, growth[sample(9,12,replace=T),], simplify = FALSE)
> 
> 
> 
> This is working very well.
> 
> 
> 
> Now, the problem that I am now stuck with is incorporating a growth
> model
> into the three new datasets to estimate growth parameters.  Since there
> are
> now three new datasets I want to get three new estimates of the growth
> parameters, essentially one from each new dataset.
> 
> 
> 
> I am using the von Bertalanffy growth model.  Here is my code:
> 
> 
> 
> par<-list(Linf=700, K=0.20, to=-0.1)
> #these are the starting values for parameters
> 
> vb<-nls(Length~Linf*(1-exp(-K*(Age-to))), start=par, data=???)
> #this is
> the growth model  with the parameters estimated with non linear least
> 
> squares (nls)
> 
> 
> 
> I tried placing my resampling function the data part of the nls
> function but
> it asks me for parameter estimates.
> 
> 
> 
> Any advice would be greatly appreciated.
> 
> 
> 
> Mike
> 
> 
> 
> 
>   [[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-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] Error: cannot allocate vector of size x Gb (64-bit ... yet again)

2010-11-23 Thread derek eder

Hello,

I am facing the dreaded "Error: cannot allocate vector of size x Gb" and 
don't understand
enough about R (or operating system) memory management to diagnose and 
solve the problem

-- despite studying previous posts and relevant R help -- e.g.:

"Error messages beginning cannot allocate vector of size indicate a 
failure to obtain memory,
either because the size exceeded the address-space limit for a process 
or, more likely,

because the system was unable to provide the memory.
[...] On all builds of R, the maximum length (number of elements)
of a vector is 2^31 - 1 ~ 2*10^9, as lengths are stored as signed integers.
In addition, the storage space cannot exceed the address limit."
- from Memory-limits {Base}


Simple question:  Given 64-bit R (AMD64 Linux) with a ulimit of 
"unlimited", can the size of an R object exceed the amount of availlable RAM

memory?

Empirically my system with 4Gb RAM and ample Swap, is failing:

>  x <- integer(10^9)

> object.size(x)
400040 bytes

> gc()
used   (Mb) gc trigger   (Mb)  max used   (Mb)
Ncells1211956.5 35   18.735   18.7
Vcells 500124024 3815.7  606849099 4629.9 550124408 4197.2

> matrix(x, ncol=16)
Error: cannot allocate vector of size 3.7 Gb

I don't understand how this operation violates the limits detailed in 
the Memory-limit help (above).


Thank you!


Derek Eder



-

> version
   _
platform   x86_64-pc-linux-gnu
arch   x86_64
os linux-gnu
system x86_64, linux-gnu
status
major  2
minor  11.1
year   2010
month  05
day31
svn rev52157
language   R
version.string R version 2.11.1 (2010-05-31)



de...@papanca:~$ top

top - 09:10:18 up 51 min,  4 users,  load average: 0.51, 0.51, 0.45
Tasks: 160 total,   2 running, 158 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us, 25.0%sy,  0.0%ni, 75.0%id,  0.0%wa,  0.0%hi,  0.0%si,  
0.0%st

Mem:   3796484k total,  3764852k used,31632k free,14204k buffers
Swap:  2929660k total,   834240k used,  2095420k free,94800k cached

  PID USER  PR  NI  VIRT  RES  SHR S %CPU %MEMTIME+ COMMAND
 2854 derek 20   0  239m 9260 5448 S6  0.2   0:05.53 
gnome-terminal

 1164 root  20   0  218m  31m  10m S4  0.8   1:29.71 Xorg
 3331 derek 20   0 19276 1324  944 R1  0.0   0:00.6  top

__
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] Function to Define a Function

2010-08-09 Thread Derek Ogle
I am trying to define a general R function that has a function as the output 
that depends on the user's input arguments (this may make more sense by looking 
at the toy example below).  My real use for this type of code is to allow a 
user to choose from many parameterizations of the same general model.

My "issue" is that when I compile a package with this type of code in it I get 
a __warning__ that "multiple local function definitions for 'm' with different 
formal arguments."  While this is not a "deadly error" I would like to avoid 
the warning if possible.  Can someone provide some guidance?  Thank you in 
advance for any help you can offer.

For what it is worth ... I am working on a Windows XP machine with R 2.11.1.




## A function that allows the user to create a new function that depends on 
their
##   choice in the type argument.  As a simple example, if the user chooses 
"one"
##   then the output function is exponential growth, if the user choses "two" 
then
##   thhe output function is logistic growth.

mdlChooser <- function(type=c("one","two")) {
  type <- match.arg(type)
  switch(type,
one={ m <- function(x,N0,r) N0*exp(x*r) },
two={ m <- function(x,N0,r,K) (N0*K)/(N0+(K-N0)*exp(-x*r)) },
  )
  m
}

## define time steps
t <- 0:10

## create a function -- junk1 -- that produces exponential growth
junk1 <- mdlChooser("one")
junk1
res1 <- junk1(t,500,0.2)
res1

## create a function -- junk2 -- that produces logistic growth
junk2 <- mdlChooser("two")
junk2
res2 <- junk2(t,500,0.2,1000)
res2



[[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.


Re: [R] Function to Define a Function

2010-08-10 Thread Derek Ogle
Gabor ... that worked perfectly.  Thank you.

> -Original Message-
> From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com]
> Sent: Monday, August 09, 2010 10:20 PM
> To: Derek Ogle
> Cc: R (r-help@R-project.org)
> Subject: Re: [R] Function to Define a Function
> 
> On Mon, Aug 9, 2010 at 9:31 PM, Derek Ogle  wrote:
> > I am trying to define a general R function that has a function as the
> output that depends on the user's input arguments (this may make more
> sense by looking at the toy example below).  My real use for this type
> of code is to allow a user to choose from many parameterizations of the
> same general model.
> >
> > My "issue" is that when I compile a package with this type of code in
> it I get a __warning__ that "multiple local function definitions for
> 'm' with different formal arguments."  While this is not a "deadly
> error" I would like to avoid the warning if possible.  Can someone
> provide some guidance?  Thank you in advance for any help you can
> offer.
> >
> > For what it is worth ... I am working on a Windows XP machine with R
> 2.11.1.
> >
> >
> >
> >
> > ## A function that allows the user to create a new function that
> depends on their
> > ##   choice in the type argument.  As a simple example, if the user
> chooses "one"
> > ##   then the output function is exponential growth, if the user
> choses "two" then
> > ##   thhe output function is logistic growth.
> >
> > mdlChooser <- function(type=c("one","two")) {
> >  type <- match.arg(type)
> >  switch(type,
> >    one={ m <- function(x,N0,r) N0*exp(x*r) },
> >    two={ m <- function(x,N0,r,K) (N0*K)/(N0+(K-N0)*exp(-x*r)) },
> >  )
> >  m
> > }
> >
> > ## define time steps
> > t <- 0:10
> >
> > ## create a function -- junk1 -- that produces exponential growth
> > junk1 <- mdlChooser("one")
> > junk1
> > res1 <- junk1(t,500,0.2)
> > res1
> >
> > ## create a function -- junk2 -- that produces logistic growth
> > junk2 <- mdlChooser("two")
> > junk2
> > res2 <- junk2(t,500,0.2,1000)
> > res2
> >
> 
> 
> Try this:
> 
> mdlChooser <- function(type = c("one", "two")) {
>one <- function(x,N0,r) N0*exp(x*r)
>two <- function(x,N0,r,K) (N0*K)/(N0+(K-N0)*exp(-x*r))
>type <- match.arg(type)
>get(type)
> }

__
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.


Re: [R] Linear regression on several groups

2010-08-13 Thread Derek Ogle
Have a look at lmList() in the nlme package.

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of JesperHybel
> Sent: Friday, August 13, 2010 7:56 AM
> To: r-help@r-project.org
> Subject: Re: [R] Linear regression on several groups
> 
> 
> Example is spot on - sr for not providing one myself.
> The results you calculate are what I'm looking for.
> 
> Would like a function F where I could type:
> 
> F(weight ~ Time, data = ChickWeight, SOME ARGUMENT = Diet))
> 
> Resulting in
> 
> for (i in 1:4){
> print(
> 
> lm(weight ~ Time, data = ChickWeight, subset = Diet==i)
> 
> )
> }
> 
> I'm simply trying to minimize amount of looping and typing etc.
> 
> BR Jesper
> 
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Linear-
> regression-on-several-groups-tp2322835p2324154.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> 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-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.


Re: [R] Equality of Vectors

2010-08-13 Thread Derek Ogle
Patrick,

See all().  For example,

> all(c(1,2,3)==c(1,2,3))
[1] TRUE
> all(c(1,2,3)==c(2,1,3))
[1] FALSE


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Downey, Patrick
> Sent: Friday, August 13, 2010 1:49 PM
> To: r-help@r-project.org
> Subject: [R] Equality of Vectors
> 
> Hello,
> 
> Is there a way to get a single TRUE or FALSE statement from comparing
> two
> vectors? For example,
> c(1,2,3) == c(1,2,3)
> produces
> TRUE TRUE TRUE
> 
> where I would like it to produce only
> TRUE
> for use in an if statement.
> 
> Likewise, when two vectors are not exactly identical (in all elements)
> I
> would like a single FALSE result, as opposed to
> c(1,2,3) == c(1,2,5)
> TRUE TRUE FALSE
> 
> Any ideas?
> 
> Thanks,
> Mitch
> 
> __
> 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-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] Help Preparing Data for Heatmap creation

2010-05-19 Thread Derek Dees
All -

Below are samples of the data, a description of my approach and the
work I've done so far. My goal is two-fold, first learn more about R
and the creation of heatmaps; second, to create a heat map where the
vertical access is a series of days and the horizontal is the hour of
a day with the color of the cells being determined by the number of
texts in that hour. While the project doesn't have a lot of general
applicability to anything really significant for my job, I'm curious
about the distribution of texts sent by myself, my wife and my
children. So, a project that can scratch two itches with one stick.

My general approach is to:

0: Read in the data from the file downloaded from my cell phone
provider into a 6 column variable.
1: Add a 7th column combining the Date and Time columns, formatted as
a POSIXct value.
2: Create a data frame with 5 columns - day, hour, number sent, number
received, total number
4: Create the heatmap using the first two columns plus whichever of
the remaining 3 I'm interested in at the moment.

The issues I'm currently having revolve around creating the data frame
to hold the information that I will use for the heatmap. I cannot seem
to get round or round.POSIXt to properly round to the date hour
format, and I'm not sure I'm understanding working with POSIXct data.
I also am floundering on how to sum sent/received counts by hour. Not
having a statistics background and being an R newbie, I suspect I'm
asking the wrong questions in the documentation.

Any suggestions regarding how to achieve my aims or points to useful
material beyond "Learning R" and the R man pages would be appreciated
greatly.

I'm using R 2.10.1 on Windows XP.

The code I'm using is:

#!/usr/bin/R
# rdf:
# dc:title textingHeatMap.R
# dc:date 2010.05.14
# dc:creator http://www.mm.com/user/djdees/knows/who#derek-dees
# dc:language R
# dc:rights Copyright ©
# dc:description Creates a heatmap showing # of texts per hour per day.
# doap:SVNRepository
# doap:browse
# doap:homepage
# doap:wiki
# doap:program-language
# doap:version 1.0
# cvs:date $Date$

# Libraries/Packages

# Functions

# Setup
file <- "\\tmp\\R\\UnbilledMessaging.action"

# Read Data
rawData <- read.csv(file, header=TRUE, sep="\t",quote="\"")

# Work Data
rawData$time.stamp <- paste(rawData$Date, rawData$Time)
rawData$time.stamp <- as.POSIXct(rawData$time.stamp, format="%m/%d/%Y %I:%M %p")
format(rawData$time.stamp, "%m/%d/%Y %I")

# Plot

=
Sanitized data looks like:
"Date"  "Time"  "To""From"  "Direction" "Message Type"
"05/03/2010""9:49 AM"   "0123456789""0123456789""Sent"  "--"
"05/03/2010""9:46 AM"   "0123456789""0123456789"
"Received"  "--"

-- 
Derek
=
djd...@gmail.com

The three-legged stool of understanding is held up by history,
languages, and mathematics. Equipped with these three you can learn
anything you want to learn. But if you lack any one of them you are
just another ignorant peasant with dung on your boots. — Robert A.
Heinlein

__
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] calculating "treatment effects" (differences) in a data frame?

2010-05-24 Thread derek eder
I am trying to  calculating the treatment effect for individual subjects 
("ID")

of a ("score") between 2 time-points ("visit") (see example below).

The data is in an unbalanced data.frame in "long" format with some 
missing data.


I suspect that I am overlooking a very simple function, something along 
the lines of

tapply().

Thank you for you attention!


Derek Eder



##  Examples:

myData = data.frame(
  ID = c("a","a","b","c","c","d","d"),
  visit=c(1,2,1,1,2,1,2),
  score=c(10,2,12,16,0,NA,5)
  )

> myData
  ID visit score
1  a 110
2  a 2 2
3  b 112
4  c 116
5  c 2 0
6  d 1NA
7  d 2 5

# The desired result is a vector of time differences by ID
#  a  b  c  d
#  8  NA 16 NA



##  solutions ?

# This works, but the returned data frame is awkward for me
# because the "empty cells" (b and d) contain integer(0)
# and not the more familiar NA.

> aggregate(data=myData, score~ID,FUN=diff)
  ID score
1  a-8
2  b
3  c   -16
4  d


# This works as desired ... but somehow seems unecessarily complicated

> reshape(data=myData,timevar="visit",idvar="ID", direction="wide")
  ID score.1 score.2
1  a  10   2
3  b  12  NA
4  c  16   0
6  d  NA   5

> apply(X = reshape(data=myData,timevar="visit",idvar="ID", 
direction="wide")[,-1],

  MARGIN = 1, FUN = diff)

  1   3   4   6
 -8  NA -16  NA

__
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] Finding Imported Packages

2011-03-20 Thread Derek Ogle
Is there a function similar to pkgDepends() that returns the packages that a 
particular package imports or imports from?  I believe I can get this 
information from the matrix returned from installed.packages() but something 
like pkgDepends() would be more convenient.

I did not find anything useful in my search of the R-help archives (my search 
string may have been poorly chosen), my use of ??import, or my (hoped for) use 
of ?pkgImports.

Thank you in advance for any help you can offer.

p.s., For what it is worth I am using Windows and R version 12.2-1.

[[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] Biplot - how can I make it more readable?

2012-06-18 Thread Derek . Schanze
Hello,
I am doing a principle component analysis on a dataset with a lot of 
different variables and have constructed a biplot of the data. 
 Unfortunately, as can be seen on the attached image, the biplot is very 
messy, cluttered, and hard to read.  I have performed a few modifications 
including outlier removal from a few of the variables, which has made the 
plot better, however it still is too cluttered to read the variable names. 
 Is there any further improvment that can be made to the attached plot and 
if so what steps should I take? 

Thanks, 
Derek 


__
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.


Re: [R] Graph digitisation / tracing

2012-01-28 Thread Derek Ogle
I have successfully used the digitize package for this purpose ...

http://cran.r-project.org/web/packages/digitize/index.html


 wrote:
>
> I want to take some published graphs and digitise them to allow me to 
> run some analysis on them.
> Is this possible using any of R's
> plugins. I don't think it is but I never cease to be amazed at what R 
> can do and it'd be great if it was as it would almost certainly be 
> more powerful than doing it in one of the web programmes that can do it

__
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] Distribution Graph Idea/Help

2008-04-18 Thread Derek Ogle

For pedagogical reasons (i.e., moving a way from tables of distributions) I 
want to plot a probability density or distribution function with a shaded area 
corresponding to the calculated value or user input.  For example, I want a 
plot to visually demonstrate the result of 

pnorm(1.3)

I have seen the interactive examples in TeachingDemos and rPanel but am 
interested in using the function from the "command line" rather than from a 
"GUI".  I have generated code to construct this type of graph, but my question 
is now how best to implement it.  My initial solution was to add a plot=TRUE 
argument to pnorm() but that requires altering a base function and I now think 
that this is not a good idea (although it worked nicely from the student's 
perspective).  Thus, I have considered three new options ...

1) making a new function called something like pnorm1() which would return what 
pnorm() returns but also would construct the graphic.  This implementation 
would be simple given the function that I have already made but it feels clumsy 
and inelegant.
2) creating a generic plot() function that would take, for example, an object 
returned from pnorm().  However, this does not seem immediately possible as, it 
appears to me, that pnorm() just returns a numeric.
3) creating a general function that would take the name of a distribution, type 
of calculation ("p" or "q" type), value of interest (x value or probability), 
and distribution parameters as arguments and then call the specific 
distribution functions and my graphing function to produce the results.  I 
would likely implement this just for distributions that I use regularly in my 
classes.

Has anybody already implemented a solution to this idea?  Does anyone have a 
suggestion on which of my three options above is best for this code?  Better 
ideas?

Thanks in advance for any help.

__
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] R-Forge vs. RForge

2008-04-22 Thread Derek Ogle

I have two packages that I use locally and have been curious about moving them 
to "R Forge" to take advantage of SVN, builds, etc.  In looking into this I 
stumbled across two different sites.  The apparent official "R Forge" site at 
http://r-forge.r-project.org/ and a seemingly "unofficial" site at 
http://www.rforge.net/ .  Does anyone have any comments of comparison between 
these two "R Forge" versions or any comments about "R Forge"ing in general.  
Your help is appreciated.  Thanks in advance.

__
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] Ordered Multidimensional Arrays

2008-12-23 Thread Derek Schaeffer
Hi,
I am inquiring as to what are the best practices with respect to storing and
manipulating ordered multi-dimensional arrays.  For example, suppose I have
a sequence of time-varying covariance matrices of asset returns.  The data
is ordered, but the ordering is not necessarily regular (e.g. daily data
omitting weekends and holidays, etc.).  The data array is say, N x N x T.
For example, the first two elements may look as follows:

> *result$covariance[,,1:2]
, , 1*
* [,1] [,2] [,3] [,4]
[1,] 1.511137e-06 1.918668e-06 1.201553e-06 3.205271e-06
[2,] 1.918668e-06 7.488916e-06 6.593317e-06 1.203421e-05
[3,] 1.201553e-06 6.593317e-06 1.305861e-05 2.132272e-05
[4,] 3.205271e-06 1.203421e-05 2.132272e-05 4.571225e-05*
*, , 2*
* [,1] [,2] [,3] [,4]
[1,] 1.500858e-06 1.905574e-06 1.193412e-06 3.183290e-06
[2,] 1.905574e-06 7.444871e-06 6.555459e-06 1.195876e-05
[3,] 1.193412e-06 6.555459e-06 1.297075e-05 2.11e-05
[4,] 3.183290e-06 1.195876e-05 2.11e-05 4.551706e-05*

I would like to be able to partition this sequence of matrices by date and
by individual element.  Partitioning by individual elements is trivial;
however, partitioning by time stamp is not (especially if the partitioned
data set must be carried through a number of downstream calculations).  I
could carry the data in a list complete with a date vector and the data
array, and partition the list as I go, but this seems somewhat clunky.  Any
ideas?  A "zoo"-like package capable of handling multidimensional arrays
would be optimal, but I don't believe this exists.

Thanks,
Derek

[[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] Table Modification

2009-01-23 Thread Derek Ogle
I am trying to construct a two-way table where, instead of printing the
two-way frequencies in the table, I would like to print the values of a
third variable that correspond to the frequencies.

 

For example, the following is easily constructed in R

 

> fact1 <- factor(sample(LETTERS[1:3],10,replace=TRUE))

> fact2 <- factor(sample(LETTERS[25:26],10,replace=TRUE))

> fact3 <- letters[1:10]

> data.frame(fact1,fact2,fact3)

   fact1 fact2 fact3

1  C Z a

2  A Y b

3  A Y c

4  C Z d

5  A Z e

6  A Y f

7  B Y g

8  B Y h

9  C Z i

10 A Y j

> table(fact1,fact2)

 fact2

fact1 Y Z

A 4 1

B 2 0

C 0 3

 

But I would like to create something like this (done physically by hand)
...

 

 fact2

fact1Y   Z

A b,c,f,je

B   g,h  -

C- a,d,i

 

Any help would be appreciated.  Thank you in advance.

 

For what it is worth,

 

> Sys.info()

 sysname 

   "Windows" 

 release 

"XP" 

 version 

"build 2600, Service Pack 2"


[[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.


Re: [R] Table Modification

2009-01-23 Thread Derek Ogle
Yes, that was exactly what I was looking for.  Very concise.  Thank you.

My "real" example has many more items in each cell.  I will now have to
figure out how to put a "carriage return" after, say, every fourth item.

Nevertheless, thank you very much for the quick and accurate answer.

-Original Message-
From: r...@quantide.com [mailto:r...@quantide.com] 
Sent: Friday, January 23, 2009 9:25 AM
To: Derek Ogle
Cc: r-h...@stat.math.ethz.ch
Subject: Re: [R] Table Modification

If I understood propelly

 > tapply(fact3, list(fact1, fact2) , paste, collapse = ",")

A.

__
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.


Re: [R] batch process file in R

2009-03-12 Thread Derek Norton
If these are the only files in the directory, then you might try...
(File paths will need to change if the folder "200209" isn't in the
working directory)

fpath <- "./200209"
a <- list.files(fpath)
for(i in 1:length(a)){
 assign(paste("y",i,sep=""),read.table(paste(fpath,a[i],sep="/")))
}

Another option is to put them in a list...

for(i in 1:length(a)){
 y[[i]] <- read.table(paste(fpath,a[i],sep="/")
}

or with lapply...

y <- lapply(1:length(a), function(i) read.table(paste(fpath,a
[i],sep="/"))

Hope this helps.

Cheers,
Derek

On Mar 12, 7:52 am, tedzzx  wrote:
> Dear R experts,
>
> I have a folder names "200209" and in this folder there are many data files,
> such as:
> "BA020902.txt","BA020903.txt","BA020904.txt",
> "BA020905.txt","BA020906.txt","BA020909.txt",
> "BA020910.txt","BA020911.txt","BA020912.txt",
> "BA020913.txt","BA020916.txt","BA020917.txt",
> "BA020918.txt","BA020919.txt","BA020920.txt",
> "BA020923.txt","BA020924.txt","BA020925.txt",
> "BA020926.txt","BA020927.txt","BA020930.txt",
> "GMAS0209.txt","MAST0209.txt"
>
> I want to imort all these data files into R at once without typing tedious
> a<-read.table("BA020902.txt"),
> b<-read.table("BA020903.txt").
>
> Thanks
>
> Ted
>
> --
> View this message in 
> context:http://www.nabble.com/batch-process-file-in-R-tp22474751p22474751.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
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] NLS -- multiplicative errors and group comparison

2008-02-26 Thread Derek Ogle
Hello,

 

I am attempting to fit a non-linear model (Von Bertalanffy growth model)
to fish length-at-age data with the purpose of determining if any of the
three parameters differ between male and female fish.  I believe that I
can successfully accomplish this goal assuming an additive error
structure (illustrated in section 1 below).  My trouble begins when I
attempt this analysis using a model with a multiplicative error
structure.  I believe that I can fit the multiplicative error model to
data without attempting to test between males and females (section 2
below), but I am not sure how to declare the model formula if I want to
test between males and females (section 3 below).  In addition, I
assumed what I did in section 2 was correct, separated the data into a
dataframe of males and a dataframe of females, and then attempted to fit
separate models to each group (Section 4).  This was "successful" for
males but not for females.  The problem with the female group appears to
be that my "logging" creates NaN cells.  When I put a trace on the nls
function it appears to do one iteration and then fails.  My assumption
is that the nls function must be attempting different parameter
estimates that return a NaN but I cannot test this as I'm not sure how
to see the new parameters that it is trying.  [I tried different
starting values but did not find any that corrected this problem.]

 

So (1) how do I declare the model formula for using multiplicative
errors (i.e., is what I did in Section 2 correct), (2) how do I declare
the model formula for comparing two groups and using multiplicative
errors, and (3) any suggestions for how to find the "issue" leading to
the error for just the female model in section 4.

 

Sys.info information is in Section 4 and I am using R 2.6.1.  I have not
included the data as it is a rather large file.

 

Thank you very much for reading this long message and for any help that
you can offer.

 

 

 

### Section 1 ###

> library(xlsReadWrite)

> fwd <- read.xls("FWDrum_SDF.xls",sheet=1)

> fwd$Gm <- fwd$Gf <- rep(0,length(fwd$age))

> fwd$Gf[fwd$sex=="female"] <- 1

> fwd$Gm[fwd$sex=="male"] <- 1

> str(fwd)

'data.frame':   719 obs. of  5 variables:

 $ age: num  1.27 2.25 2.25 2.25 2.25 ...

 $ tl : num  226 208 226 226 234 ...

 $ sex: Factor w/ 2 levels "female","male": 1 1 1 1 1 1 1 1 1 1 ...

 $ Gf : num  1 1 1 1 1 1 1 1 1 1 ...

 $ Gm : num  0 0 0 0 0 0 0 0 0 0 ...

 

# starting values

> sLinf <- 405

> sK <- 0.11

> sto <- -5.2

> svb <- list(Linf=sLinf,K=sK,to=sto)

 

# Fit the additive error structure model to both groups combined

> vbla <- nls(tl~Linf*(1-exp(-K*(age-to))),start=svb,data=fwd)

> summary(vbl1)

 

Formula: tl ~ Linf * (1 - exp(-K * (age - to)))

 

Parameters:

   Estimate Std. Error t value Pr(>|t|)

Linf 520.751048  19.560552  26.623  < 2e-16 ***

K  0.061097   0.008506   7.183 1.72e-12 ***

to-6.950346   1.112839  -6.246 7.24e-10 ***

---

Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

 

Residual standard error: 83.75 on 716 degrees of freedom

 

Number of iterations to convergence: 9 

Achieved convergence tolerance: 7.525e-06 

 

# Fit the additive error structure model to the separate groups

#  compare this to vbla to see if any parameters differ (fit other
models to see which parameter)

> vbla.gen<- nls(tl~Gf*Linff*(1-exp(-Kf*(age-tof))) +
Gm*Linfm*(1-exp(-Km*(age-tom))),

+
start=list(Linff=sLinf,Kf=sK,tof=sto,Linfm=sLinf,Km=sK,tom=sto),data=fwd
)

> summary(vbla.gen)

 

Formula: tl ~ Gf * Linff * (1 - exp(-Kf * (age - tof))) + Gm * Linfm * 

(1 - exp(-Km * (age - tom)))

 

Parameters:

Estimate Std. Error t value Pr(>|t|)

Linff 692.719734  47.191732  14.679  < 2e-16 ***

Kf  0.038532   0.006469   5.957 4.04e-09 ***

tof-7.589941   1.235644  -6.142 1.35e-09 ***

Linfm 372.224132  13.268491  28.053  < 2e-16 ***

Km  0.095814   0.024983   3.835 0.000137 ***

tom-8.058334   2.445654  -3.295 0.001033 ** 

---

Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

 

Residual standard error: 68.15 on 713 degrees of freedom

 

Number of iterations to convergence: 8 

Achieved convergence tolerance: 6.589e-06

 

 

 

### Section 2 ###

> vblm <- nls(log(tl)~log(Linf*(1-exp(-K*(age-to,start=svb,data=fwd)

> summary(vblm)

 

Formula: log(tl) ~ log(Linf * (1 - exp(-K * (age - to

 

Parameters:

   Estimate Std. Error t value Pr(>|t|)

Linf 515.414166  21.239627  24.267  < 2e-16 ***

K  0.055431   0.007486   7.404 3.71e-13 ***

to-8.289902   1.002402  -8.270 6.51e-16 ***

---

Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

 

Residual standard error: 0.1907 on 716 degrees of freedom

 

Number of iterations to convergence: 8 

Achieved convergence tolerance: 2.236e-06

 

 

### Section 3 ###

# FIRST TRY -- Fit the multiplicative error structure model to the
separate groups

> vblm.gen1<- nls(log(tl)~log(Gf*Linff*(1-exp(-Kf

[R] seq() question

2007-09-28 Thread Derek Ogle
Hello all,

I am attempting to use the seq() function to define breaks for the cut() 
function but am finding performance that I do not understand.  The root of my 
problem appears to be contained in the following simple example.

> brks <- seq(0.8,1.2,0.1)
> brks
[1] 0.8 0.9 1.0 1.1 1.2
> brks==1.2
[1] FALSE FALSE FALSE FALSE FALSE
> brks==1.1
[1] FALSE FALSE FALSE  TRUE FALSE

The last value in the sequence does not appear to be equal to its apparent 
value (i.e., 1.2) whereas the fourth value in the sequence, for example, does 
(e.g., 1.1).

Any help/suggestions with the concept or "trick" that I am missing here?  Thank 
you in advance.

p.s., I am using R 2.5.1 with ...

> Sys.info()
  sysname   release 
"Windows"  "NT 5.1" 
  version  nodename 
"(build 2600) Service Pack 2"  "CSE229-001" 
  machine
"x86"

__
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] memory.limit

2009-04-21 Thread Derek Stephen Elmerick
I ran the memory limit function in R 2.9.0 and received the 'error'
below. The memory appears to update correctly, so there's probably no
implication beyond cosmetic; however, thought I would make sure since the
function as written did not generate the same error in my 2.8.0 version of
R.

Thanks


> memory.limit(size=4095)
Error in trunc(.Internal(memory.size(size))) :
  Non-numeric argument to mathematical function
> memory.limit()
[1] 4095
>

 

[[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.


Re: [R] memory.limit

2009-04-27 Thread Derek Stephen Elmerick
Hello --

So, independently of any other code, the memory limit error I referenced is
not a problem. The issue I am running into now is that our analytics
group must go back to all existing code and comment out the memory limit
reference [See my example below]. I'm sure there is a quick fix. If anyone
has ideas, I would appreciate it.

Thanks

>
> for (k in 1:3)
+ {
+cat("hello world","\n")
+ }
hello world
hello world
hello world
>
>
> for (k in 1:10)
+ {
+memory.limit(size=4095)
+cat("hello world","\n")
+ }
Error in trunc(.Internal(memory.size(size))) :
  Non-numeric argument to mathematical function
>



On Wed, Apr 22, 2009 at 4:33 PM, Francisco J. Zagmutt <
gerifalt...@hotmail.com> wrote:

> Hello Stephen,
>
> I can confirm that I get the same behavior in my Windows machine.  Here is
> a summary:
>
> > memory.limit()
> [1] 2046
> > memory.limit(2092)
> Error in trunc(.Internal(memory.size(size))) :
>  Non-numeric argument to mathematical function
> > memory.limit()
> [1] 2092
>
> As you described, the function reports an error but it indeed modified the
> memory allocation limit.  This must be somehow related to the modification
> to memory.limit() described in the release notes for Windows R version 2.9.0
> (http://cran.r-project.org/bin/windows/base/CHANGES.R-2.9.0)
>
> > version
>   _
> platform   i386-pc-mingw32
> arch   i386
> os mingw32
> system i386, mingw32
> status
> major  2
> minor  9.0
> year   2009
> month  04
> day17
> svn rev48333
> language   R
> version.string R version 2.9.0 (2009-04-17)
>
> All: is this a bug or are we missing something?
>
> Regards,
>
> Francisco
>
> __
> Francisco J. Zagmutt
> Vose Consulting
> 2891 20th Street
> Boulder, CO, 80304
> USA
> franci...@voseconsulting.com
> www.voseconsulting.com
>
> Derek Stephen Elmerick wrote:
>
>>  I ran the memory limit function in R 2.9.0 and received the 'error'
>> below. The memory appears to update correctly, so there's probably no
>> implication beyond cosmetic; however, thought I would make sure since the
>> function as written did not generate the same error in my 2.8.0 version of
>> R.
>>
>> Thanks
>>
>>
>> memory.limit(size=4095)
>>>
>> Error in trunc(.Internal(memory.size(size))) :
>>  Non-numeric argument to mathematical function
>>
>>> memory.limit()
>>>
>> [1] 4095
>>
>>  
>>
>>[[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<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>

[[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.


Re: [R] RGB -> CYMK, with consistent colors

2020-11-29 Thread Derek M Jones

Martin,


Have you tried printed a few pages in CMYK?

A monitor is based on mixing light using Red-Green-Blue. So it is not
possible for the monitor to show
CMYK which must be printed on paper to view correctly.


Yes, I have printed some 'CMYK' pages.

The blue is very obviously not cyan, as compared to printing the
RGB version.

--
Derek M. Jones   Evidence-based software engineering
tel: +44 (0)1252 520667  blog:shape-of-code.coding-guidelines.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Multivariate binary response analysis

2010-12-13 Thread Janszen, Derek B
Greetings ~

I need some assistance determining an appropriate approach to analyzing 
multivariate binary response data, and how to do it in R.

The setting: Data from an assay, wherein 6-hours-post-fertilization zebrafish 
embryos (n=20, say) are exposed in a vial to a chemical (replicated 3 times, 
say), and 5 days later observed for the presence/absence (1/0) of defects in 
several organ systems (yolk sac, jaw, snout, body axis, pericardial edema, 
etc.) for each fish. The assay can be used as a screen (in which case a single 
response 'any' is first analyzed) as well as for comparing the responses of 
different classes of chemicals (a MANOVA-type analysis). Interest is focused on 
where response(s) are occurring, any associations among responses, and 
ultimately on possible biological mechanisms (the fish are tested for 
behavioral activity prior to this assay, and then ground up to provide RNA for 
microarray assays. A-lotta-data!).

What I *wish* I could do is something like glm(response.matrix ~ treat/vial, 
family=binomial(logit), data=zf.dat) but I know this can't be done. I came 
across the baymvb (Bayesian analysis of multivariate binary data) package in 
the R contributed packages archives, but it is no longer supported and the 
author is incommunicado. In the baymvb function the model is specified as 
single.stacked.response ~ structure.factor + linear.model.terms. Huh? This 
looks suspiciously similar to analyzing repeated measures data in SAS as a 
univariate response with a split-plot structure (which forces the response 
covariance matrix to have a compound symmetric structure). If this is what's 
happening with this function it is definitely not appropriate. How about a GEE 
approach (I'm not familiar with the literature, or with any of the R packages 
that implement it)? Any other recommendations? (NB: just discovered the bayesm 
package. Don't know if this will work for me or not.)

Any help would be greatly appreciated.
Derek Janszen, PhD
Sr Research Biostatistician
Computational Biology & Bioinformatics
Pacific Northwest National Laboratory
Richland, WA  99352 USA
derek.jans...@pnl.gov



[[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] log y 'axis' of histogram

2010-08-29 Thread Derek M Jones

All,

I have been trying to get calls to hist(...) to be plotted
with the y-axis having a log scale.

I have tried: par(ylog=TRUE)

I have also looked at the histogram package.

Suggestions welcome.

--
Derek M. Jones tel: +44 (0) 1252 520 667
Knowledge Software Ltd mailto:de...@knosof.co.uk
Source code analysis   http://www.knosof.co.uk

__
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.


Re: [R] log y 'axis' of histogram

2010-08-30 Thread Derek M Jones

Hadley,


It's not just that counts might be zero, but also that the base of
each bar starts at zero. I really don't see how logging the y/axis of
a histogram makes sense.


I have counts ranging over 4-6 orders of magnitude with peaks
occurring at various 'magic' values.  Using a log scale for the
y-axis enables the smaller peaks, which would otherwise
be almost invisible bumps along the x-axis, to be seen

The references given for logHist in David Scott's DistributionUtils
package are:

Barndorff-Nielsen, O. (1977) Exponentially decreasing distributions for 
the logarithm of particle size, Proc. Roy. Soc. Lond., A353, 401–419.


Barndorff-Nielsen, O. and Blæsild, P (1983). Hyperbolic distributions. 
In Encyclopedia of Statistical Sciences, eds., Johnson, N. L., Kotz, S. 
and Read, C. B., Vol. 3, pp. 700–707. New York: Wiley.


Fieller, N. J., Flenley, E. C. and Olbricht, W. (1992) Statistics of 
particle size data. Appl. Statist., 41, 127–146.




Hadley

On Sunday, August 29, 2010, Joshua Wiley  wrote:

Hi Derek,

Here is an option using the package ggplot2:

library(ggplot2)
x<- sample(x = 10:50, size = 50, replace = TRUE)
qplot(x = x, geom = "histogram") + scale_y_log()

However, the log scale is often inappropriate for histograms, because
the y-axis represents counts, which could potentially be 0, and
therefore undefined (R outputs -Inf).  Another option using base
graphics would be something along the lines (no pun intended) of:

temp<- hist(x, plot = FALSE) #get histogram data
plot(x = temp$mids, y = log(temp$counts), type = "h")

HTH,

Josh

On Sun, Aug 29, 2010 at 6:58 PM, Derek M Jones  wrote:

All,

I have been trying to get calls to hist(...) to be plotted
with the y-axis having a log scale.

I have tried: par(ylog=TRUE)

I have also looked at the histogram package.

Suggestions welcome.

--
Derek M. Jones tel: +44 (0) 1252 520 667
Knowledge Software Ltd mailto:de...@knosof.co.uk
Source code analysis   http://www.knosof.co.uk

__
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.





--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
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.





--
Derek M. Jones tel: +44 (0) 1252 520 667
Knowledge Software Ltd mailto:de...@knosof.co.uk
Source code analysis   http://www.knosof.co.uk

__
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.


Re: [R] log y 'axis' of histogram

2010-08-30 Thread Derek M Jones

Hadley,


I have counts ranging over 4-6 orders of magnitude with peaks
occurring at various 'magic' values.  Using a log scale for the
y-axis enables the smaller peaks, which would otherwise
be almost invisible bumps along the x-axis, to be seen


That doesn't justify the use of a _histogram_  - and regardless of


The usage highlights meaningful characteristics of the data.
What better justification for any method of analysis and display is
there?


what distributional display you use, logging the counts imposes some
pretty heavy restrictions on the shape of the distribution (e.g. that
it must not drop to zero).


Does there have to be a recognized statistical distribution to use R?
In my case I am using R for all of the analysis and graphics in a
new book.  This means that sometimes I have to deal with data sets
that are more or less a jumble of numbers with patterns in a few
places.  For instance, the numeric value of integer constants
appearing as one operand of the binary bitwise-AND operator (see
figure 1224.1 of www.knosof.co.uk/cbook/usefigtab.pdf, raw data
at: www.knosof.co.uk/cbook/bandcons.hist.gz)

qplot(band, binwidth=8, geom="histogram") + scale_y_log()
does a good job of highlighting the peaks.


It may be useful for your purposes, but that doesn't necessarily make
it a meaningful graphic.


Doesn't being useful for my purpose make it meaningful, at least for me
and I hope my readers?

--
Derek M. Jones tel: +44 (0) 1252 520 667
Knowledge Software Ltd mailto:de...@knosof.co.uk
Source code analysis   http://www.knosof.co.uk

__
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.


Re: [R] log y 'axis' of histogram

2010-08-30 Thread Derek M Jones

Hadley,


That you're displaying something that is mathematically well founded
and meaningful - but my emphasis there was on histogram.  I don't
think a histogram makes sense, but there are other ways of displaying
the same data that would (e.g. a frequency polygon, or maybe a density
plot)


The problem I have with geom = "freqpoly" is that it is not immediately
obvious to the casual reader of the figure that binned data has been
plotted.  The horizontal line at the top of each bar does make that
obvious.  Lots of solid black is an eye sore and using something
like fill="white" helps to solve this problem (although this
currently appears red for me, probably some configuration issue to
sort out).

I'm not sure that a histogram using variable width bins and one log
scale has any meaningful interpretation; having both axis use a log
scale might make sense with variable width bins.


what distributional display you use, logging the counts imposes some
pretty heavy restrictions on the shape of the distribution (e.g. that
it must not drop to zero).


Does there have to be a recognized statistical distribution to use R?


My point is about the display - if your binned counts look like 1,
100, 1000, 100, 0, 0, 10, 1000, 1000, how do you display the log
counts?


Many functions cannot handle log(0) so the safest thing to do is
remove 0s.  What about 1 and other values more than X orders of
magnitude less than the maximum?  This is an issue on any log scaled
plot and invariably they don't appear (and neither do the log(0)
cases).

Having a scale that gets closer to zero without ever getting there
is something that has to be accepted when displaying a log scale.

Logarithms are familiar to a technical readership and using them for
data spanning several orders of magnitude can highlight meaningful
relationships.  A non-technical readership is likely to completely
misunderstand a log scale and I have no idea how to display this
kind of data to such people.


I couldn't find that figure, but I'd think geom = "freqpoly" would be
more appropriate.  (I'd also suggest adding a bit more space between
the data and the margins in your figures - they overlap in many
plots).


My mistake, I as looking at a very old printed copy.  See figure 1234.1
These figures are from a previous book
www.knosof.co.uk/cbook
which used grap to draw all the graphs
www.lunabase.org/~faber/Vault/software/grap/
with the numbers being extracted and processed by various C programs and
awk scripts.

--
Derek M. Jones tel: +44 (0) 1252 520 667
Knowledge Software Ltd mailto:de...@knosof.co.uk
Source code analysis   http://www.knosof.co.uk

__
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.