Re: [R] Circular variables within a GLM, GLM-GEE or GAM

2011-01-21 Thread Clare Embling
Hi Simon,

Thanks for that!  Yes the circular variable is a predictor variable - great 
that it can be done using GAMs.
I actually would like to do a GAM-GEE model - do you know if I can do this 
within R yet?  I'm using GLM-GEEs because I can't do GAM-GEEs (I have data 
collected over the same survey route repeatedly over time, so want to take into 
account the fact that my data are not independent - I'm modelling my 
correlation structure using an ar-1 autoregressive correlation structure within 
a GEE). That way too, I can include my circular variables with circular 
smoothing functions as you suggested.

Best wishes & thanks,
Clare


From: Simon Wood [s.w...@bath.ac.uk]
Sent: 18 January 2011 17:58
To: r-help@r-project.org
Cc: Clare Embling
Subject: Re: [R] Circular variables within a GLM, GLM-GEE or GAM

Is the variable to be used as a predictor? If so mgcv::gam has a couple of
circular smoother built in...

s(x,bs="cc") or s(x,bs="cp")

(if the range of x is less than the full  [0, 360] then you can supply a
`knots' argument to gam to force the x range to go from 0 to 360, otherwise
s(min(x), bs="c*") will be identical to s(max(x),bs="c*"), which may not be
matching in the right place).

Simon

On Tuesday 18 January 2011 12:07, Clare Embling wrote:
> Hi,
>
> I have a variable (current speed direction) which is circular (0=360
> degrees), and I'd like my GLM to include the variable as a circular
> variable.  Can I do this?  And what is the code?
>
> I'm actually doing a GLM-GEE using the 'geepack' package, so want to use it
> in that, but also interested in whether it can also be used in GLMs and
> GAMs (I use the 'mgcv' package for GAMs).
>
> Any help would be gratefully received,
> Thanks in advance,
>
> :o) Clare
>
> __
> 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.

--
> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
> +44 1225 386603  www.maths.bath.ac.uk/~sw283
__
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 and parameters

2011-01-21 Thread Moritz Grenke
#dummy data:
master=as.data.frame(list(clientId=c(1:4,2), date=1001:1005,
value=10001:10005))
control=as.data.frame(list(clientId=c(2,3), mindate=c(100,1005),
maxdate=c(1005,1005), control.params=c(1,2)))

#reducing master df:
#generating "TRUE FALSE index":
idIndex=master$clientId %in% control$clientId

#choose only those lines where index==TRUE
master_reduced=master[idIndex,]
master_reduced

#merging dfs:
mergingIndex= match(master_reduced$clientId, control$clientId)
master_reduced=cbind(master_reduced, control[mergingIndex,])
master_reduced

#finally choose those lines where date is in range
dateIndex=master_reduced$date>master_reduced$mindate &
master_reduced$datehttp://www.360mix.de

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
Auftrag von analys...@hotmail.com
Gesendet: Freitag, 21. Januar 2011 03:02
An: r-help@r-project.org
Betreff: [R] data and parameters

(1) I have a master data frame that reads

ClientID |date |value

(2) I also have a control data frame that reads

Client ID| Min date| Max date| control parameters

The control data set may not have all client IDs .

I want to use the control data frame on the master data frame to
remove client IDS that don't exist in the control data set and for
those that do, remove dates outside the required range.

(3) We can either put the control parameters on all rows corresponding
to a client ID or look it up from the control data frame

(4) The basic function call looks like

do.something(df,control parameters)

where df is the subset of the master data set that corresponds to a
single client with unwanted dates removed and the control parameters
pertain to that client.

Any help would be appreciated.

__
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] forecasting with L-STAR

2011-01-21 Thread Sara Szeremeta
Is it possible to make forecasts with L-STAR model (or alternatively E-STAR)
?
Although function for LSTAR exists I did not find an indication of
forecasting possibilities in the documentation.

[[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] 3D Binning

2011-01-21 Thread vioravis

I am trying to do binning on three variables (3d binning). The bin boundaries
are specified by the user separately for each variable. I used the bin2
function in the 'ash' package for 2d binning that involves only two
variables but didn't any package for similar binning with three variables.
Are there any packages or codes available for 3d binning?? Thank you.

-- 
View this message in context: 
http://r.789695.n4.nabble.com/3D-Binning-tp3229137p3229137.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! complete the reviewer's suggest: carry out GA+GP (gaussian process)!

2011-01-21 Thread bbslover

Hello, all experts,

My major is computer-aied drug design ( main QSAR).

Now, my paper need be reviesed, and one reviewer ask me do genetic algorithm
coupled with gaussian process method (GA+GP).

my data:
training set: 191*106
test set: 73*106

here, I need use GA+GP to do variable selection when building the model. 

In R, there are not GA package like in matlab
GA-toolbox(http://www.sheffield.ac.uk/acse/research/ecrg/gat.html) .

now, I just can use the matlab GA-tool box, however, I can not use
GP-toolbox in matlab. so I search the internet, find R package "genalg" can
do GA. and an example given is to do wavelength selection by GA+PLS, so I
think i certainly do the GA+GP. unfortunately, in this genalg package, i do
not know how to extract the selected variables, it seems likes there is not
such function. So I want to all friends help me to solve the reviewer's
suggestion: do GA+GP and extract the optimal variables and get the some
statistical parameters (i.e., cross-validation R2, pred R2 etc).

now, I can do GA+svm to do variable selection and build the models and get
some statistical paramets depicted above.

GA: matlab GA toolbox
(http://www.sheffield.ac.uk/acse/research/ecrg/gat.html)
svm: libsvm (http://www.csie.ntu.edu.tw/~cjlin/libsvm/)

now I want to know, how to get the predicted values :

In libsvm for example:
cmd = ['-v ',num2str(v),' -c',num2str(cgp(nind,1)),  '-g
',num2str(cgp(nind,2)),' -p ',num2str(cgp(nind,3)),' -s 3'];
model = svmtrain(train_y,train_data_best,cmd);
train_pred = svmpredict(train_y,train_data_best,model); % get the predicted
values for the training set

I can get the train_pred, likewise I can get the test_pred (tes_pred =
svmpredict(test_y,test_data_best,model);)

If I have the obsved train_y,test_y and the predicted train_pred and
test_pred, some statistical parameter can be calculated. 

But For GP, how can i get the predicted values?

(from GP website:  http://www.gaussianprocess.org/gpml/code/matlab/doc/)

prediction: [ymu ys2 fmu fs2   ] = gp(hyp, inf, mean, cov, lik, x, y, xs); 

here, the "ymu" are the predicted values that similar to "test_pred" in
libsvm?  

I hope all friends  can give me a hand, sincere there are little days i
should upload my revised manuscript, but until now this quest can not be
soved.

thanks for your help.

kevin




-- 
View this message in context: 
http://r.789695.n4.nabble.com/help-complete-the-reviewer-s-suggest-carry-out-GA-GP-gaussian-process-tp3229097p3229097.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] nlminb doesn't converge and produce a warning

2011-01-21 Thread kamel gaanoun
Hi Everybody,

My problem is that nlminb doesn't converge, in minimising a logLikelihood
function, with 31*6 parameters(2 weibull parameters+29 regressors repeated 6
times).


I use nlminb like this :
res1<-nlminb(vect, V, lower=c(rep(0.01, 12), rep(0.01, 3), rep(-Inf, n-15)),
upper=c(rep(Inf, 12), rep(0.99, 3), rep(Inf, n-15)), control =
list(maxit=1000) )

and that's the result :

Message d'avis :
In nlminb(vect, V, lower = c(rep(0.01, 12), rep(0.01, 3), rep(-Inf,  :
  unrecognized control element(s) named `maxit' ignored
> res1
$par
  [1]   2.48843979   4.75209125   2.57199837  16.80712783   3.15211075
16.86606178  58.61925499  37.85793462  48.78215699
 [10] 151.64638501  43.60420299  15.14639541   0.58754382   0.76180935
0.66191763  -0.26802757  -0.96378197  -0.68369525
 [19]   0.37813096   0.89778593 -10.26471908  -0.87265813   6.43973968
-1.74417166  12.00193419   0.60638326  -1.66675589
 [28]   1.29312079   1.39846863  -0.48449361  20.14470193  -0.50729841
-2.15177967  -0.78155345   0.41857810  -0.40863744
 [37] -17.18489562  -1.69140562   1.45236861  -0.23738183   5.47688642
-0.71546576   9.95015047  -2.16096138  -0.74503151
 [46]  -0.66258461   5.38871217   2.53147752 -12.58827379  -0.45669589
-0.37285088   2.15116198  -2.50414066  -0.99752892
 [55]   4.83972450  -1.16496925  -3.53429528   0.56083677  -9.87490932
-1.75153657   9.87912224  -0.75783517  -9.95423392
 [64]  -0.07530469  -0.73466191  -0.27397382  15.15891548  -0.02489436
12.91493065  -4.65335356   0.03524561   0.
 [73]  -9.06720312  -0.25413758  -0.18578765   0.53283198  -4.02688497
-0.50581412  -0.31544940   0.57450848   6.15206152
 [82]   0.08178377   0.82978606   0.39337352  -3.65304712  -0.06833839
3.87790848  -1.08017043   3.62779184  -0.14700541
 [91] -13.95610827  -1.50385432   8.05851743  -1.24250013  -0.01249817
0.38085483  -4.97064573  -0.98852401  -3.00305183
[100]   0.35053875  -4.26833889  -0.12463188  16.05828402   0.41736764
-0.94678922  -0.75813452   2.15378348   0.39586048
[109]   1.41359441   0.81603207  -4.43963958  -0.79438435   0.49530882
0.11197484  -8.43196798   1.00456535 -22.04423030
[118]  -0.11532887   2.58085765   1.41912515  -0.78120889  -1.23850824
12.39079062   0.23567444   1.39557879  -2.22993802
[127] -12.58827379  -0.45669589  -0.37285088  -0.73563805   3.40201735
0.58550247  -3.62769828   0.21657740  -7.37785506
[136]  -0.68218180   6.41876225   0.38708385  -0.33009429  -0.25230736
3.53672719   1.53676202   3.65074513   0.42623602
[145]  -7.26982010   0.70597611 -23.15198788  -0.36822845  -2.29863267
0.70223129 -14.45665129  -0.54094864  -2.17858443
[154]  -0.56501734   2.50032796  -0.45677181  12.04113439  -1.42294094
-16.1687  -0.49101846  -6.29724769  -1.38333722
[163] -14.16552579   1.57502968   5.04329383   0.24857745  -1.69885428
-0.46757266   4.41795651  -2.41006349   4.61648610
[172]   0.42235314  -3.22153895  -0.15443857   1.07661101  -0.63653449
-2.74034265   0.20898466   1.37927183   0.26722477
[181] -15.09685067   0.87160467 -24.79722150   1.48810684   1.70068893
-0.22538026   7.63908028   1.60431981  -7.52661064

$objective
[1] 1514.691

$convergence
[1] 1

$message
[1] "iteration limit reached without convergence (9)"

$iterations
[1] 150

$evaluations
function gradient
 17644935

I tried many times to take the res1$par as initial values and retry againe
but still doesn't converge.


Any help will save me Thanks

-- 
Kamel Gaanoun
(+33) (0)6.76.04.65.77

[[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] Loop and store results

2011-01-21 Thread Sam
Dear List,

I have a data-frame 

#prepare the data
example <- data.frame(letters[1:9],
   sample(letters, 9),
   sample(letters, 9),
   sample(letters, 9),
   sample(letters, 9),
   sample(letters, 9),
   sample(letters, 9),
   sample(letters, 9),
   sample(letters, 9))
colnames(example) <- c("individuals", 1:8)

I want to sample this 

#sample the data
a_1 <- example[sample(nrow(example),3),]

individuals 1 2 3 4 5 6 7 8
8   h w m r a n v v b
6   f e b g u v r b p
3   c z c s k t e i g

However i want to sample it 500 times, so i need to use the loop function - 
which is something, unfortunately i am unsure how to write.

Furthermore, i want to output the results in a data-frame ( i think i need the 
list function, but again i am unsure)

Ideally it would be separated by sample but i am unsure if this is possible? 
However as long as the order is kept intact that will be fine. I.E the top 3 
are sample 1, the next 3 are sample 2 etc

What i require:-

individuals 1 2 3 4 5 6 7 8

8h w m r a n v v b
6   f e b g u v r b p
3   c z c s k t e i g

9   h w m f a n v v b
4   f e b g b v r b p
2   c z c s k t e i g

If its not too much to ask: I will then sample it 4 individuals 500 times , 5 
individuals etc etc and store these _ i can always do these separately if its 
asking too much!

Thanks,

Sam

__
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] auc function

2011-01-21 Thread Petr Savicky
On Thu, Jan 20, 2011 at 03:14:01PM -0800, Changbin Du wrote:
> ROCR
> 

I appreciate this information, which is new for me. Up to now, i was
using the function

  get.auc <- function(statistic, label, negative, positive)
  {
  xmove <- as.numeric(label == negative)
  ymove <- as.numeric(label == positive)
  stopifnot(xmove + ymove == 1)
  rank.stat <- rank(statistic, ties.method="min")
  steps <- aggregate(cbind(xmove, ymove), by=list(rank.stat), sum)
  n <- nrow(steps)
  x <- c(0, cumsum(steps[n:1, 2]))
  y <- c(0, cumsum(steps[n:1, 3]))
  sum(diff(x) * (y[1:n] + y[2:(n+1)]))/(2*max(x)*max(y))
  }

CRAN package ROCR allows to compute many different measures and
visualisations of classifier performance. In particular, AUC may
be computed as follows

  library(ROCR)

  n <- 50
  label <- ordered(rep(c("c1", "c2"), length=n))
  set.seed(12345)
  statistic <- rnorm(n) + (label == "c2")
  pred <- prediction(statistic, label)
  AUC <- performance(pred, "auc")@y.values[[1]]
  cbind(AUC, diff=AUC - get.auc(statistic, label, "c1", "c2"))
  # AUC diff
  # [1,] 0.73920

The difference is not always exactly zero, but is at the level
of the machine rounding error.

Petr Savicky.

> 
> 
> On Thu, Jan 20, 2011 at 3:04 PM, He, Yulei  wrote:
> 
> > Hi, there.
> >
> > Suppose I already have sensitivities and specificities. What is the quick
> > R-function to calculate AUC for the ROC plot? There seem to be many R
> > functions to calculate AUC.
> >
> > Thanks.
> >
> > Yulei
> >
> >

__
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] stochastic models for population growth

2011-01-21 Thread Vassily Shvets
Hello,
Having measured two populations' characteristics at one particular time[with 
great precision] with R, I would like to extend this to measuring the same 
populations starting at t1, and then again at t2, and try to develop a growth 
model (something like dpop1/dt=r*pop^(...),dpop2/dt=r*pop^(...)). I think the 
idea is to create a model that will predict the growth of a population(N(mu, 
sigma)) within a margin of error. This kind of modeling isn't well known or 
publicized in terms of R, am I right?
regards,
s

__
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] Loop and store results

2011-01-21 Thread Henrique Dallazuanna
Try this:

replicate(500, example[sample(nrow(example), 3),], simplify = FALSE)


On Fri, Jan 21, 2011 at 8:47 AM, Sam  wrote:

> Dear List,
>
> I have a data-frame
>
> #prepare the data
> example <- data.frame(letters[1:9],
>   sample(letters, 9),
>   sample(letters, 9),
>   sample(letters, 9),
>   sample(letters, 9),
>   sample(letters, 9),
>   sample(letters, 9),
>   sample(letters, 9),
>   sample(letters, 9))
> colnames(example) <- c("individuals", 1:8)
>
> I want to sample this
>
> #sample the data
> a_1 <- example[sample(nrow(example),3),]
>
> individuals 1 2 3 4 5 6 7 8
> 8   h w m r a n v v b
> 6   f e b g u v r b p
> 3   c z c s k t e i g
>
> However i want to sample it 500 times, so i need to use the loop function -
> which is something, unfortunately i am unsure how to write.
>
> Furthermore, i want to output the results in a data-frame ( i think i need
> the list function, but again i am unsure)
>
> Ideally it would be separated by sample but i am unsure if this is
> possible? However as long as the order is kept intact that will be fine. I.E
> the top 3 are sample 1, the next 3 are sample 2 etc
>
> What i require:-
>
> individuals 1 2 3 4 5 6 7 8
>
> 8h w m r a n v v b
> 6   f e b g u v r b p
> 3   c z c s k t e i g
>
> 9   h w m f a n v v b
> 4   f e b g b v r b p
> 2   c z c s k t e i g
>
> If its not too much to ask: I will then sample it 4 individuals 500 times ,
> 5 individuals etc etc and store these _ i can always do these separately if
> its asking too much!
>
> Thanks,
>
> Sam
>
> __
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] Function comparable to cutpt.coxph from "Survival Analysis using S"

2011-01-21 Thread Schneider, Friederike Dr.
Dear Mrs Rachel Pearce,
I am looking for a function "cutpt-coxph" in R - like you did some years ago.
How have you solved the problem? Have you found it or a similar function?

thank you, Sincerely, Friederike


"The title says it all really; I am looking for a function along the lines of
cutpt.coxph as described in "Survival Analysis Using S" (Tableman and
Kim), Chapter 6. As may be guessed, the function optimises the
cutpoint of a continuous variable for cox proportional hazard
modelling. I can't find it, or any similar function, on CRAN.

Alternatively, perhaps there is a way of extracting the likelihoods
from the output of coxph."


Dr. med. Friederike Schneider 
Assistenzärztin 
Klinikum der LMU 
Campus Grosshadern 
Marchioninistr. 15 
81377 München 
Tel.: 089-7099-425
friederike.schnei...@med.uni-muenchen.de

__
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] nlminb doesn't converge and produce a warning

2011-01-21 Thread Karl Ove Hufthammer
kamel gaanoun wrote:

> I use nlminb like this :
> res1<-nlminb(vect, V, lower=c(rep(0.01, 12), rep(0.01, 3), rep(-Inf,
> n-15)), upper=c(rep(Inf, 12), rep(0.99, 3), rep(Inf, n-15)), control =
> list(maxit=1000) )
> 
> and that's the result :
> 
> Message d'avis :
> In nlminb(vect, V, lower = c(rep(0.01, 12), rep(0.01, 3), rep(-Inf,  :
> unrecognized control element(s) named `maxit' ignored

Just increase the maximum number of iterations. Which you tried to do, but 
didn’t succeed in, as the above warnings shows. The argument is called 
‘iter.max’, not ‘max.iter’.

-- 
Karl Ove Hufthammer

__
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] User input in R program

2011-01-21 Thread christiaan pauw
HI Everybody

Does anyone know of documentation about different ways of obtaining user
input in R. I have used readline() but I wondered is there are sophisticated
packages that does things like validate answers or generate selection
lists.

bets regards
Christaan

[[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] How to look into the asterisked function?

2011-01-21 Thread Bogaso Christofer
Hi friends, there is methods() function to see the all available methods for
a particular function, for example:

 

> head(methods("print"))

[1] "print.acf" "print.anova"   "print.aov" "print.aovlist"
"print.ar"  "print.Arima"  

 

In this list, there are some functions which are asterisked like
print.acf(). How can I see the contents of those function?

 

Thanks and regards,


[[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] How to look into the asterisked function?

2011-01-21 Thread Henrique Dallazuanna
Try this:

getS3method("print", "acf")

On Fri, Jan 21, 2011 at 11:02 AM, Bogaso Christofer <
bogaso.christo...@gmail.com> wrote:

> Hi friends, there is methods() function to see the all available methods
> for
> a particular function, for example:
>
>
>
> > head(methods("print"))
>
> [1] "print.acf" "print.anova"   "print.aov" "print.aovlist"
> "print.ar"  "print.Arima"
>
>
>
> In this list, there are some functions which are asterisked like
> print.acf(). How can I see the contents of those function?
>
>
>
> Thanks and regards,
>
>
>[[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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] How to look into the asterisked function?

2011-01-21 Thread jim holtman
You can also use:

getAnywhere("functionName")


On Fri, Jan 21, 2011 at 8:02 AM, Bogaso Christofer
 wrote:
> Hi friends, there is methods() function to see the all available methods for
> a particular function, for example:
>
>
>
>> head(methods("print"))
>
> [1] "print.acf"     "print.anova"   "print.aov"     "print.aovlist"
> "print.ar"      "print.Arima"
>
>
>
> In this list, there are some functions which are asterisked like
> print.acf(). How can I see the contents of those function?
>
>
>
> Thanks and regards,
>
>
>        [[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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
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 and parameters

2011-01-21 Thread jim holtman
try 'sqldf'

> master=as.data.frame(list(clientId=c(1:4,2), date=1001:1005,
+ value=10001:10005))
> control=as.data.frame(list(clientId=c(2,3), mindate=c(100,1005),
+ maxdate=c(1005,1005), control.params=c(1,2)))
> master
  clientId date value
11 1001 10001
22 1002 10002
33 1003 10003
44 1004 10004
52 1005 10005
> control
  clientId mindate maxdate control.params
12 1001005  1
2310051005  2
> require(sqldf)
> sqldf("
+ select m.*
+ from master m, control c
+ where m.clientId = c.clientID
+ and m.date between c.mindate and c.maxdate
+ ")
  clientId date value
12 1002 10002
22 1005 10005
>
>


On Thu, Jan 20, 2011 at 9:02 PM, analys...@hotmail.com
 wrote:
> (1) I have a master data frame that reads
>
> ClientID |date |value
>
> (2) I also have a control data frame that reads
>
> Client ID| Min date| Max date| control parameters
>
> The control data set may not have all client IDs .
>
> I want to use the control data frame on the master data frame to
> remove client IDS that don't exist in the control data set and for
> those that do, remove dates outside the required range.
>
> (3) We can either put the control parameters on all rows corresponding
> to a client ID or look it up from the control data frame
>
> (4) The basic function call looks like
>
> do.something(df,control parameters)
>
> where df is the subset of the master data set that corresponds to a
> single client with unwanted dates removed and the control parameters
> pertain to that client.
>
> Any help would be appreciated.
>
> __
> 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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
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 and parameters

2011-01-21 Thread jim holtman
forgot the control parameters:

> sqldf("
+ select m.*, c.control_params
+ from master m, control c
+ where m.clientId = c.clientID
+ and m.date between c.mindate and c.maxdate
+ ")
  clientId date value control_params
12 1002 10002  1
22 1005 10005  1
>


On Thu, Jan 20, 2011 at 9:02 PM, analys...@hotmail.com
 wrote:
> (1) I have a master data frame that reads
>
> ClientID |date |value
>
> (2) I also have a control data frame that reads
>
> Client ID| Min date| Max date| control parameters
>
> The control data set may not have all client IDs .
>
> I want to use the control data frame on the master data frame to
> remove client IDS that don't exist in the control data set and for
> those that do, remove dates outside the required range.
>
> (3) We can either put the control parameters on all rows corresponding
> to a client ID or look it up from the control data frame
>
> (4) The basic function call looks like
>
> do.something(df,control parameters)
>
> where df is the subset of the master data set that corresponds to a
> single client with unwanted dates removed and the control parameters
> pertain to that client.
>
> Any help would be appreciated.
>
> __
> 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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
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] Extraction and replacement of data in a data frame

2011-01-21 Thread michael.hopgood

Dear all,

Thank you for the prompt responses.  It is until today that I have managed
to scrap together the time to develop my R-project further.  In my free
time, I have been reading various intro manuals, so I have a rough idea of
what needs doing.  Sometimes, though, putting it into practice is more
troublesome than it looks. It is fascinating how pliable this programming
language is.  I will report on my progress as soon as I can.

Sincerely,
Michael Hopgood.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Extraction-and-replacement-of-data-in-a-data-frame-tp3221261p3229476.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] User input in R program

2011-01-21 Thread Hugo Mildenberger
Hello Christian,

for an example of interacting with graphic output, just run

example(getGraphicsEvent)

However, on X11, that feature had ceased to work since a pre-release 
of R-2.12 if Cairo support was enabled at compile time. The reason for 
this defect had already been documented in R's bugs database for long. 
Maybe getGraphicsEvent still runs on Windows.

Best 

Hugo

On Friday 21 January 2011 13:26:26 christiaan pauw wrote:
> HI Everybody
> 
> Does anyone know of documentation about different ways of obtaining user
> input in R. I have used readline() but I wondered is there are sophisticated
> packages that does things like validate answers or generate selection
> lists.
> 
> bets regards
> Christaan
> 
>   [[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] complex transformation of data

2011-01-21 Thread Den
Dear [R] people
Could you please help with following data transformation.
Any suggestions, hints, references and even guessing on performing any
of the following steps are highly appreciated. Those transformations are
crucial for my work. 

(n_, _n, j_, k_ signify numbers)

SOURCE DATA:   
id  cycle1  cycle2  cycle3  …   cycle_n
1   c   c   c   c
1   m   m   m   m
1   f   f   f   f
2   m   m   m   NA
2   f   f   f   NA
2   c   c   c   NA
3   a   a   NA  NA
3   c   c   c   NA
3   f   f   f   NA
3   NA  NA  m   NA
...



RESULT DATA1:
id  cyc1cyc2cyc3…   cyc_n
1   cfm cfm cfm cfm
2   cfm cfm cfm NA
3   acf acf cfm NA
...


RESULT DATA2:
id  treatment
1   n_cfm
2   j_cfm
3   2acf->k_cfm
...


RESULT DATA3:
id  regimen numOfCycles
1   cfm n_
2   cfm j_
3   asf->cfm{2+k_}
.



Thank you
Denis

__
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 comparable to cutpt.coxph from "Survival Analysis using S"

2011-01-21 Thread Frank Harrell

It is very uncommon for the assumptions underlying this method to be
satisfied.  These assumptions include (1) the relationship between X and log
relative hazard is discontinuous at X=c and only X=c; (2) c is correctly
found as the cutpoint; (3) X vs log hazard is flat to the left of c; (4) X
vs log hazard is flat to the right of c; (5) the 'optimal' cutpoint does not
depend on the values of other predictors.

These relationships rarely occur in nature unless X=time.  Failure to have
these assumptions satisfied will result in (1) great error in estimating c
(because c doesn't exist); (2) low predictive accuracy; (3) serious lack of
fit; (4) residual confounding; and (5) overestimation of effects of
remaining variables.

This non-existence of cutpoints is why in medical research no two
investigators seem to find the same cutpoint for the same predictor in
different datasets.

Frank


-
Frank Harrell
Department of Biostatistics, Vanderbilt University
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Function-comparable-to-cutpt-coxph-from-Survival-Analysis-using-S-tp3229420p3229704.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] Regression Testing

2011-01-21 Thread Mojo

On 1/20/2011 4:42 PM, Achim Zeileis wrote:

On Thu, 20 Jan 2011, Mojo wrote:

I'm new to R and some what new to the world of stats.  I got 
frustrated with excel and found R.  Enough of that already.


I'm trying to test and correct for Heteroskedasticity

I have data in a csv file that I load and store in a dataframe.


ds <- read.csv("book2.csv")
df <- data.frame(ds)


I then preform a OLS regression:


lmfit <- lm(df$y~df$x)


Just btw: lm(y ~ x, data = df) is somewhat easier to read and also 
easier to write when the formula involves more regressors.



To test for Heteroskedasticity, I run the BPtest:


bptest(lmfit)


   studentized Breusch-Pagan test

data:  lmfit
BP = 11.6768, df = 1, p-value = 0.0006329

From the above, if I'm interpreting this correctly, there is 
Heteroskedasticity present.  To correct for this, I need to calculate 
robust error terms.


That is one option. Another one would be using WLS instead of OLS - or 
maybe FGLS. As the model just has one regressor, this might be 
possible and result in a more efficient estimate than OLS.


I thought that WLS (which I guessing is a weighted regression) is really 
only useful when you know or at least have an idea of what is causing 
the Heteroskedasticity?  I'm not familiar with FGLS.  I plan on adding 
additional independent variables as I get more comfortable with everything.





From my reading on this list, it seems like I need to vcovHC.


That's another option, yes.


vcovHC(lmfit)

 (Intercept) df$x
(Intercept)  1.057460e-03 -4.961118e-05
df$x   -4.961118e-05  2.378465e-06

I'm having a little bit of a hard time following the help pages.


Yes, the manual page is somewhat technical but the first thing the 
"Details" section does is: It points you to some references that 
should be easier to read. I recommend starting with


 Zeileis A (2004), Econometric Computing with HC and HAC Covariance
 Matrix Estimators. _Journal of Statistical Software_, *11*(10),
 1-17. URL http://www.jstatsoft.org/v11/i10/>.


I will look into that.

Thanks,
Mojo

__
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] Regression Testing

2011-01-21 Thread Achim Zeileis

On Fri, 21 Jan 2011, Mojo wrote:


On 1/20/2011 4:42 PM, Achim Zeileis wrote:

On Thu, 20 Jan 2011, Mojo wrote:

I'm new to R and some what new to the world of stats.  I got frustrated 
with excel and found R.  Enough of that already.


I'm trying to test and correct for Heteroskedasticity

I have data in a csv file that I load and store in a dataframe.


ds <- read.csv("book2.csv")
df <- data.frame(ds)


I then preform a OLS regression:


lmfit <- lm(df$y~df$x)


Just btw: lm(y ~ x, data = df) is somewhat easier to read and also easier 
to write when the formula involves more regressors.



To test for Heteroskedasticity, I run the BPtest:


bptest(lmfit)


   studentized Breusch-Pagan test

data:  lmfit
BP = 11.6768, df = 1, p-value = 0.0006329

From the above, if I'm interpreting this correctly, there is 
Heteroskedasticity present.  To correct for this, I need to calculate 
robust error terms.


That is one option. Another one would be using WLS instead of OLS - or 
maybe FGLS. As the model just has one regressor, this might be possible and 
result in a more efficient estimate than OLS.


I thought that WLS (which I guessing is a weighted regression) is really only 
useful when you know or at least have an idea of what is causing the 
Heteroskedasticity?


Yes. But with only a single variable that shouldn't be too hard to do. 
Also in the Breusch-Pagan test you specify a hypothesized functional form 
for the variance.



I'm not familiar with FGLS.


There is a worked example in

  demo("Ch-LinearRegression", package = "AER")

The corresponding book has some more details.

hth,
Z

I plan on adding additional 
independent variables as I get more comfortable with everything.





From my reading on this list, it seems like I need to vcovHC.


That's another option, yes.


vcovHC(lmfit)

 (Intercept) df$x
(Intercept)  1.057460e-03 -4.961118e-05
df$x   -4.961118e-05  2.378465e-06

I'm having a little bit of a hard time following the help pages.


Yes, the manual page is somewhat technical but the first thing the 
"Details" section does is: It points you to some references that should be 
easier to read. I recommend starting with


 Zeileis A (2004), Econometric Computing with HC and HAC Covariance
 Matrix Estimators. _Journal of Statistical Software_, *11*(10),
 1-17. URL http://www.jstatsoft.org/v11/i10/>.


I will look into that.

Thanks,
Mojo




__
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] User input in R program

2011-01-21 Thread Matt Shotwell
Martyn Plummer's 'coda' package has some nice interactive menus. The
package appears to be written entirely in R. You could start with the
codamenu() function in the package source:

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

-Matt

On Fri, 2011-01-21 at 14:26 +0200, christiaan pauw wrote:
> HI Everybody
> 
> Does anyone know of documentation about different ways of obtaining user
> input in R. I have used readline() but I wondered is there are sophisticated
> packages that does things like validate answers or generate selection
> lists.
> 
> bets regards
> Christaan
> 
>   [[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.


Re: [R] User input in R program

2011-01-21 Thread D Kelly O'Day

Christian

Have you looked at the  http://www.stats.gla.ac.uk/~adrian/rpanel/ rpanel 
package?

I have a post which shows an example of interactive input that allows user
to adjust plot parameters.
http://chartsgraphs.wordpress.com/2009/05/08/rpanel-package-adds-interactive-capabilites-to-r/
 
link 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/User-input-in-R-program-tp3229515p3229738.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] complex transformation of data

2011-01-21 Thread ONKELINX, Thierry
Denis,

Have a look at paste(), aggregate(), ddply() (from the plyr package) and melt() 
and cast() (both from the reshape package).

Best regards,

Thierry


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey
  

> -Oorspronkelijk bericht-
> Van: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] Namens Den
> Verzonden: vrijdag 21 januari 2011 13:26
> Aan: R-help
> Onderwerp: [R] complex transformation of data
> 
> Dear [R] people
> Could you please help with following data transformation.
> Any suggestions, hints, references and even guessing on 
> performing any of the following steps are highly appreciated. 
> Those transformations are crucial for my work. 
> 
> (n_, _n, j_, k_ signify numbers)
> 
> SOURCE DATA:   
> idcycle1  cycle2  cycle3  ... cycle_n
> 1 c   c   c   c
> 1 m   m   m   m
> 1 f   f   f   f
> 2 m   m   m   NA
> 2 f   f   f   NA
> 2 c   c   c   NA
> 3 a   a   NA  NA
> 3 c   c   c   NA
> 3 f   f   f   NA
> 3 NA  NA  m   NA
> ...
> 
> 
> 
> RESULT DATA1:
> idcyc1cyc2cyc3... cyc_n
> 1 cfm cfm cfm cfm
> 2 cfm cfm cfm NA
> 3 acf acf cfm NA
> ...
> 
> 
> RESULT DATA2:
> idtreatment
> 1 n_cfm
> 2 j_cfm
> 3 2acf->k_cfm
> ...
> 
> 
> RESULT DATA3:
> idregimen numOfCycles
> 1 cfm n_
> 2 cfm j_
> 3 asf->cfm{2+k_}
> .
> 
> 
> 
> Thank you
> Denis
> 
> __
> 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] complex transformation of data

2011-01-21 Thread Moritz Grenke
Hi Denis, 

#minimal example:
test<-as.data.frame(list(id=c(1,1,1,2,2,2), cycle1=c("c", "m", "f", "m",
"f", "c")))

#gettin your first cell of Result 1
paste(sort(test$cycle1[test$id==1]), collapse="")


Hope this helps for the first task ... 
Moritz

__
Moritz Grenke
http://www.360mix.de

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
Auftrag von Den
Gesendet: Freitag, 21. Januar 2011 13:26
An: R-help
Betreff: [R] complex transformation of data

Dear [R] people
Could you please help with following data transformation.
Any suggestions, hints, references and even guessing on performing any
of the following steps are highly appreciated. Those transformations are
crucial for my work. 

(n_, _n, j_, k_ signify numbers)

SOURCE DATA:   
id  cycle1  cycle2  cycle3  …   cycle_n
1   c   c   c   c
1   m   m   m   m
1   f   f   f   f
2   m   m   m   NA
2   f   f   f   NA
2   c   c   c   NA
3   a   a   NA  NA
3   c   c   c   NA
3   f   f   f   NA
3   NA  NA  m   NA
...



RESULT DATA1:
id  cyc1cyc2cyc3…   cyc_n
1   cfm cfm cfm cfm
2   cfm cfm cfm NA
3   acf acf cfm NA
...


RESULT DATA2:
id  treatment
1   n_cfm
2   j_cfm
3   2acf->k_cfm
...


RESULT DATA3:
id  regimen numOfCycles
1   cfm n_
2   cfm j_
3   asf->cfm{2+k_}
.



Thank you
Denis

__
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] User input in R program

2011-01-21 Thread Mauricio Zambrano
Probably, iplots may be useful for you:

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

Kinds,

Mauricio
-- 
===
Linux user #454569 -- Ubuntu user #17469
===

2011/1/21 christiaan pauw :
> HI Everybody
>
> Does anyone know of documentation about different ways of obtaining user
> input in R. I have used readline() but I wondered is there are sophisticated
> packages that does things like validate answers or generate selection
> lists.
>
> bets regards
> Christaan
>
>        [[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] HHT-methodology

2011-01-21 Thread Torbjørn Lorentzen

Hello R-experts,

I wonder whether any of the R-packages cover the Hilbert-Huang Transform 
methodology (HHT)?


Regards,
Torbjorn



--
Torbjørn Lorentzen | torbjorn.lorent...@bjerknes.uib.no 
|torbjorn.lorent...@uni.no | http://www.bjerknes.uib.no/
Phone: +47 55 58 25 05 | Cellphone: +47 906 972 36 | Bjerknes Centre for 
Climate Research | Geophysical Institute |

University of Bergen | Allegaten 55 | NO-5007 Bergen | Norway |

__
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 in ANOVA for model comparison

2011-01-21 Thread Rosario Garcia Gil
Hello

I am trying to compare two models using anova(), however I get a message error 
(see below).
In the net I only found some information on certain library(car) for which one 
should use anova with A capital letter (Anova instead of anova), but I could 
not find car library as it says it does not exist.


> Model <- lm(interceptG ~ SW + TSC + FSC + PF + SlopeG + K, data=AllTrait)
> Model1 <- lm(interceptG ~ SW + TSC + FSC + PF + SlopeG + PHt, data=AllTrait)

Error in anova.lmlist(object, ...) : 
  models were not all fitted to the same size of dataset

I have NA in the datafile, should that be the problem?

Kind regards and thanks in advance
Rosario
__
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 for lattice. par(new=TRUE)

2011-01-21 Thread Fabrice Tourre
Hi list,
I want to plot two plot in the same figure. I set par(new=TRUE). But
it does not work.

library(lattice)
myPanel <- function(x,...)
{
   panel.histogram(x,alpha=0.4,...)
   ltext(0.4,1.5,paste("Mean=","0.05",digit=2)),cex=0.8)
   ltext(0.8,1.5,paste("s.d.=","0.06",digit=2)),cex=0.8)
}
histogram(sh2, 
type="percent",panel=myPanel,breaks=seq(0,1,by=0.01),ylim=c(0,5),col=rgb(0.1,0.1,0.8,0.5))

par(new=TRUE)  Here is does not work. Warning message: In par(new
= TRUE) : calling par(new=TRUE) with no plot

histogram(sh2, type="percent",panel=myPanel,breaks=seq(0,1,by=0.01),ylim=c(0,5))

I want to the two hist in the same map. How can I set it in lattice?
Thanks.

__
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] Regression Testing

2011-01-21 Thread Mojo

On 1/21/2011 9:13 AM, Achim Zeileis wrote:

On Fri, 21 Jan 2011, Mojo wrote:


On 1/20/2011 4:42 PM, Achim Zeileis wrote:

On Thu, 20 Jan 2011, Mojo wrote:

I'm new to R and some what new to the world of stats.  I got 
frustrated with excel and found R.  Enough of that already.


I'm trying to test and correct for Heteroskedasticity

I have data in a csv file that I load and store in a dataframe.


ds <- read.csv("book2.csv")
df <- data.frame(ds)


I then preform a OLS regression:


lmfit <- lm(df$y~df$x)


Just btw: lm(y ~ x, data = df) is somewhat easier to read and also 
easier to write when the formula involves more regressors.



To test for Heteroskedasticity, I run the BPtest:


bptest(lmfit)


   studentized Breusch-Pagan test

data:  lmfit
BP = 11.6768, df = 1, p-value = 0.0006329

From the above, if I'm interpreting this correctly, there is 
Heteroskedasticity present.  To correct for this, I need to 
calculate robust error terms.


That is one option. Another one would be using WLS instead of OLS - 
or maybe FGLS. As the model just has one regressor, this might be 
possible and result in a more efficient estimate than OLS.


I thought that WLS (which I guessing is a weighted regression) is 
really only useful when you know or at least have an idea of what is 
causing the Heteroskedasticity?


Yes. But with only a single variable that shouldn't be too hard to do. 
Also in the Breusch-Pagan test you specify a hypothesized functional 
form for the variance.



I'm not familiar with FGLS.


There is a worked example in

  demo("Ch-LinearRegression", package = "AER")

The corresponding book has some more details.

hth,
Z

I plan on adding additional independent variables as I get more 
comfortable with everything.





From my reading on this list, it seems like I need to vcovHC.


That's another option, yes.


vcovHC(lmfit)

 (Intercept) df$x
(Intercept)  1.057460e-03 -4.961118e-05
df$x   -4.961118e-05  2.378465e-06

I'm having a little bit of a hard time following the help pages.


Yes, the manual page is somewhat technical but the first thing the 
"Details" section does is: It points you to some references that 
should be easier to read. I recommend starting with


 Zeileis A (2004), Econometric Computing with HC and HAC Covariance
 Matrix Estimators. _Journal of Statistical Software_, *11*(10),
 1-17. URL http://www.jstatsoft.org/v11/i10/>.


I will look into that.

Thanks,
Mojo




If I were to use vcovHAC instead of vcovHC, does that correct for serial 
correlation as well as Heteroskedasticity?


Thanks,
Mojo

__
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] Regression Testing

2011-01-21 Thread Achim Zeileis

On Fri, 21 Jan 2011, Mojo wrote:


On 1/21/2011 9:13 AM, Achim Zeileis wrote:

On Fri, 21 Jan 2011, Mojo wrote:


On 1/20/2011 4:42 PM, Achim Zeileis wrote:

On Thu, 20 Jan 2011, Mojo wrote:

I'm new to R and some what new to the world of stats.  I got frustrated 
with excel and found R.  Enough of that already.


I'm trying to test and correct for Heteroskedasticity

I have data in a csv file that I load and store in a dataframe.


ds <- read.csv("book2.csv")
df <- data.frame(ds)


I then preform a OLS regression:


lmfit <- lm(df$y~df$x)


Just btw: lm(y ~ x, data = df) is somewhat easier to read and also easier 
to write when the formula involves more regressors.



To test for Heteroskedasticity, I run the BPtest:


bptest(lmfit)


   studentized Breusch-Pagan test

data:  lmfit
BP = 11.6768, df = 1, p-value = 0.0006329

From the above, if I'm interpreting this correctly, there is 
Heteroskedasticity present.  To correct for this, I need to calculate 
robust error terms.


That is one option. Another one would be using WLS instead of OLS - or 
maybe FGLS. As the model just has one regressor, this might be possible 
and result in a more efficient estimate than OLS.


I thought that WLS (which I guessing is a weighted regression) is really 
only useful when you know or at least have an idea of what is causing the 
Heteroskedasticity?


Yes. But with only a single variable that shouldn't be too hard to do. Also 
in the Breusch-Pagan test you specify a hypothesized functional form for 
the variance.



I'm not familiar with FGLS.


There is a worked example in

  demo("Ch-LinearRegression", package = "AER")

The corresponding book has some more details.

hth,
Z

I plan on adding additional independent variables as I get more 
comfortable with everything.





From my reading on this list, it seems like I need to vcovHC.


That's another option, yes.


vcovHC(lmfit)

 (Intercept) df$x
(Intercept)  1.057460e-03 -4.961118e-05
df$x   -4.961118e-05  2.378465e-06

I'm having a little bit of a hard time following the help pages.


Yes, the manual page is somewhat technical but the first thing the 
"Details" section does is: It points you to some references that should 
be easier to read. I recommend starting with


 Zeileis A (2004), Econometric Computing with HC and HAC Covariance
 Matrix Estimators. _Journal of Statistical Software_, *11*(10),
 1-17. URL http://www.jstatsoft.org/v11/i10/>.


I will look into that.

Thanks,
Mojo




If I were to use vcovHAC instead of vcovHC, does that correct for serial 
correlation as well as Heteroskedasticity?


Yes, as the name (HAC = Heteroskedasticity and Autocorrelation Consistent) 
conveys. But for details please read the papers that accompany the 
software package and the original references cited therein.

Z


Thanks,
Mojo



__
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 look into the asterisked function?

2011-01-21 Thread Bogaso Christofer
Thanks Jim and Henrique for your replies. I would like to know why some
particular functions are asterisked? What is the pros and cons while making
a typical UDF asterisked? How can I make a typical function asterisked? For
example print.anova() is not asterisked however print.acf() is. How can I
make print.anova() asterisked? 

Thanks and regards,

-Original Message-
From: jim holtman [mailto:jholt...@gmail.com] 
Sent: 21 January 2011 18:20
To: Bogaso Christofer
Cc: r-help@r-project.org
Subject: Re: [R] How to look into the asterisked function?

You can also use:

getAnywhere("functionName")


On Fri, Jan 21, 2011 at 8:02 AM, Bogaso Christofer
 wrote:
> Hi friends, there is methods() function to see the all available 
> methods for a particular function, for example:
>
>
>
>> head(methods("print"))
>
> [1] "print.acf"     "print.anova"   "print.aov"     "print.aovlist"
> "print.ar"      "print.Arima"
>
>
>
> In this list, there are some functions which are asterisked like 
> print.acf(). How can I see the contents of those function?
>
>
>
> Thanks and regards,
>
>
>        [[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.
>



--
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
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] Error in ANOVA for model comparison

2011-01-21 Thread John Fox
Dear Rosario,

Because of missing data in the additional variable PHt, the two models
weren't fit to the same subset of valid observations -- the default in lm()
is to use complete cases for the variables in the model. 

A mechanical solution is to use na.omit() to filter your data set, only for
the variables you intend to use, to produce a data set with no NAs. Then
you'll fit each model to a consistent subset of valid cases. 

Of course, if you have a substantial amount of missing data, complete-case
analysis is probably a poor strategy.

I hope this helps,
 John


John Fox
Senator William McMaster
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox




> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Rosario Garcia Gil
> Sent: January-21-11 9:31 AM
> To: r-help@r-project.org
> Subject: [R] Error in ANOVA for model comparison
> 
> Hello
> 
> I am trying to compare two models using anova(), however I get a message
> error (see below).
> In the net I only found some information on certain library(car) for
> which one should use anova with A capital letter (Anova instead of
> anova), but I could not find car library as it says it does not exist.
> 
> 
> > Model <- lm(interceptG ~ SW + TSC + FSC + PF + SlopeG + K,
> data=AllTrait)
> > Model1 <- lm(interceptG ~ SW + TSC + FSC + PF + SlopeG + PHt,
> data=AllTrait)
> 
> Error in anova.lmlist(object, ...) :
>   models were not all fitted to the same size of dataset
> 
> I have NA in the datafile, should that be the problem?
> 
> Kind regards and thanks in advance
> Rosario
> __
> 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] clustering fuzzy

2011-01-21 Thread pete

hello,
i'm pete ,how can i order rows of matrix by max to min value?
I have a matrix of membership degrees, with 82 (i) rows and K coloumns, K
are clusters.
I need first and second largest elements of the i-th row.

for example
1  0.66 0.04 0.01 0.30
2  0.02 0.89 0.09 0.00
3  0.06 0.92 0.01 0.01
4  0.07 0.71 0.21 0.01
5  0.10 0.85 0.04 0.01
6  0.91 0.04 0.02 0.02
7  0.00 0.01 0.98 0.00
8  0.02 0.05 0.92 0.01
9  0.05 0.54 0.40 0.01
10 0.02 0.06 0.92 0.00
11 0.05 0.55 0.39 0.01
12 0.77 0.02 0.01 0.20
13 0.95 0.01 0.00 0.04
14 0.43 0.33 0.18 0.06
15 0.79 0.10 0.08 0.03
18 0.02 0.04 0.94 0.00
20 0.09 0.15 0.76 0.01
21 0.80 0.10 0.07 0.03
22 0.06 0.15 0.79 0.01
23 0.05 0.01 0.00 0.94
24 0.83 0.02 0.01 0.15
25 0.87 0.05 0.03 0.04
27 0.76 0.10 0.11 0.03
28 0.17 0.68 0.10 0.05
29 0.10 0.01 0.00 0.90
30 0.09 0.29 0.60 0.01
31 0.05 0.01 0.00 0.94
32 0.53 0.04 0.01 0.43
33 0.85 0.04 0.02 0.09
34 0.82 0.06 0.02 0.10
35 0.76 0.07 0.02 0.14
37 0.36 0.31 0.30 0.02
38 0.01 0.02 0.97 0.00
39 0.12 0.04 0.02 0.82
40 0.02 0.00 0.00 0.97
41 0.57 0.15 0.02 0.25
42 0.14 0.03 0.02 0.82
43 0.89 0.06 0.01 0.03
44 0.02 0.00 0.00 0.98
45 0.61 0.02 0.01 0.36
46 0.03 0.00 0.00 0.97
47 0.88 0.07 0.02 0.03
48 0.06 0.60 0.32 0.02
49 0.01 0.98 0.01 0.00
50 0.06 0.88 0.05 0.01
51 0.01 0.05 0.93 0.00
52 0.02 0.08 0.90 0.00
53 0.11 0.01 0.01 0.87
54 0.27 0.01 0.00 0.72
55 0.94 0.03 0.01 0.02
58 0.45 0.41 0.05 0.09
59 0.12 0.61 0.22 0.05
60 0.26 0.07 0.02 0.64
61 0.17 0.19 0.62 0.02
62 0.08 0.00 0.00 0.92
63 0.02 0.94 0.03 0.00
64 0.08 0.01 0.00 0.91
65 0.98 0.01 0.00 0.01
67 0.22 0.69 0.08 0.01
68 0.96 0.02 0.00 0.02
69 0.96 0.02 0.01 0.01
71 0.00 0.01 0.98 0.00
72 0.56 0.05 0.01 0.37
73 0.10 0.01 0.01 0.88
74 0.91 0.01 0.00 0.08
75 0.36 0.38 0.21 0.05
76 0.15 0.40 0.44 0.01
77 0.02 0.06 0.91 0.00
78 0.48 0.43 0.03 0.06
79 0.51 0.02 0.01 0.45
80 0.04 0.01 0.00 0.95
81 0.47 0.03 0.01 0.49
82 0.98 0.01 0.00 0.01
83 0.05 0.01 0.01 0.93
84 0.03 0.00 0.00 0.96
85 0.76 0.07 0.01 0.15
86 0.95 0.03 0.01 0.01
88 0.03 0.00 0.00 0.96
90 0.79 0.13 0.02 0.06
91 0.37 0.50 0.05 0.09
92 0.86 0.10 0.02 0.02
93 0.13 0.82 0.03 0.01


 A[1,][order(A[1,],decreasing=TRUE)]
[1] 0.66 0.30 0.04 0.01

I want this for every row
thank you
-- 
View this message in context: 
http://r.789695.n4.nabble.com/clustering-fuzzy-tp3229853p3229853.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] complex transformation of data

2011-01-21 Thread Henrique Dallazuanna
Try this:

aggregate(.~ id, lapply(test, as.character), FUN = paste, collapse = "")

On Fri, Jan 21, 2011 at 10:25 AM, Den  wrote:

> Dear [R] people
> Could you please help with following data transformation.
> Any suggestions, hints, references and even guessing on performing any
> of the following steps are highly appreciated. Those transformations are
> crucial for my work.
>
> (n_, _n, j_, k_ signify numbers)
>
> SOURCE DATA:
> id  cycle1  cycle2  cycle3  …   cycle_n
> 1   c   c   c   c
> 1   m   m   m   m
> 1   f   f   f   f
> 2   m   m   m   NA
> 2   f   f   f   NA
> 2   c   c   c   NA
> 3   a   a   NA  NA
> 3   c   c   c   NA
> 3   f   f   f   NA
> 3   NA  NA  m   NA
> ...
>
>
>
> RESULT DATA1:
> id  cyc1cyc2cyc3…   cyc_n
> 1   cfm cfm cfm cfm
> 2   cfm cfm cfm NA
> 3   acf acf cfm NA
> ...
>
>
> RESULT DATA2:
> id  treatment
> 1   n_cfm
> 2   j_cfm
> 3   2acf->k_cfm
> ...
>
>
> RESULT DATA3:
> id  regimen numOfCycles
> 1   cfm n_
> 2   cfm j_
> 3   asf->cfm{2+k_}
> .
>
>
>
> Thank you
> Denis
>
> __
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] clustering fuzzy

2011-01-21 Thread jim holtman
use 'apply':

> head(x.m)
   V2   V3   V4   V5
[1,] 0.66 0.04 0.01 0.30
[2,] 0.02 0.89 0.09 0.00
[3,] 0.06 0.92 0.01 0.01
[4,] 0.07 0.71 0.21 0.01
[5,] 0.10 0.85 0.04 0.01
[6,] 0.91 0.04 0.02 0.02
> x.m.sort <- apply(x.m, 1, sort, decreasing = TRUE)
> head(t(x.m.sort))
 [,1] [,2] [,3] [,4]
[1,] 0.66 0.30 0.04 0.01
[2,] 0.89 0.09 0.02 0.00
[3,] 0.92 0.06 0.01 0.01
[4,] 0.71 0.21 0.07 0.01
[5,] 0.85 0.10 0.04 0.01
[6,] 0.91 0.04 0.02 0.02
>


On Fri, Jan 21, 2011 at 10:07 AM, pete  wrote:
>
> hello,
> i'm pete ,how can i order rows of matrix by max to min value?
> I have a matrix of membership degrees, with 82 (i) rows and K coloumns, K
> are clusters.
> I need first and second largest elements of the i-th row.
>
> for example
> 1  0.66 0.04 0.01 0.30
> 2  0.02 0.89 0.09 0.00
> 3  0.06 0.92 0.01 0.01
> 4  0.07 0.71 0.21 0.01
> 5  0.10 0.85 0.04 0.01
> 6  0.91 0.04 0.02 0.02
> 7  0.00 0.01 0.98 0.00
> 8  0.02 0.05 0.92 0.01
> 9  0.05 0.54 0.40 0.01
> 10 0.02 0.06 0.92 0.00
> 11 0.05 0.55 0.39 0.01
> 12 0.77 0.02 0.01 0.20
> 13 0.95 0.01 0.00 0.04
> 14 0.43 0.33 0.18 0.06
> 15 0.79 0.10 0.08 0.03
> 18 0.02 0.04 0.94 0.00
> 20 0.09 0.15 0.76 0.01
> 21 0.80 0.10 0.07 0.03
> 22 0.06 0.15 0.79 0.01
> 23 0.05 0.01 0.00 0.94
> 24 0.83 0.02 0.01 0.15
> 25 0.87 0.05 0.03 0.04
> 27 0.76 0.10 0.11 0.03
> 28 0.17 0.68 0.10 0.05
> 29 0.10 0.01 0.00 0.90
> 30 0.09 0.29 0.60 0.01
> 31 0.05 0.01 0.00 0.94
> 32 0.53 0.04 0.01 0.43
> 33 0.85 0.04 0.02 0.09
> 34 0.82 0.06 0.02 0.10
> 35 0.76 0.07 0.02 0.14
> 37 0.36 0.31 0.30 0.02
> 38 0.01 0.02 0.97 0.00
> 39 0.12 0.04 0.02 0.82
> 40 0.02 0.00 0.00 0.97
> 41 0.57 0.15 0.02 0.25
> 42 0.14 0.03 0.02 0.82
> 43 0.89 0.06 0.01 0.03
> 44 0.02 0.00 0.00 0.98
> 45 0.61 0.02 0.01 0.36
> 46 0.03 0.00 0.00 0.97
> 47 0.88 0.07 0.02 0.03
> 48 0.06 0.60 0.32 0.02
> 49 0.01 0.98 0.01 0.00
> 50 0.06 0.88 0.05 0.01
> 51 0.01 0.05 0.93 0.00
> 52 0.02 0.08 0.90 0.00
> 53 0.11 0.01 0.01 0.87
> 54 0.27 0.01 0.00 0.72
> 55 0.94 0.03 0.01 0.02
> 58 0.45 0.41 0.05 0.09
> 59 0.12 0.61 0.22 0.05
> 60 0.26 0.07 0.02 0.64
> 61 0.17 0.19 0.62 0.02
> 62 0.08 0.00 0.00 0.92
> 63 0.02 0.94 0.03 0.00
> 64 0.08 0.01 0.00 0.91
> 65 0.98 0.01 0.00 0.01
> 67 0.22 0.69 0.08 0.01
> 68 0.96 0.02 0.00 0.02
> 69 0.96 0.02 0.01 0.01
> 71 0.00 0.01 0.98 0.00
> 72 0.56 0.05 0.01 0.37
> 73 0.10 0.01 0.01 0.88
> 74 0.91 0.01 0.00 0.08
> 75 0.36 0.38 0.21 0.05
> 76 0.15 0.40 0.44 0.01
> 77 0.02 0.06 0.91 0.00
> 78 0.48 0.43 0.03 0.06
> 79 0.51 0.02 0.01 0.45
> 80 0.04 0.01 0.00 0.95
> 81 0.47 0.03 0.01 0.49
> 82 0.98 0.01 0.00 0.01
> 83 0.05 0.01 0.01 0.93
> 84 0.03 0.00 0.00 0.96
> 85 0.76 0.07 0.01 0.15
> 86 0.95 0.03 0.01 0.01
> 88 0.03 0.00 0.00 0.96
> 90 0.79 0.13 0.02 0.06
> 91 0.37 0.50 0.05 0.09
> 92 0.86 0.10 0.02 0.02
> 93 0.13 0.82 0.03 0.01
>
>
>  A[1,][order(A[1,],decreasing=TRUE)]
> [1] 0.66 0.30 0.04 0.01
>
> I want this for every row
> thank you
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/clustering-fuzzy-tp3229853p3229853.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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
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] Maxiter specification in R

2011-01-21 Thread Hongwei Dong
Dear R users,

I'm having a problem with maxiter specification in VGLM function. I tried to
increase the number of iteration to 100, but it still stopped at 30, which
is the default. Here is my script:

FIT <- vglm(SFH_PCT ~ RD_DEN + CAR_HH + TRS + RES_L, tobit(Lower=0), maxiter
= 100)

Thanks

Gary

[[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] Maxiter specification in R

2011-01-21 Thread David Winsemius


On Jan 21, 2011, at 12:34 PM, Hongwei Dong wrote:


Dear R users,

I'm having a problem with maxiter specification in VGLM function. I  
tried to
increase the number of iteration to 100, but it still stopped at 30,  
which

is the default. Here is my script:

FIT <- vglm(SFH_PCT ~ RD_DEN + CAR_HH + TRS + RES_L, tobit(Lower=0),  
maxiter

= 100)


?vglm.control




--

David Winsemius, MD
West Hartford, CT

__
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] number of iterations in a Tobit model

2011-01-21 Thread Terry Therneau
-- begin inclusion ---
I'm running a Tobit model but convergence can not be reached within 30
iterations. Is there anyway I can change the max number of iterations?
Thanks.
--- end inclusion ---

"Tobit" is simply a linear model with censored data.  You don't say how
you are fitting this, but I'll assume you are using survreg
fit <- survreg(Surv(time, status) ~ x1 + x2, dist='gaussian',..)
with appropriate additional arguments to the Surv function if the data
is left or interval censored.

 If survreg doesn't converge in 30 iterations it likely won't converge
in 100 or more. The Newton-Raphson algoritm has gotton lost.  Data sets
with a very large fraction of censored observations can be numerically
challenging.  help(survreg.control) will tell you all the necessary
details however.
  Over the years I have accumulated a few data sets that were very
difficult maximizations for survreg, and led to further tuning of the
underlying algorithm.  Yours would be the first new one in a while; if
you are willing to share it that would help me track down the issue.
You likely will need to use specific starting estimates.

 If you are not using survreg, try it.  Perhaps it is already robust
enough for your data.

Terry Therneau

__
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] randomForest: too many elements specified?

2011-01-21 Thread Liaw, Andy
I grep for "n, n)" in all the R code of the package (current version),
and the only place that happens is in creating proximity.  Can you do a
traceback() and see where it happens?

You should seriously consider upgrading R and the packages...

Andy 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Czerminski, Ryszard
> Sent: Thursday, January 20, 2011 1:08 PM
> To: r-h...@stat.math.ethz.ch
> Subject: [R] randomForest: too many elements specified?
> 
> I getting "Error in matrix(0, n, n) : too many elements specified"
> while building randomForest model, which looks like memory allocation
> error.
> Software versions are: randomForest 4.5-25, R version 2.7.1
> 
> Dataset is big (~90K rows, ~200 columns), but this is on a 
> big machine (
> ~120G RAM)
> and I call randomForest like this: randomForest(x,y)
> i.e. in supervised mode and not requesting proximity matrix, therefore
> answer from Andy Liaw to an email reporting the same problems in 2005
> (see below)
> is probably not directly applicable, still it looks like it is too big
> data set for this dataset/machine combination.
> 
> How does memory usage in randomForest scale with dataset size?
> Is there a way to build global rf model with dataset of this size?
> 
> Best regards,
> Ryszard
> 
> Ryszard Czerminski
> AstraZeneca Pharmaceuticals LP
> 35 Gatehouse Drive
> Waltham, MA 02451
> USA
> 781-839-4304
> ryszard.czermin...@astrazeneca.com
> 
> RE: [R] randomForest: too many element specified?
> Liaw, Andy
> Mon, 17 Jan 2005 05:56:28 -0800
> > From: luk
> >
> > When I run randonForest with a 169453x5 matrix, I got the
> > following message.
> >
> > Error in matrix(0, n, n) : matrix: too many elements specified
> >
> > Can you please advise me how to solve this problem?
> >
> > Thanks,
> >
> > Lu
> 
> 1.  When asking new questions, please don't reply to other posts.
> 
> 2.  When asking questions like these, please do show the commands you
> used.
> 
> My guess is that you asked for the proximity matrix, or is running
> unsupervised randomForest (by not providing a response vector).  This
> will
> requires a couple of n by n matrices to be created (on top of other
> things),
> n being 169453 in this case.  To store a 169453 x 169453 matrix in
> double
> precision, you need 169453^2 * 8 bytes, or or nearly 214 GB of memory.
> Even
> if you have that kind of hardware, I doubt you'll be able to make much
> sense
> out of the result.
> 
> Andy
> 
> 
> 
> --
> 
> Confidentiality Notice: This message is private and may 
> ...{{dropped:11}}
> 
> __
> 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.
> 
Notice:  This e-mail message, together with any attachme...{{dropped:11}}

__
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] nlminb doesn't converge and produce a warning

2011-01-21 Thread Douglas Bates
On Fri, Jan 21, 2011 at 3:51 AM, kamel gaanoun  wrote:
> Hi Everybody,
>
> My problem is that nlminb doesn't converge, in minimising a logLikelihood
> function, with 31*6 parameters(2 weibull parameters+29 regressors repeated 6
> times).

Hmm, the length of the parameter vector shown below is 189, which is
neither 31*6 nor 2 + 29*6.

I suppose it is possible to do nonlinear optimization with box
constraints on such a large number of parameters but you should expect
it to take a long time and perhaps a lot of memory.  Even if the
optimizer converges, it would be optimistic to expect that the
parameter value returned is necessarily the global optimum.  I would
recommend trying to simplify the optimization problem.  A method like
this is just using the computer as a blunt instrument with which to
bludgeon the problem to death (sometimes called the "SAS approach").

>
>
> I use nlminb like this :
> res1<-nlminb(vect, V, lower=c(rep(0.01, 12), rep(0.01, 3), rep(-Inf, n-15)),
> upper=c(rep(Inf, 12), rep(0.99, 3), rep(Inf, n-15)), control =
> list(maxit=1000) )
>
> and that's the result :
>
> Message d'avis :
> In nlminb(vect, V, lower = c(rep(0.01, 12), rep(0.01, 3), rep(-Inf,  :
>  unrecognized control element(s) named `maxit' ignored
>> res1
> $par
>  [1]   2.48843979   4.75209125   2.57199837  16.80712783   3.15211075
> 16.86606178  58.61925499  37.85793462  48.78215699
>  [10] 151.64638501  43.60420299  15.14639541   0.58754382   0.76180935
> 0.66191763  -0.26802757  -0.96378197  -0.68369525
>  [19]   0.37813096   0.89778593 -10.26471908  -0.87265813   6.43973968
> -1.74417166  12.00193419   0.60638326  -1.66675589
>  [28]   1.29312079   1.39846863  -0.48449361  20.14470193  -0.50729841
> -2.15177967  -0.78155345   0.41857810  -0.40863744
>  [37] -17.18489562  -1.69140562   1.45236861  -0.23738183   5.47688642
> -0.71546576   9.95015047  -2.16096138  -0.74503151
>  [46]  -0.66258461   5.38871217   2.53147752 -12.58827379  -0.45669589
> -0.37285088   2.15116198  -2.50414066  -0.99752892
>  [55]   4.83972450  -1.16496925  -3.53429528   0.56083677  -9.87490932
> -1.75153657   9.87912224  -0.75783517  -9.95423392
>  [64]  -0.07530469  -0.73466191  -0.27397382  15.15891548  -0.02489436
> 12.91493065  -4.65335356   0.03524561   0.
>  [73]  -9.06720312  -0.25413758  -0.18578765   0.53283198  -4.02688497
> -0.50581412  -0.31544940   0.57450848   6.15206152
>  [82]   0.08178377   0.82978606   0.39337352  -3.65304712  -0.06833839
> 3.87790848  -1.08017043   3.62779184  -0.14700541
>  [91] -13.95610827  -1.50385432   8.05851743  -1.24250013  -0.01249817
> 0.38085483  -4.97064573  -0.98852401  -3.00305183
> [100]   0.35053875  -4.26833889  -0.12463188  16.05828402   0.41736764
> -0.94678922  -0.75813452   2.15378348   0.39586048
> [109]   1.41359441   0.81603207  -4.43963958  -0.79438435   0.49530882
> 0.11197484  -8.43196798   1.00456535 -22.04423030
> [118]  -0.11532887   2.58085765   1.41912515  -0.78120889  -1.23850824
> 12.39079062   0.23567444   1.39557879  -2.22993802
> [127] -12.58827379  -0.45669589  -0.37285088  -0.73563805   3.40201735
> 0.58550247  -3.62769828   0.21657740  -7.37785506
> [136]  -0.68218180   6.41876225   0.38708385  -0.33009429  -0.25230736
> 3.53672719   1.53676202   3.65074513   0.42623602
> [145]  -7.26982010   0.70597611 -23.15198788  -0.36822845  -2.29863267
> 0.70223129 -14.45665129  -0.54094864  -2.17858443
> [154]  -0.56501734   2.50032796  -0.45677181  12.04113439  -1.42294094
> -16.1687  -0.49101846  -6.29724769  -1.38333722
> [163] -14.16552579   1.57502968   5.04329383   0.24857745  -1.69885428
> -0.46757266   4.41795651  -2.41006349   4.61648610
> [172]   0.42235314  -3.22153895  -0.15443857   1.07661101  -0.63653449
> -2.74034265   0.20898466   1.37927183   0.26722477
> [181] -15.09685067   0.87160467 -24.79722150   1.48810684   1.70068893
> -0.22538026   7.63908028   1.60431981  -7.52661064
>
> $objective
> [1] 1514.691
>
> $convergence
> [1] 1
>
> $message
> [1] "iteration limit reached without convergence (9)"
>
> $iterations
> [1] 150
>
> $evaluations
> function gradient
>     176    44935
>
> I tried many times to take the res1$par as initial values and retry againe
> but still doesn't converge.
>
>
> Any help will save me Thanks
>
> --
> Kamel Gaanoun
> (+33) (0)6.76.04.65.77
>
>        [[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.


Re: [R] nlminb doesn't converge and produce a warning

2011-01-21 Thread Ravi Varadhan
Hi,

It is indeed annoying that each optimization code has different names for the 
parameters that control the behavior of the algorithms.  This is one of the 
reasons that we have developed "optimx" - to unify the calling convention for 
the various algorithms.  You can call the optimization algorithm of your choice 
without having to worry about the names of the control parameters. 

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: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Karl Ove Hufthammer
Sent: Friday, January 21, 2011 6:48 AM
To: r-h...@stat.math.ethz.ch
Subject: Re: [R] nlminb doesn't converge and produce a warning

kamel gaanoun wrote:

> I use nlminb like this :
> res1<-nlminb(vect, V, lower=c(rep(0.01, 12), rep(0.01, 3), rep(-Inf,
> n-15)), upper=c(rep(Inf, 12), rep(0.99, 3), rep(Inf, n-15)), control =
> list(maxit=1000) )
> 
> and that's the result :
> 
> Message d'avis :
> In nlminb(vect, V, lower = c(rep(0.01, 12), rep(0.01, 3), rep(-Inf,  :
> unrecognized control element(s) named `maxit' ignored

Just increase the maximum number of iterations. Which you tried to do, but 
didn’t succeed in, as the above warnings shows. The argument is called 
‘iter.max’, not ‘max.iter’.

-- 
Karl Ove Hufthammer

__
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] Unexpected Gap in simple line plot

2011-01-21 Thread Duncan Murdoch

On 20/01/2011 9:33 PM, D Kelly O'Day wrote:

Bill&  Duncan

Thanks for your quick reply. I would still be looking for days.

Now I have to figure out how the bad data got into cts since I generate this
file each month.


When I read that .csv file in OpenOffice, the lines with the NAs arise 
because the line before has an extra column.  That might be a hint as to 
what's going wrong in the generation...


Duncan Murdoch

__
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] Marginality rule between powers and interaction terms in lm()

2011-01-21 Thread JiHO
Dear all,

I have a model with simple terms, quadratic effects, and interactions.
I am wondering what to do when a variable is involved in a significant
interaction and in a non-significant quadratic effect. Here is an
example

d = data.frame(a=runif(20), b=runif(20))

d$y = d$a + d$b^2

So I create both an simple effect of a and a quadratic effect of b.

m = lm(y ~ a + b + I(a^2) + I(b^2) + a:b, data=d)
drop1(m)
...
   Df Sum of Sq  RSS  AIC
  0.00 -1487.56
I(a^2)  1  0.00 0.00 -1482.04
I(b^2)  1  0.098444 0.098444   -96.28
a:b 1  0.00 0.00 -1488.37

Here R cleverly shows that I can drop a:b or any quadratic term
(suggesting that they have equal marginality?) but not simple terms
since they are marginal to the quadratic or the interaction terms. At
this point the interaction is not significant so the situation is
simple: drop a:b, then drop a^2 and then stop.

Now let's add an interaction

d[d$b > 0.5, "y"] = d[d$b > 0.5, "y"] + 0.01*d[d$b > 0.5, "a"]

m = lm(y ~ a + b + I(a^2) + I(b^2) + a:b, data=d)
summary(m)
...
(Intercept) -3.275e-04  1.585e-03  -0.207  0.83932
a9.988e-01  5.839e-03 171.070  < 2e-16 ***
b   -1.613e-04  5.492e-03  -0.029  0.97698
I(a^2)  -6.515e-05  5.159e-03  -0.013  0.99010
I(b^2)   1.001e+00  4.892e-03 204.593  < 2e-16 ***
a:b  1.191e-02  3.221e-03   3.698  0.00238 **

Now the interaction *is* significant, but a^2 still isn't. drop1()
still suggests that I can remove either the interaction or the
quadratic terms:

drop1(m)
...
   Df Sum of Sq  RSS  AIC
  0.33 -254.306
I(a^2)  1  0.00 0.33 -256.306
I(b^2)  1  0.098611 0.098644  -96.239
a:b 1  0.32 0.65 -242.674

However, this: http://www.stats.ox.ac.uk/pub/MASS3/Exegeses.pdf
suggests that marginality rules between powers of variables might not
be implemented (although they might have been since 2000).

My question is: I am "allowed", according to marginality rules, to remove a^2?

I have found plenty of information on how the coefficients
corresponding to single terms change meaning when a quadratic term or
an interation is involved, and why they should not be removed in most
circumstances. I haven't found anything related to quadratic vs.
interactions.

Thanks in advance for your help. Sincerely,

JiHO
---
http://maururu.net

__
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] extracting random intercept

2011-01-21 Thread Xebar Saram
Hi all

I am using this model for a time series analysis :

lung_new <- (glmmPQL(LUNG ~ 1, random = ~ 1 | GUID, family = poisson, data =
ts0004lag)

Im interested in extracting just the random intercept

can anyone point me in the right direction

thx

zeltak

[[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] Extracting random intercept

2011-01-21 Thread Xebar Saram
Hi all
I am using this model for a time series analysis :
lung_new <- (glmmPQL(LUNG ~ 1, random = ~ 1 | GUID, family = poisson,
data = ts0004lag)
Im interested in extracting just the random intercept
can anyone point me in the right direction
thx
zeltak

__
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] Inconsisten graphics i/o when using Rscript versus GUI

2011-01-21 Thread MacQueen, Don
John,

The first thing I would do is create a simpler example, i.e., to help isolate 
the issue. Here’s a simple example:

The contents of a file are:

#! /usr/bin/Rscript

pdf('test1.pdf')
plot(1:10)
dev.off()

pdf('test2.pdf')
plot(10:1)
dev.off()
--

With this file, I get both pdf files either way.

Since you’re using plotting functions from ggplot2, you may need to wrap 
print() around the qplot() call in the second one. That is,

  print( qplot(fitted(profiles.spl), residuals(profiles.spl)) )

The ‘null device’ message is what dev.off() returns, as in this example:

> x11()
> dev.off()
null device
  1

So it’s not relevant. However, with my simple example above, I get the ‘null 
device’ message twice when I run it as an Rscript.

What’s the first line of your file look like? Try including the -- restore  
   option, if you have not already:

#! /usr/bin/Rscript —restore

Your .RData file is not automatically loaded with Rscript, and the plot that 
isn’t happening may depend on some object that is loaded from .RData. Although, 
in that case, I would expect an error message.

-Don


On 1/20/11 6:53 PM, "John Helly"  wrote:

Hi.

I'm running R OS X GUI 1.35-dev Leopard build 64-bit.  When I run the following 
code (snippet from a larger code) from the GUI I obtain 2 separate *.pdf files 
as you would expect from the high-lighted code.  However, when I run from 
Rscript (command-line), I only get the first one.  No errors appear in the 
console log however I do get a 'null device' message that I don't understand.  
It's probably related but I have no clue how to debug this.  Perhaps the second 
output file is not getting initialized?  I've tried a few variations to see if 
I can unearth the cause but no joy so far.  Any suggestions would be 
appreciated.

Thanks.
...

profiles.spl <- smooth.spline(x, y)
(profiles.spl)
x_pred = seq(1,as.integer(max(x)))
B = data.frame(predict(profiles.spl,x_pred))
pdf(file=paste("/Volumes/SLR_Data_001/USN_SERDP_SLR/data/level1/beach_profiles_Flick/",Filename,".pdf",sep=""))
caption = paste(aLocation," (", aYear,".",aMonth,".",aDay,")",sep="")
credits = paste("splineWriter.R / hel...@ucsd.edu / 20110120")
xrng = range(x)
yrng = range(y)
pred = qplot(x,y, data=B, xlab="Distance (m)", ylab = "Elevation (m)", 
xlim=c(0,1000), ylim=c(-12,4))
pred + geom_text(aes(700,2,label=caption)) + 
geom_text(aes(180,-12,label=credits),size=2.7)
dev.off()
## Residual (Tukey Anscombe) plot:
pdf(file=paste("/Volumes/SLR_Data_001/USN_SERDP_SLR/data/level1/beach_profiles_Flick/",Filename,"TA.pdf",sep=""))
qplot(fitted(profiles.spl), residuals(profiles.spl))
dev.off()

...

--
John Helly, University of California, San Diego / San Diego Supercomputer 
Center / Scripps Institution of Oceanography / stonesteps (Skype) / stonesteps7 
(iChat) / http://www.sdsc.edu/~hellyj
 [[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
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.


Re: [R] complex transformation of data

2011-01-21 Thread Henrique Dallazuanna
Try this:

aggregate(.~ id, lapply(replace(df, is.na(df), ''), as.character), FUN =
paste, collapse = "", na.action = na.pass)

On Fri, Jan 21, 2011 at 5:45 PM, Den  wrote:

> Dear Henrique
> Thank you again for helping me
> Unfortunately, your code seems not to be working
>
> > aggregate(.~ id, lapply(df, as.character), FUN = paste, collapse = "")
>  id cycle1 cycle2 cycle3
> 1  1cmfcmfcmf
> 2  2mfcmfcmfc
> 3  3 cf cf cf
>
> (letter 'a' missing in df[3,c("cycle1",cycle2")]
>
> You suggested very interesting approach, however. Those '.~ id' and
> 'as.character' gave me hope for success.
> With very best regards
> Denis
>
>
> У Пят, 21/01/2011 у 14:16 -0200, Henrique Dallazuanna піша:
> > Try this:
> >
> > aggregate(.~ id, lapply(test, as.character), FUN = paste, collapse =
> > "")
> >
> > On Fri, Jan 21, 2011 at 10:25 AM, Den  wrote:
> > Dear [R] people
> > Could you please help with following data transformation.
> > Any suggestions, hints, references and even guessing on
> > performing any
> > of the following steps are highly appreciated. Those
> > transformations are
> > crucial for my work.
> >
> > (n_, _n, j_, k_ signify numbers)
> >
> > SOURCE DATA:
> > id  cycle1  cycle2  cycle3  …   cycle_n
> > 1   c   c   c   c
> > 1   m   m   m   m
> > 1   f   f   f   f
> > 2   m   m   m   NA
> > 2   f   f   f   NA
> > 2   c   c   c   NA
> > 3   a   a   NA  NA
> > 3   c   c   c   NA
> > 3   f   f   f   NA
> > 3   NA  NA  m   NA
> > ...
> >
> >
> >
> > RESULT DATA1:
> > id  cyc1cyc2cyc3…   cyc_n
> > 1   cfm cfm cfm cfm
> > 2   cfm cfm cfm NA
> > 3   acf acf cfm NA
> > ...
> >
> >
> > RESULT DATA2:
> > id  treatment
> > 1   n_cfm
> > 2   j_cfm
> > 3   2acf->k_cfm
> > ...
> >
> >
> > RESULT DATA3:
> > id  regimen numOfCycles
> > 1   cfm n_
> > 2   cfm j_
> > 3   asf->cfm{2+k_}
> > .
> >
> >
> >
> > Thank you
> > Denis
> >
> > __
> > 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.
> >
> >
> >
> > --
> > Henrique Dallazuanna
> > Curitiba-Paraná-Brasil
> > 25° 25' 40" S 49° 16' 22" O
>
>
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] complex transformation of data

2011-01-21 Thread Henrique Dallazuanna
correction:
aggregate(.~ id, lapply(df, as.character), FUN = paste, collapse = "",
na.action = na.pass)

On Fri, Jan 21, 2011 at 5:56 PM, Henrique Dallazuanna wrote:

> Try this:
>
> aggregate(.~ id, lapply(replace(df, is.na(df), ''), as.character), FUN =
> paste, collapse = "", na.action = na.pass)
>
>
> On Fri, Jan 21, 2011 at 5:45 PM, Den  wrote:
>
>> Dear Henrique
>> Thank you again for helping me
>> Unfortunately, your code seems not to be working
>>
>> > aggregate(.~ id, lapply(df, as.character), FUN = paste, collapse = "")
>>  id cycle1 cycle2 cycle3
>> 1  1cmfcmfcmf
>> 2  2mfcmfcmfc
>> 3  3 cf cf cf
>>
>> (letter 'a' missing in df[3,c("cycle1",cycle2")]
>>
>> You suggested very interesting approach, however. Those '.~ id' and
>> 'as.character' gave me hope for success.
>> With very best regards
>> Denis
>>
>>
>> У Пят, 21/01/2011 у 14:16 -0200, Henrique Dallazuanna піша:
>> > Try this:
>> >
>> > aggregate(.~ id, lapply(test, as.character), FUN = paste, collapse =
>> > "")
>> >
>> > On Fri, Jan 21, 2011 at 10:25 AM, Den  wrote:
>> > Dear [R] people
>> > Could you please help with following data transformation.
>> > Any suggestions, hints, references and even guessing on
>> > performing any
>> > of the following steps are highly appreciated. Those
>> > transformations are
>> > crucial for my work.
>> >
>> > (n_, _n, j_, k_ signify numbers)
>> >
>> > SOURCE DATA:
>> > id  cycle1  cycle2  cycle3  …   cycle_n
>> > 1   c   c   c   c
>> > 1   m   m   m   m
>> > 1   f   f   f   f
>> > 2   m   m   m   NA
>> > 2   f   f   f   NA
>> > 2   c   c   c   NA
>> > 3   a   a   NA  NA
>> > 3   c   c   c   NA
>> > 3   f   f   f   NA
>> > 3   NA  NA  m   NA
>> > ...
>> >
>> >
>> >
>> > RESULT DATA1:
>> > id  cyc1cyc2cyc3…   cyc_n
>> > 1   cfm cfm cfm cfm
>> > 2   cfm cfm cfm NA
>> > 3   acf acf cfm NA
>> > ...
>> >
>> >
>> > RESULT DATA2:
>> > id  treatment
>> > 1   n_cfm
>> > 2   j_cfm
>> > 3   2acf->k_cfm
>> > ...
>> >
>> >
>> > RESULT DATA3:
>> > id  regimen numOfCycles
>> > 1   cfm n_
>> > 2   cfm j_
>> > 3   asf->cfm{2+k_}
>> > .
>> >
>> >
>> >
>> > Thank you
>> > Denis
>> >
>> > __
>> > 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.
>> >
>> >
>> >
>> > --
>> > Henrique Dallazuanna
>> > Curitiba-Paraná-Brasil
>> > 25° 25' 40" S 49° 16' 22" O
>>
>>
>>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] complex transformation of data

2011-01-21 Thread Den
Dear Henrique
Thank you again for helping me
Unfortunately, your code seems not to be working

> aggregate(.~ id, lapply(df, as.character), FUN = paste, collapse = "")
  id cycle1 cycle2 cycle3
1  1cmfcmfcmf
2  2mfcmfcmfc
3  3 cf cf cf

(letter 'a' missing in df[3,c("cycle1",cycle2")] 

You suggested very interesting approach, however. Those '.~ id' and
'as.character' gave me hope for success.
With very best regards   
Denis


У Пят, 21/01/2011 у 14:16 -0200, Henrique Dallazuanna піша:
> Try this:
> 
> aggregate(.~ id, lapply(test, as.character), FUN = paste, collapse =
> "")
> 
> On Fri, Jan 21, 2011 at 10:25 AM, Den  wrote:
> Dear [R] people
> Could you please help with following data transformation.
> Any suggestions, hints, references and even guessing on
> performing any
> of the following steps are highly appreciated. Those
> transformations are
> crucial for my work.
> 
> (n_, _n, j_, k_ signify numbers)
> 
> SOURCE DATA:
> id  cycle1  cycle2  cycle3  …   cycle_n
> 1   c   c   c   c
> 1   m   m   m   m
> 1   f   f   f   f
> 2   m   m   m   NA
> 2   f   f   f   NA
> 2   c   c   c   NA
> 3   a   a   NA  NA
> 3   c   c   c   NA
> 3   f   f   f   NA
> 3   NA  NA  m   NA
> ...
> 
> 
> 
> RESULT DATA1:
> id  cyc1cyc2cyc3…   cyc_n
> 1   cfm cfm cfm cfm
> 2   cfm cfm cfm NA
> 3   acf acf cfm NA
> ...
> 
> 
> RESULT DATA2:
> id  treatment
> 1   n_cfm
> 2   j_cfm
> 3   2acf->k_cfm
> ...
> 
> 
> RESULT DATA3:
> id  regimen numOfCycles
> 1   cfm n_
> 2   cfm j_
> 3   asf->cfm{2+k_}
> .
> 
> 
> 
> Thank you
> Denis
> 
> __
> 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.
> 
> 
> 
> -- 
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O

__
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] Information

2011-01-21 Thread Akash
Hello

I am student of Bioinformatics and I am doin somework in R in which some
problem occurs. So Please help me to solve these problems.
I have two problems:

1. How to generate a graph in which there are 8 rows and 20 columns are
present?
2. And how to put some title in the end of the graph i.e for example after
generating the rows if I want to give the name in the end of those rows like
1,2,3...8.. how can I do this thing?

Right now I am using this code.

graph<- function(X)
{
for(j in 1:8)
  {
  for(k in 1:20)
{
xx<-((j-1)*10)
rect(xx,y(j,k-1,X),(xx)+10,y(j,k,X), col=colmap[k])
if ( X[k,j] != 0)
  {
   text( (xx+5),(y(j,k-1,X) + round(X[k,j])/2), a[k])
  }
 }
  }
}

plot(c(0,10*8),c(0,abc), col="white")

where "a" is sumthing which I have to put inside of those rows and columns


Looking for your positive reply.

Thanking You

With Regards
Akash

[[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] Looping with incremented object name and increment function

2011-01-21 Thread Michael Costello
Folks,

I am trying to get a loop to run which increments the object name as part of
the loop.  Here "fit1" "fit2" "fit3" and "fit4" are linear regression models
that I have created.

> for (ii in c(1:4)){
+ SSE[ii]=rbind(anova(fit[ii])$"Sum Sq")
+ dfe[ii]=rbind(summary(fit[ii])$df)
+ }
Error in anova(fit[ii]) : object 'fit' not found

Why isn't it looking for object 'fit1' instead of 'fit'?

The idea is that it would store in SSE1 the Sum Sq of the model fit1, and so
on for the other 3 models.  Is there a way to do this in R?  I can do it in
Stata, but am only somewhat knowledgeable in R.

-Michael

[[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] Storm Clustering using clusters in evd

2011-01-21 Thread dpender

Hi,

I am using the clusters function in the evd package in order to determine
storm events from a wave time series.

So far I have the code working as I want it for wave height on its own but I
would now like to include the period as well.  The input data is in the form
of:

H t
H t
H t

so every height measurement has a corresponding period.

The storms are defined when the wave height exceeds a certain value and what
I am looking to do is to retain the corresponding periods relating to the
wave heights in the cluster.  This would essentially result in a cluster
with 2 variables.

Does any one have any ideas?

Thanks in advance,

Doug
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Storm-Clustering-using-clusters-in-evd-tp3229951p3229951.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] confidence interval

2011-01-21 Thread Francesco Petrogalli
Hi,
I have a circular shaped set of point on the plane (X,Y) centered in
zero. The distribution is more dense close to zero and less dense far
from zero.

I need to find the radius of a circle centered in zero that contains
65% of the points in the sample. Is there any R directive that can do
this?

I wanna start with 2D set of points, but the real case scenario is
with a 5D set of points.

Thanks,

Francesco

__
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 find data that includes certain values

2011-01-21 Thread poppinkid

I am trying to return an index for a data set by searching using filenames.  

The name may be ANG_AUT.N.0734C70411A-1_1sA_0734C70411A.fasta, but i'd just
like to search it using the term "0734C70411"  as the file may be
0734C70411A or 0734C70411C or 0734C70411D

Any way to do this other than doing something like this.  where 0734C70411A
is part of matrix list[,8]

samp=paste("ANG_AUT.N.",list[i,8],"-1_1sA_",list[i,8],".fasta",sep="")
data[which(data[,2]==samp),]

This is similar to the =~/ / function in perl.


Thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-find-data-that-includes-certain-values-tp3230161p3230161.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] clustering fuzzy

2011-01-21 Thread pete

thank you ,you have been very kind
-- 
View this message in context: 
http://r.789695.n4.nabble.com/clustering-fuzzy-tp3229853p3230228.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] User input in R program

2011-01-21 Thread jverzani
christiaan pauw  gmail.com> writes:

> 
> HI Everybody
> 
> Does anyone know of documentation about different ways of obtaining user
> input in R. I have used readline() but I wondered is there are sophisticated
> packages that does things like validate answers or generate selection
> lists.

You might consider the gWidgets package. Like rpanel, there are many functions 
that make this kind of thing quite easy to implement.

__
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] ordering a vector

2011-01-21 Thread Francesco Petrogalli
Hi,
is there a R function that order a matrix according to some criteria
based on the rows(or cols) of that matrix?

For example, let's say that my matrix S is composed by n rows S_1,
S_2,.., S_n and that I compute some real value g_i=g(S_i) for each
row.
Then I want to order this set of g_i (from smaller to bigger) and
order the correspondent row to the new position.

Is it possible (apart from looping on the index) to do this with some
predefined R function?

Thanks,

Francesco

__
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 find data that includes certain values

2011-01-21 Thread jim holtman
There are several pattern matching functions that will solve your problem:

grep regexpr

do RSiteSearch("pattern match")

On Fri, Jan 21, 2011 at 12:26 PM, poppinkid  wrote:
>
> I am trying to return an index for a data set by searching using filenames.
>
> The name may be ANG_AUT.N.0734C70411A-1_1sA_0734C70411A.fasta, but i'd just
> like to search it using the term "0734C70411"  as the file may be
> 0734C70411A or 0734C70411C or 0734C70411D
>
> Any way to do this other than doing something like this.  where 0734C70411A
> is part of matrix list[,8]
>
> samp=paste("ANG_AUT.N.",list[i,8],"-1_1sA_",list[i,8],".fasta",sep="")
> data[which(data[,2]==samp),]
>
> This is similar to the =~/ / function in perl.
>
>
> Thanks
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/How-to-find-data-that-includes-certain-values-tp3230161p3230161.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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
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 find data that includes certain values

2011-01-21 Thread Henrique Dallazuanna
Take a look on grep function.

On Fri, Jan 21, 2011 at 3:26 PM, poppinkid  wrote:

>
> I am trying to return an index for a data set by searching using filenames.
>
> The name may be ANG_AUT.N.0734C70411A-1_1sA_0734C70411A.fasta, but i'd just
> like to search it using the term "0734C70411"  as the file may be
> 0734C70411A or 0734C70411C or 0734C70411D
>
> Any way to do this other than doing something like this.  where 0734C70411A
> is part of matrix list[,8]
>
> samp=paste("ANG_AUT.N.",list[i,8],"-1_1sA_",list[i,8],".fasta",sep="")
> data[which(data[,2]==samp),]
>
> This is similar to the =~/ / function in perl.
>
>
> Thanks
> --
> View this message in context:
> http://r.789695.n4.nabble.com/How-to-find-data-that-includes-certain-values-tp3230161p3230161.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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[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] complex transformation of data

2011-01-21 Thread Henrique Dallazuanna
Just change the FUN function:

aggregate(.~ id, lapply(df, as.character), FUN = function(x)paste(sort(x),
collapse = ''), na.action = na.pass)

On Fri, Jan 21, 2011 at 6:27 PM, Den  wrote:

>
> Thank you for your efforts.
> Although it is still not working, it feels like getting closer and
> closer.
>
> id cycle1 cycle2 cycle3
> 1  1cmfcmfcmf
> 2  2mfcmfcmfc
> 3  3  acfNA  acfNA  NAcfm
>
> I really appreciate transformation from subsets ("c","m","f") to "cmf".
> That was critical for me.
> Hopefully, I'll figure  out the rest later with ddply from plyr package.
> At least this is my idea for now.
>
>
>
> У Пят, 21/01/2011 у 18:00 -0200, Henrique Dallazuanna піша:
> > correction:
> > aggregate(.~ id, lapply(df, as.character), FUN = paste, collapse = "",
> > na.action = na.pass)
> >
> > On Fri, Jan 21, 2011 at 5:56 PM, Henrique Dallazuanna
> >  wrote:
> > Try this:
> >
> > aggregate(.~ id, lapply(replace(df, is.na(df), ''),
> > as.character), FUN = paste, collapse = "", na.action =
> > na.pass)
> >
> >
> >
> > On Fri, Jan 21, 2011 at 5:45 PM, Den 
> > wrote:
> > Dear Henrique
> > Thank you again for helping me
> > Unfortunately, your code seems not to be working
> >
> > > aggregate(.~ id, lapply(df, as.character), FUN =
> > paste, collapse = "")
> >  id cycle1 cycle2 cycle3
> > 1  1cmfcmfcmf
> > 2  2mfcmfcmfc
> > 3  3 cf cf cf
> >
> > (letter 'a' missing in df[3,c("cycle1",cycle2")]
> >
> > You suggested very interesting approach, however.
> > Those '.~ id' and
> > 'as.character' gave me hope for success.
> > With very best regards
> > Denis
> >
> >
> > У Пят, 21/01/2011 у 14:16 -0200, Henrique Dallazuanna
> > піша:
> >
> > > Try this:
> > >
> > > aggregate(.~ id, lapply(test, as.character), FUN =
> > paste, collapse =
> > > "")
> > >
> > > On Fri, Jan 21, 2011 at 10:25 AM, Den
> >  wrote:
> > > Dear [R] people
> > > Could you please help with following data
> > transformation.
> > > Any suggestions, hints, references and even
> > guessing on
> > > performing any
> > > of the following steps are highly
> > appreciated. Those
> > > transformations are
> > > crucial for my work.
> > >
> > > (n_, _n, j_, k_ signify numbers)
> > >
> > > SOURCE DATA:
> > > id  cycle1  cycle2  cycle3  …
> > cycle_n
> > > 1   c   c   c   c
> > > 1   m   m   m   m
> > > 1   f   f   f   f
> > > 2   m   m   m   NA
> > > 2   f   f   f   NA
> > > 2   c   c   c   NA
> > > 3   a   a   NA  NA
> > > 3   c   c   c   NA
> > > 3   f   f   f   NA
> > > 3   NA  NA  m   NA
> > > ...
> > >
> > >
> > >
> > > RESULT DATA1:
> > > id  cyc1cyc2cyc3…
> > cyc_n
> > > 1   cfm cfm cfm cfm
> > > 2   cfm cfm cfm NA
> > > 3   acf acf cfm NA
> > > ...
> > >
> > >
> > > RESULT DATA2:
> > > id  treatment
> > > 1   n_cfm
> > > 2   j_cfm
> > > 3   2acf->k_cfm
> > > ...
> > >
> > >
> > > RESULT DATA3:
> > > id  regimen numOfCycles
> > > 1   cfm n_
> > > 2   cfm j_
> > > 3 

Re: [R] ordering a vector

2011-01-21 Thread jim holtman
look at 'order'

yourMatrix[order(yourMatrix[, 'yourCol']), ]

On Fri, Jan 21, 2011 at 2:38 PM, Francesco Petrogalli
 wrote:
> Hi,
> is there a R function that order a matrix according to some criteria
> based on the rows(or cols) of that matrix?
>
> For example, let's say that my matrix S is composed by n rows S_1,
> S_2,.., S_n and that I compute some real value g_i=g(S_i) for each
> row.
> Then I want to order this set of g_i (from smaller to bigger) and
> order the correspondent row to the new position.
>
> Is it possible (apart from looping on the index) to do this with some
> predefined R function?
>
> Thanks,
>
> Francesco
>
> __
> 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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
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] ordering a vector

2011-01-21 Thread Peter Langfelder
I think you want the following, assuming you defined your function g():

gValues = apply(S, 1, g);

Sordered = S[order(gValues), ]

Peter

On Fri, Jan 21, 2011 at 11:38 AM, Francesco Petrogalli
 wrote:
> Hi,
> is there a R function that order a matrix according to some criteria
> based on the rows(or cols) of that matrix?
>
> For example, let's say that my matrix S is composed by n rows S_1,
> S_2,.., S_n and that I compute some real value g_i=g(S_i) for each
> row.
> Then I want to order this set of g_i (from smaller to bigger) and
> order the correspondent row to the new position.
>
> Is it possible (apart from looping on the index) to do this with some
> predefined R function?
>
> Thanks,
>
> Francesco
>
> __
> 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] Pearson correlation with randomization

2011-01-21 Thread David Winsemius


On Jan 21, 2011, at 3:29 PM, Brahmachary, Manisha wrote:


Hi David,

Thanks a lot for you inputs. I have modified my code accordingly.  
There

is one more place that I need some help.
This is my code:

= 
= 
==

==

X<- read.table("X.txt",as.is=T,header=T,row.names=1)
Y<- read.table("Y.txt",as.is=T,header=T,row.names=1)

X.mat<- as.matrix(X)
Y.mat<- as.matrix(Y)

# calculating the true correlation values from my original dataset
True.Corrs<- matrix()
for (k in 1:nrow(SNP.mat)){
True.Corrs[k]<- cor.test(X.mat[k,],Y.mat[k,],alternative
=c("greater"),method= c("pearson"))$p.value
}

# Creating the random distribution of Correlation p-values
X.rand <- list()
Y.rand<- list()

X.rand<-replicate(1000,(X[sample(1:ncol(Y))]),simplify=FALSE)  #
Randomizing the column values for each row
Y.rand<-replicate(1000,Y,simplify=FALSE) # Creating an equivalent list
of the Y matrix (non-randomised), to be able to do a pair-wise  
cor.test


Corrs.rand<- list()
tmp<- list()
for (i in 1:2){
for (j in 1:3){
# How to store a multiple values per element of list?
tmp[[j]] <- cor.test(t(X.rand[[i]][j,]),t(Y.rand[[i]][j,]),alternative
=c("greater"),method= c("pearson"))$p.value
Corrs.rand[[i]] <- rbind(Corrs.rand[[j]],tmp[[j]])
}
}

= 
= 
==


At this step:

for (i in 1:length(X.rand)){
for (j in 1:nrow(X.rand[[1]]){
# How to store a multiple values per element of list?
tmp[[j]] <- cor.test(t(X.rand[[i]][j,]),t(Y.rand[[i]][j,]),alternative
=c("greater"),method= c("pearson"))$p.value
Corrs.rand[[i]] <- rbind(Corrs.rand[[j]],tmp[[j]])
}
}

I am not sure how I can store multiple values per element.


The usual way would be to pre-allocate a matrix or a data.frame and  
then use "[<-" to assign either a  whole row at a time or assign  
individual elements one by one. rbind in a loop is definitely going to  
slow you down.


I haven't followed through the individual steps of all the for-loops.  
I guess I have lost the ability to think that way after learning to  
use the matrix and indexing features of R, alas. If Corrs.rand is a  
1000 x 12  data.frame (which is just a special square list) then you  
can assign the i-th row with:


Corrs.rand[i, ] <- 

Or you can assign the i,j-th element with:

Corrs.rand[i,j ] <- 

The same syntax works for matrices.
--
David.


For eg. I
want a list of length 1000 (which is the number of random  
permutations I
have generated for my dataset) and in each element of the list I  
need to

store 12 p.values where 12 corresponds to the number of rows I have in
my randomized dataset. Eg.

[[1]]
0.23
0.05
0.78
0.78
0.87
0.11
0.003
0.9
0.76
0.11
0.23
0.56
[[2]]
0.08
0.67
0.45
0.23
0.35
0.85
0.99
0.78
0.66
0.45
0.06
0.1
[[3]]
So on...

I maybe going about this in a complicated way and there may be other
ways of storing the p.values for each of my randomized dataset. So if
anybody has ideas please oblige me.
==
X dataset:(sample)
#Probes X10851  X12144  X12155  X11882  X10860  X12762  X12239  X12154
1   1   1   0   0   1   0   2   0
2   0   0   0   0   0   0   0   0
3   2   2   2   2   1   2   1   2
4   0   0   0   0   0   0   0   0
5   2   2   2   2   2   2   2   2
6   0   1   0   0   1   1   1   1
7   2   2   NaN 2   2   2   2   2
8   2   2   2   2   2   2   2   2
9   0   1   0   1   1   NaN 1   2
10  2   2   2   2   2   2   2   2
11  2   0   0   0   0   0   0   0
12  0   1   0   1   1   0   1   1


Y dataset:(sample)

Probes  X10851  X12144  X12155  X11882  X10860  X12762  X12239  X12154
1   793.0830793 788.1813828 867.8504057 729.8321265
816.8519963 805.2113707 774.5990003 854.6384306
2   12.8695023  4.312894024 10.69769375 5.872212512
13.79299806 9.394132659 6.297552848 9.307943304
3   699.7791876 826.997429  795.6409729 770.9376141
806.1241089 782.3970486 817.107482  859.7154906
4   892.8217221 869.0481458 806.3386667 812.0431017
873.5565439 794.4752191 813.9587056 814.8681274
5   892.8217221 869.0481458 806.3386667 812.0431017
873.5565439 794.4752191 813.9587056 814.8681274
6   839.7350251 943.4455677 950.7575323 859.0208018
894.246041  853.524053  941.4841508 913.0246205
7   653.1272418 751.5217836 750.1757745 737.382114
757.8486157 758.2407075 724.2185775 770.8669409
8   12.8695023  4.312894024 10.69769375 5.872212512
13.792

Re: [R] Information

2011-01-21 Thread David Winsemius


On Jan 21, 2011, at 2:59 PM, Akash wrote:


Hello

I am student of Bioinformatics and I am doin somework in R in which  
some

problem occurs. So Please help me to solve these problems.
I have two problems:

1. How to generate a graph in which there are 8 rows and 20 columns  
are

present?
2. And how to put some title in the end of the graph i.e for example  
after
generating the rows if I want to give the name in the end of those  
rows like

1,2,3...8.. how can I do this thing?


matplot will let you specify the plotting character with the pch  
argument. Coloring is also available and legends are reasonably simple  
as well.


?matplot
?legend

If you had presented data with the dput() function I would have  
returned working code, But I have gotten tired of making up examples  
when people don't post their own sample data.


--
David.


Right now I am using this code.

graph<- function(X)
{
for(j in 1:8)
 {
 for(k in 1:20)
   {
   xx<-((j-1)*10)
   rect(xx,y(j,k-1,X),(xx)+10,y(j,k,X), col=colmap[k])
   if ( X[k,j] != 0)
 {
  text( (xx+5),(y(j,k-1,X) + round(X[k,j])/2), a[k])
 }
}
 }
}

plot(c(0,10*8),c(0,abc), col="white")

where "a" is sumthing which I have to put inside of those rows and  
columns



Looking for your positive reply.

Thanking You

With Regards
Akash

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


David Winsemius, MD
West Hartford, CT

__
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] confidence interval

2011-01-21 Thread David Winsemius


On Jan 21, 2011, at 11:33 AM, Francesco Petrogalli wrote:


Hi,
I have a circular shaped set of point on the plane (X,Y) centered in
zero. The distribution is more dense close to zero and less dense far
from zero.

I need to find the radius of a circle centered in zero that contains
65% of the points in the sample. Is there any R directive that can do
this?

I wanna start with 2D set of points, but the real case scenario is
with a 5D set of points.


Something along the lines of

dxy= with(dfm, sqrt(x^2 +y^2))
quantile(dxy, probs=0.65)

The generalization to 5 dimensions appears trivial. Even the  
generalization to finding the radius around an arbitrary point seems  
trivial assuming an L2 norm.


--
David Winsemius, MD
West Hartford, CT

__
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] Looping with incremented object name and increment function

2011-01-21 Thread Greg Snow
This is FAQ 7.21.

The real gem in the answer there is at the end where it tells you that it is 
easier to just use a list.  If your fit1, fit2, fit3, and fit4 were elements in 
a list then you can just loop through the list elements, or even easier use the 
lapply function to loop through the list elements for you.

The syntax fit[ii] means that you want the ii'th element of the vector named 
"fit", the FAQ shows how to do what you want, but in the long run (and the 
medium run, and even the short run) using a list instead of separate global 
variables will make your life easier.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Michael Costello
> Sent: Friday, January 21, 2011 9:43 AM
> To: r-help@r-project.org
> Subject: [R] Looping with incremented object name and increment
> function
> 
> Folks,
> 
> I am trying to get a loop to run which increments the object name as
> part of
> the loop.  Here "fit1" "fit2" "fit3" and "fit4" are linear regression
> models
> that I have created.
> 
> > for (ii in c(1:4)){
> + SSE[ii]=rbind(anova(fit[ii])$"Sum Sq")
> + dfe[ii]=rbind(summary(fit[ii])$df)
> + }
> Error in anova(fit[ii]) : object 'fit' not found
> 
> Why isn't it looking for object 'fit1' instead of 'fit'?
> 
> The idea is that it would store in SSE1 the Sum Sq of the model fit1,
> and so
> on for the other 3 models.  Is there a way to do this in R?  I can do
> it in
> Stata, but am only somewhat knowledgeable in R.
> 
> -Michael
> 
>   [[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] Help with LMSreg

2011-01-21 Thread eniven

I'm doing regression with least median squares (LMS) using the lmsreg
command. I've got the coefficients (slope and intercept), but how do I get
the LMS correlation coefficient?

Thanks, in advance, for any help!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Help-with-LMSreg-tp3230611p3230611.html
Sent from the R help mailing list archive at Nabble.com.

[[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] complex transformation of data

2011-01-21 Thread Den

Thank you for your efforts.
Although it is still not working, it feels like getting closer and
closer. 
  
id cycle1 cycle2 cycle3
1  1cmfcmfcmf
2  2mfcmfcmfc
3  3  acfNA  acfNA  NAcfm

I really appreciate transformation from subsets ("c","m","f") to "cmf".
That was critical for me.
Hopefully, I'll figure  out the rest later with ddply from plyr package.
At least this is my idea for now.



У Пят, 21/01/2011 у 18:00 -0200, Henrique Dallazuanna піша:
> correction:
> aggregate(.~ id, lapply(df, as.character), FUN = paste, collapse = "",
> na.action = na.pass)
> 
> On Fri, Jan 21, 2011 at 5:56 PM, Henrique Dallazuanna
>  wrote:
> Try this:
> 
> aggregate(.~ id, lapply(replace(df, is.na(df), ''),
> as.character), FUN = paste, collapse = "", na.action =
> na.pass)
> 
> 
> 
> On Fri, Jan 21, 2011 at 5:45 PM, Den 
> wrote:
> Dear Henrique
> Thank you again for helping me
> Unfortunately, your code seems not to be working
> 
> > aggregate(.~ id, lapply(df, as.character), FUN =
> paste, collapse = "")
>  id cycle1 cycle2 cycle3
> 1  1cmfcmfcmf
> 2  2mfcmfcmfc
> 3  3 cf cf cf
> 
> (letter 'a' missing in df[3,c("cycle1",cycle2")]
> 
> You suggested very interesting approach, however.
> Those '.~ id' and
> 'as.character' gave me hope for success.
> With very best regards
> Denis
> 
> 
> У Пят, 21/01/2011 у 14:16 -0200, Henrique Dallazuanna
> піша:
> 
> > Try this:
> >
> > aggregate(.~ id, lapply(test, as.character), FUN =
> paste, collapse =
> > "")
> >
> > On Fri, Jan 21, 2011 at 10:25 AM, Den
>  wrote:
> > Dear [R] people
> > Could you please help with following data
> transformation.
> > Any suggestions, hints, references and even
> guessing on
> > performing any
> > of the following steps are highly
> appreciated. Those
> > transformations are
> > crucial for my work.
> >
> > (n_, _n, j_, k_ signify numbers)
> >
> > SOURCE DATA:
> > id  cycle1  cycle2  cycle3  …
> cycle_n
> > 1   c   c   c   c
> > 1   m   m   m   m
> > 1   f   f   f   f
> > 2   m   m   m   NA
> > 2   f   f   f   NA
> > 2   c   c   c   NA
> > 3   a   a   NA  NA
> > 3   c   c   c   NA
> > 3   f   f   f   NA
> > 3   NA  NA  m   NA
> > ...
> >
> >
> >
> > RESULT DATA1:
> > id  cyc1cyc2cyc3…
> cyc_n
> > 1   cfm cfm cfm cfm
> > 2   cfm cfm cfm NA
> > 3   acf acf cfm NA
> > ...
> >
> >
> > RESULT DATA2:
> > id  treatment
> > 1   n_cfm
> > 2   j_cfm
> > 3   2acf->k_cfm
> > ...
> >
> >
> > RESULT DATA3:
> > id  regimen numOfCycles
> > 1   cfm n_
> > 2   cfm j_
> > 3   asf->cfm{2+k_}
> > .
> >
> >
> >
> > Thank you
> > Denis
> >
> >
> _

[R] building package

2011-01-21 Thread las65
I have built a package that I would like to submit to the CRAN. When I perform 
a R CMD 
check I get the following warning: 
* checking Rd cross-references ... WARNING
Error in .find.package(package, lib.loc) : 
  there is no package called 'foreign'
Calls:  -> lapply -> FUN -> .find.package
Execution halted

I believe this has to do with the fact I use mapply function utilizing internal 
functions I have within the package? Am I wrong in this assumption? How would I 
remedy 
this in order to get rid of the warning? 

Any advice is appreciated. 
Thank you 
Lori 

__
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] Pearson correlation with randomization

2011-01-21 Thread Brahmachary, Manisha
Hi David,

Thanks a lot for you inputs. I have modified my code accordingly. There
is one more place that I need some help.
This is my code:


==

X<- read.table("X.txt",as.is=T,header=T,row.names=1)
Y<- read.table("Y.txt",as.is=T,header=T,row.names=1)

X.mat<- as.matrix(X)
Y.mat<- as.matrix(Y)

# calculating the true correlation values from my original dataset
True.Corrs<- matrix()
for (k in 1:nrow(SNP.mat)){
True.Corrs[k]<- cor.test(X.mat[k,],Y.mat[k,],alternative
=c("greater"),method= c("pearson"))$p.value
}

# Creating the random distribution of Correlation p-values
X.rand <- list()
Y.rand<- list()

X.rand<-replicate(1000,(X[sample(1:ncol(Y))]),simplify=FALSE)  #
Randomizing the column values for each row
Y.rand<-replicate(1000,Y,simplify=FALSE) # Creating an equivalent list
of the Y matrix (non-randomised), to be able to do a pair-wise cor.test

Corrs.rand<- list()
tmp<- list()
for (i in 1:2){
for (j in 1:3){
# How to store a multiple values per element of list?
tmp[[j]] <- cor.test(t(X.rand[[i]][j,]),t(Y.rand[[i]][j,]),alternative
=c("greater"),method= c("pearson"))$p.value
Corrs.rand[[i]] <- rbind(Corrs.rand[[j]],tmp[[j]])
}
}



At this step:

for (i in 1:length(X.rand)){
for (j in 1:nrow(X.rand[[1]]){
# How to store a multiple values per element of list?
tmp[[j]] <- cor.test(t(X.rand[[i]][j,]),t(Y.rand[[i]][j,]),alternative
=c("greater"),method= c("pearson"))$p.value
Corrs.rand[[i]] <- rbind(Corrs.rand[[j]],tmp[[j]])
}
}

I am not sure how I can store multiple values per element. For eg. I
want a list of length 1000 (which is the number of random permutations I
have generated for my dataset) and in each element of the list I need to
store 12 p.values where 12 corresponds to the number of rows I have in
my randomized dataset. Eg.

[[1]]
0.23
0.05
0.78
0.78
0.87
0.11
0.003
0.9
0.76
0.11
0.23
0.56
[[2]]
0.08
0.67
0.45
0.23
0.35
0.85
0.99
0.78
0.66
0.45
0.06
0.1
[[3]]
So on... 
 
I maybe going about this in a complicated way and there may be other
ways of storing the p.values for each of my randomized dataset. So if
anybody has ideas please oblige me.
==
X dataset:(sample)
#Probes X10851  X12144  X12155  X11882  X10860  X12762  X12239  X12154
1   1   1   0   0   1   0   2   0
2   0   0   0   0   0   0   0   0
3   2   2   2   2   1   2   1   2
4   0   0   0   0   0   0   0   0
5   2   2   2   2   2   2   2   2
6   0   1   0   0   1   1   1   1
7   2   2   NaN 2   2   2   2   2
8   2   2   2   2   2   2   2   2
9   0   1   0   1   1   NaN 1   2
10  2   2   2   2   2   2   2   2
11  2   0   0   0   0   0   0   0
12  0   1   0   1   1   0   1   1


Y dataset:(sample)

Probes  X10851  X12144  X12155  X11882  X10860  X12762  X12239  X12154
1   793.0830793 788.1813828 867.8504057 729.8321265
816.8519963 805.2113707 774.5990003 854.6384306
2   12.8695023  4.312894024 10.69769375 5.872212512
13.79299806 9.394132659 6.297552848 9.307943304
3   699.7791876 826.997429  795.6409729 770.9376141
806.1241089 782.3970486 817.107482  859.7154906
4   892.8217221 869.0481458 806.3386667 812.0431017
873.5565439 794.4752191 813.9587056 814.8681274
5   892.8217221 869.0481458 806.3386667 812.0431017
873.5565439 794.4752191 813.9587056 814.8681274
6   839.7350251 943.4455677 950.7575323 859.0208018
894.246041  853.524053  941.4841508 913.0246205
7   653.1272418 751.5217836 750.1757745 737.382114
757.8486157 758.2407075 724.2185775 770.8669409
8   12.8695023  4.312894024 10.69769375 5.872212512
13.79299806 9.394132659 6.297552848 9.307943304
9   839.7350251 943.4455677 950.7575323 859.0208018
894.246041  853.524053  941.4841508 913.0246205
10  653.1272418 751.5217836 750.1757745 737.382114
757.8486157 758.2407075 724.2185775 770.8669409
11  653.1272418 751.5217836 750.1757745 737.382114
757.8486157 758.2407075 724.2185775 770.8669409
12  839.7350251 943.4455677 950.7575323 859.0208018
894.246041  853.524053  941.4841508 913.0246205

Thanks again

Manisha




-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Tuesday, January 18, 2011 11:56 PM
To: Brahmachary, Manisha
Cc: R-help@r-project

[R] TRADUCING lmer() syntax into lme()

2011-01-21 Thread Freddy Gamma
-- Forwarded message --
From: Freddy Gamma 
Date: 2011/1/21
Subject: TRADUCING lmer() syntax into lme()
To: r-sig-mixed-mod...@r-project.org


Dear Rsociety,

I'd like to kingly ask to anyone is willing to answer me how to implement a
NON NESTED random effects structure in lme()


In particular I've tried the following translation from lmer to lme, as
suggested from some web example




mod1<-lmer(y~x*z+(x*z|factorA1/factorB)+(x*z|factorA2/factorB))  # y,x,z
continuous

mod2<-lme(y~x*z, random= pdBlocked(list(pdIdent(~1|factorA1/factorB
),pdIdent(~1|factorA2/factorB


In detail check how I've tried to state in mod1 that Iwant to evaluate
randomness in the interaction x*z (i.e intercept, slope, interaction)
grouped by by a general nesting structure that sets factorA1 and factorA2 as
same level effects (hence non nested) and factorB as nested in both.

I also must express my momentaneous sheer ignorange on the pdMat objects,
thing that prabably is not helping me in the process



Kindly Regards


Federico Bonofiglio

[[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] glitch in building R package

2011-01-21 Thread Horace Tso
I follow Alan Lenarcic's very helpful tutorial on building R package for 
Windows (XP), which could be found in 
www.stat.columbia.edu/~gelman/stuff_for_blog/AlanRPackageTutorial.pdf.
 The package involves a small dll compiled from some very simple C++ codes.

The build process seemed to work smoothly, until i install. Then I got an error 
saying the C function was not in the load table. This is rather mysterious 
because I've been able to call this function from R with dyn.load("name.dll"). 
So the dll is working.

The install error says :

C:\R-test>R CMD INSTALL --build FirstPack_0.1.tar.gz
* installing to library 'c:/R/R-2.12.0/library'
* installing *source* package 'FirstPack' ...
** libs
cygwin warning:
  MS-DOS style path detected: c:/R/R-2.12.0/etc/i386/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/R/R-2.12.0/etc/i386/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
g++ -I"c:/R/R-2.12.0/include" -O2 -Wall  -c XDemo.cpp -o XDemo.o
g++ -I"c:/R/R-2.12.0/include" -O2 -Wall  -c XDemo_main.cpp -o XDemo_main
.o
g++ -shared -s -static-libgcc -o FirstPack.dll tmp.def XDemo.o XDemo_main.o -Lc:
/R/R-2.12.0/bin/i386 -lR
installing to c:/R/R-2.12.0/library/FirstPack/libs/i386
** R
** data
Warning: empty 'data' directory
** preparing package for lazy loading
Error in .C("DemoAutoCor", OutVec = as.double(vector("numeric", OutLength)),  :

  C symbol name "DemoAutoCor" not in load table
ERROR: lazy loading failed for package 'FirstPack'
* removing 'c:/R/R-2.12.0/library/FirstPack'
Here is how i built the package. I have the directory structure as described in 
"Writing R Extensions" and I issued the following command in DOS prompt,

C:\R-test>R CMD build FirstPack
* checking for file 'FirstPack/DESCRIPTION' ... OK
* preparing 'FirstPack':
* checking DESCRIPTION meta-information ... OK
* cleaning src
cygwin warning:
  MS-DOS style path detected: C:/R-test/FirstPack_0.1.tar
  Preferred POSIX equivalent is: /cygdrive/c/R-test/FirstPack_0.1.tar
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
cygwin warning:
  MS-DOS style path detected: C:/R-test/FirstPack_0.1.tar
  Preferred POSIX equivalent is: /cygdrive/c/R-test/FirstPack_0.1.tar
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Warning in readLines(ldpath) :
  incomplete final line found on 'FirstPack/DESCRIPTION'
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
WARNING: directory 'FirstPack/data' is empty
* building 'FirstPack_0.1.tar.gz'
cygwin warning:
  MS-DOS style path detected: C:/R-test/FirstPack_0.1.tar
  Preferred POSIX equivalent is: /cygdrive/c/R-test/FirstPack_0.1.tar
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
cygwin warning:
  MS-DOS style path detected: C:/R-test/FirstPack_0.1.tar
  Preferred POSIX equivalent is: /cygdrive/c/R-test/FirstPack_0.1.tar
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames

Thanks in advance.

H



[[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] building package

2011-01-21 Thread Duncan Murdoch

On 11-01-21 3:33 PM, la...@buffalo.edu wrote:

I have built a package that I would like to submit to the CRAN. When I perform 
a R CMD
check I get the following warning:
* checking Rd cross-references ... WARNING
Error in .find.package(package, lib.loc) :
   there is no package called 'foreign'
Calls:  ->  lapply ->  FUN ->  .find.package
Execution halted

I believe this has to do with the fact I use mapply function utilizing internal
functions I have within the package? Am I wrong in this assumption? How would I 
remedy
this in order to get rid of the warning?


This message is about your documentation files, not your R code.  Search 
your .Rd files for "foreign" and either remove the reference, or add a 
Depends statement to your DESCRIPTION saying you depend on the foreign 
package.


Duncan Murdoch



Any advice is appreciated.
Thank you
Lori

__
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] How to find data that includes certain values

2011-01-21 Thread Den
Hello
Consider following dataframe named df


var1var2var3
3771354 565
654654  963 6677
775 147 657754

df <- read.table('clipboard', header = TRUE)
df
#find indexes with '77' in var 1
myIndexes <- grep( glob2rx("*77*"), df$var1)
myIndexes
#find actual values of seach above
myValu <- grep( glob2rx("*77*"), df$var1, value=TRUE)
myValu
#find all '77' in entire dataframe
all77 <- lapply(df, function(x)grep( glob2rx("*77*"), x, value=TRUE))
all77
#OR indexes
all77ind <-lapply(df, function(x)grep( glob2rx("*77*"), x))
all77ind


Hope that helps
With best regards
Denis

__
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] complex transformation of data

2011-01-21 Thread Den
That great! It's working! Thank you so much!
It is a pure magic which makes my head spin.
aggregate(.~ id, lapply(df, as.character), FUN =
function(x)paste(sort(x), collapse = ''), na.action = na.pass)

1. help says:
 Note that ‘paste()’ coerces ‘NA_character_’, the character missing
value, to ‘"NA"'
And at the same time:
 ‘na.pass’ returns the object unchanged.
I am happy, that I don't have NAs in mydata.  I just don't understand
how
it happened.
2. Can't see the real difference between 'FUN = function(x) paste(x)'
and 'FUN = paste'. However, former working perfectly while latter simply
not.
3.Finally, all help says about LHS in formulas like '.~id' is that it's
name is "dot notation". And not a single word more. Thus, I have no
clue, what dot in that formula really means.


Conclusion:
1. It's a magic. 
2. You definitely saved my investigation. (When I've started I had no
idea it would be so difficult to arrange those chemotherapy cycles in
dataframe, although I dare to call myself pharmacoepidemiologist (which
sounds rather funny after that story))
3. THANK YOU!!

Sincerely yours 
Denis Kazakiewicz
Belarus 


У Пят, 21/01/2011 у 18:37 -0200, Henrique Dallazuanna піша:
> Just change the FUN function:
> 
> aggregate(.~ id, lapply(df, as.character), FUN =
> function(x)paste(sort(x), collapse = ''), na.action = na.pass)
> 
> On Fri, Jan 21, 2011 at 6:27 PM, Den  wrote:
> 
> Thank you for your efforts.
> Although it is still not working, it feels like getting closer
> and
> closer.
> 
> id cycle1 cycle2 cycle3
> 1  1cmfcmfcmf
> 2  2mfcmfcmfc
> 
> 3  3  acfNA  acfNA  NAcfm
> 
> I really appreciate transformation from subsets ("c","m","f")
> to "cmf".
> That was critical for me.
> Hopefully, I'll figure  out the rest later with ddply from
> plyr package.
> At least this is my idea for now.
> 
> 
> 
> У Пят, 21/01/2011 у 18:00 -0200, Henrique Dallazuanna піша:
> 
> > correction:
> > aggregate(.~ id, lapply(df, as.character), FUN = paste,
> collapse = "",
> > na.action = na.pass)
> >
> > On Fri, Jan 21, 2011 at 5:56 PM, Henrique Dallazuanna
> >  wrote:
> > Try this:
> >
> > aggregate(.~ id, lapply(replace(df, is.na(df), ''),
> > as.character), FUN = paste, collapse = "", na.action
> =
> > na.pass)
> >
> >
> >
> > On Fri, Jan 21, 2011 at 5:45 PM, Den
> 
> > wrote:
> > Dear Henrique
> > Thank you again for helping me
> > Unfortunately, your code seems not to be
> working
> >
> > > aggregate(.~ id, lapply(df, as.character),
> FUN =
> > paste, collapse = "")
> >  id cycle1 cycle2 cycle3
> > 1  1cmfcmfcmf
> > 2  2mfcmfcmfc
> > 3  3 cf cf cf
> >
> > (letter 'a' missing in
> df[3,c("cycle1",cycle2")]
> >
> > You suggested very interesting approach,
> however.
> > Those '.~ id' and
> > 'as.character' gave me hope for success.
> > With very best regards
> > Denis
> >
> >
> > У Пят, 21/01/2011 у 14:16 -0200, Henrique
> Dallazuanna
> > піша:
> >
> > > Try this:
> > >
> > > aggregate(.~ id, lapply(test,
> as.character), FUN =
> > paste, collapse =
> > > "")
> > >
> > > On Fri, Jan 21, 2011 at 10:25 AM, Den
> >  wrote:
> > > Dear [R] people
> > > Could you please help with
> following data
> > transformation.
> > > Any suggestions, hints, references
> and even
> > guessing on
> > > performing any
> > > of the following steps are highly
> > appreciated. Those
> > > transformations are
> > > crucial for my work.
> > >
> > > (n_, _n, j_, k_ signify numbers)
> > >
> > > SOURCE DATA:
>   

[R] lm(y ~ x1) vs. lm(y ~ x0 + x1 - 1) with x0 <- rep(1, length(y))

2011-01-21 Thread jochen laubrock
Dear list,

the following came up in an introductory class. Please help me understand the 
-1 (or 0+) syntax in formulae: Why do the enumerator dfs, F-statisics etc. 
differ between the models lm(y ~ x1) and lm(y ~ x0 + x1 - 1), if x0 is a vector 
containing simply ones?

Example:

N  <- 40
x0 <- rep(1,N)
x1 <- 1:N
vare <- N/8
set.seed(4)
e <- rnorm(N, 0, vare^2)

X <- cbind(x0, x1)
beta <- c(.4, 1)
y <- X %*% beta + e

summary(lm(y ~ x1))
# [...]
# Residual standard error: 20.92 on 38 degrees of freedom
# Multiple R-squared: 0.1151,   Adjusted R-squared: 0.09182 
# F-statistic: 4.943 on 1 and 38 DF,  p-value: 0.03222 

summary(lm(y ~ x0 + x1 - 1))# or summary(lm(y ~ 0 + x0 + x1))
# [...]
# Residual standard error: 20.92 on 38 degrees of freedom
# Multiple R-squared: 0.6888,   Adjusted R-squared: 0.6724
# F-statistic: 42.05 on 2 and 38 DF,  p-value: 2.338e-10 


Thanks in advance,
Jochen



Jochen Laubrock, Dept. of Psychology, University of Potsdam,
Karl-Liebknecht-Strasse 24-25, 14476 Potsdam, Germany
phone: +49-331-977-2346, fax: +49-331-977-2793

__
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] Looping with incremented object name and increment function

2011-01-21 Thread Dennis Murphy
Hi:

Here's an example of how to extract pieces from model objects using the plyr
package. I'm using the attitude data set from the datasets package
(autoloaded).

# Generate four models
m1 <- lm(rating ~ ., data = attitude)
m2 <- lm(rating ~ complaints + learning, data = attitude)
m3 <- lm(rating ~ complaints * learning, data = attitude)
m4 <- lm(rating ~ complaints, data = attitude)
# Combine them into a list
mlist <- list(m1 = m1, m2 = m2, m3 = m3, m4 = m4)

# Utility functions:
# In this context, x represents a generic model object. We want
# to extract the same information from each object.
# Can package these (or others) into a single function if you
# wish to output a list object.

# Sums of squares extraction:
ss <- function(x) summary(x)$coefficients[, 2]

# R^2
r2 <- function(x) summary(x)$r.squared

# Model and residual df:
dfs <- function(x) summary(x)$df[1:2]

# ldply() takes a list object as input and returns a data frame object
# llply() takes a list object as input and returns a list
# Each call applies a utility function to each component model in the list
library(plyr)
ldply(mlist, r2)
ldply(mlist, dfs)
llply(mlist, ss)

HTH,
Dennis

On Fri, Jan 21, 2011 at 8:42 AM, Michael Costello <
michaelavcoste...@gmail.com> wrote:

> Folks,
>
> I am trying to get a loop to run which increments the object name as part
> of
> the loop.  Here "fit1" "fit2" "fit3" and "fit4" are linear regression
> models
> that I have created.
>
> > for (ii in c(1:4)){
> + SSE[ii]=rbind(anova(fit[ii])$"Sum Sq")
> + dfe[ii]=rbind(summary(fit[ii])$df)
> + }
> Error in anova(fit[ii]) : object 'fit' not found
>
> Why isn't it looking for object 'fit1' instead of 'fit'?
>
> The idea is that it would store in SSE1 the Sum Sq of the model fit1, and
> so
> on for the other 3 models.  Is there a way to do this in R?  I can do it in
> Stata, but am only somewhat knowledgeable in R.
>
> -Michael
>
>[[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.
>

[[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] lm(y ~ x1) vs. lm(y ~ x0 + x1 - 1) with x0 <- rep(1, length(y))

2011-01-21 Thread David Winsemius


On Jan 21, 2011, at 9:03 PM, jochen laubrock wrote:


Dear list,

the following came up in an introductory class. Please help me  
understand the -1 (or 0+) syntax in formulae: Why do the enumerator  
dfs, F-statisics etc. differ between the models lm(y ~ x1) and lm(y  
~ x0 + x1 - 1), if x0 is a vector containing simply ones?


You are testing something different. In the first case you are testing  
the difference between the baseline and the second level of x1 (so  
there is only one d.f.), while in the second case you are testing for  
both of the coefficients being zero (so the numerator has 2 d.f.). It  
would be easier to see if you did print() on the fit object. The first  
model would give you an estimate for an "Intercept", which is really  
an estimate for the first level of x1.  Having been taught to think of  
anova as just a special case of regression is helpful here. Look at  
the model first  and only then look at the anova table.





Example:

N  <- 40
x0 <- rep(1,N)
x1 <- 1:N
vare <- N/8
set.seed(4)
e <- rnorm(N, 0, vare^2)

X <- cbind(x0, x1)
beta <- c(.4, 1)
y <- X %*% beta + e

summary(lm(y ~ x1))
# [...]
# Residual standard error: 20.92 on 38 degrees of freedom
# Multiple R-squared: 0.1151,   Adjusted R-squared: 0.09182
# F-statistic: 4.943 on 1 and 38 DF,  p-value: 0.03222

summary(lm(y ~ x0 + x1 - 1))# or summary(lm(y ~ 0 + x0 + x1))
# [...]
# Residual standard error: 20.92 on 38 degrees of freedom
# Multiple R-squared: 0.6888,   Adjusted R-squared: 0.6724
# F-statistic: 42.05 on 2 and 38 DF,  p-value: 2.338e-10


Thanks in advance,
Jochen



Jochen Laubrock, Dept. of Psychology, University of Potsdam,
Karl-Liebknecht-Strasse 24-25, 14476 Potsdam, Germany
phone: +49-331-977-2346, fax: +49-331-977-2793

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


David Winsemius, MD
West Hartford, CT

__
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 - Vectorization and Functional Programming Constructs

2011-01-21 Thread Mingo
Hello, I am new to R (coming from Perl) and have what is, at least at this
point, a philosophical question and a request for comment on some basic
code. As I understand it - R emphasizes ,or at least supports, the
functional programming model. I've come across some code that was markedly
absent in for loops - and have been seeing some constructs that relate to
functional programming and vectorized code (not that is at all unique to R
of course). But I'm also new to the concept of vectorizing code.

However, since I anticipate dealing with vectors of large sizes I think that
this approach is probably going to serve well in terms of performance. As an
example I anticipate having vector operations  calling for shifting. I'll be
shifting vectors to the right (or left) like below while maintaining the
length and filling with zeros. Keep in mind I'll ultimately be dealing with
vectors with very large length.

>x <- c(0,3,2,1,0,0,0)
>vlen <- length(x)
[1] 7

One solution to accomplish the right shift is to do something like:

>x=c(0,x[1:vlen-1])
>x
1] 0 0 3 2 1 0 0

this does the trick though I'm wondering if this is in the spirit of
"Vectorization". I could make recursive function that would cycle through
the whole vector eventually leaving it full of 0s thus ending the recursion.
Though does this capture the spirit of R programming and vectorizing ? Are
there more primitive operators "closer" to the underlying C code that would
serve performance interests better ?

[[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] lm(y ~ x1) vs. lm(y ~ x0 + x1 - 1) with x0 <- rep(1, length(y))

2011-01-21 Thread Bert Gunter
Well ... as x1 is continuous(numeric), it has no levels. So ...??

Note that the fits are identical for both models. The issue is only
what is the Null that you are testing in the two cases. In the first
case, it is just y = constant, so you are testing the 1 df for x1. In
the second, it is y = 0 (which rarely makes any sense) and you are
testing the 2 df for the two terms (x0 and x1). Etc. etc.

-- Bert

On Fri, Jan 21, 2011 at 7:48 PM, David Winsemius  wrote:
>
> On Jan 21, 2011, at 9:03 PM, jochen laubrock wrote:
>
>> Dear list,
>>
>> the following came up in an introductory class. Please help me understand
>> the -1 (or 0+) syntax in formulae: Why do the enumerator dfs, F-statisics
>> etc. differ between the models lm(y ~ x1) and lm(y ~ x0 + x1 - 1), if x0 is
>> a vector containing simply ones?
>
> You are testing something different. In the first case you are testing the
> difference between the baseline and the second level of x1 (so there is only
> one d.f.), while in the second case you are testing for both of the
> coefficients being zero (so the numerator has 2 d.f.). It would be easier to
> see if you did print() on the fit object. The first model would give you an
> estimate for an "Intercept", which is really an estimate for the first level
> of x1.  Having been taught to think of anova as just a special case of
> regression is helpful here. Look at the model first  and only then look at
> the anova table.
>
>
>>
>> Example:
>>
>> N  <- 40
>> x0 <- rep(1,N)
>> x1 <- 1:N
>> vare <- N/8
>> set.seed(4)
>> e <- rnorm(N, 0, vare^2)
>>
>> X <- cbind(x0, x1)
>> beta <- c(.4, 1)
>> y <- X %*% beta + e
>>
>> summary(lm(y ~ x1))
>> # [...]
>> # Residual standard error: 20.92 on 38 degrees of freedom
>> # Multiple R-squared: 0.1151,   Adjusted R-squared: 0.09182
>> # F-statistic: 4.943 on 1 and 38 DF,  p-value: 0.03222
>>
>> summary(lm(y ~ x0 + x1 - 1))        # or summary(lm(y ~ 0 + x0 + x1))
>> # [...]
>> # Residual standard error: 20.92 on 38 degrees of freedom
>> # Multiple R-squared: 0.6888,   Adjusted R-squared: 0.6724
>> # F-statistic: 42.05 on 2 and 38 DF,  p-value: 2.338e-10
>>
>>
>> Thanks in advance,
>> Jochen
>>
>>
>> 
>> Jochen Laubrock, Dept. of Psychology, University of Potsdam,
>> Karl-Liebknecht-Strasse 24-25, 14476 Potsdam, Germany
>> phone: +49-331-977-2346, fax: +49-331-977-2793
>>
>> __
>> 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.
>
> David Winsemius, MD
> West Hartford, CT
>
> __
> 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.
>



-- 
Bert Gunter
Genentech Nonclinical Biostatistics
467-7374
http://devo.gene.com/groups/devo/depts/ncb/home.shtml

__
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] lm(y ~ x1) vs. lm(y ~ x0 + x1 - 1) with x0 <- rep(1, length(y))

2011-01-21 Thread jochen laubrock
Thank you all (including Dennis), this was elucidating. 

I would have (maybe naively) anticipated that in this somewhat pathological 
case of fitting without an intercept and re-introducing it via constant x1, R 
might check whether the design matrix includes a column of ones, and adjust the 
degrees of freedom accordingly. But now I can see that by explicitly requesting 
via the formula interface not to fit a constant, I am implicitly stating my 
hypothesis that y==0, even if I re-introduce my suspicion that y==mu via x1 <- 
1. If I understood correctly, x1 is treated as a variable in the latter case, 
right?



On Jan 22, 2011, at 5:18 , Bert Gunter wrote:

> Well ... as x1 is continuous(numeric), it has no levels. So ...??
> 
> Note that the fits are identical for both models. The issue is only
> what is the Null that you are testing in the two cases. In the first
> case, it is just y = constant, so you are testing the 1 df for x1. In
> the second, it is y = 0 (which rarely makes any sense) and you are
> testing the 2 df for the two terms (x0 and x1). Etc. etc.
> 
> -- Bert
> 
> On Fri, Jan 21, 2011 at 7:48 PM, David Winsemius  
> wrote:
>> 
>> On Jan 21, 2011, at 9:03 PM, jochen laubrock wrote:
>> 
>>> Dear list,
>>> 
>>> the following came up in an introductory class. Please help me understand
>>> the -1 (or 0+) syntax in formulae: Why do the enumerator dfs, F-statisics
>>> etc. differ between the models lm(y ~ x1) and lm(y ~ x0 + x1 - 1), if x0 is
>>> a vector containing simply ones?
>> 
>> You are testing something different. In the first case you are testing the
>> difference between the baseline and the second level of x1 (so there is only
>> one d.f.), while in the second case you are testing for both of the
>> coefficients being zero (so the numerator has 2 d.f.). It would be easier to
>> see if you did print() on the fit object. The first model would give you an
>> estimate for an "Intercept", which is really an estimate for the first level
>> of x1.  Having been taught to think of anova as just a special case of
>> regression is helpful here. Look at the model first  and only then look at
>> the anova table.
>> 
>> 
>>> 
>>> Example:
>>> 
>>> N  <- 40
>>> x0 <- rep(1,N)
>>> x1 <- 1:N
>>> vare <- N/8
>>> set.seed(4)
>>> e <- rnorm(N, 0, vare^2)
>>> 
>>> X <- cbind(x0, x1)
>>> beta <- c(.4, 1)
>>> y <- X %*% beta + e
>>> 
>>> summary(lm(y ~ x1))
>>> # [...]
>>> # Residual standard error: 20.92 on 38 degrees of freedom
>>> # Multiple R-squared: 0.1151,   Adjusted R-squared: 0.09182
>>> # F-statistic: 4.943 on 1 and 38 DF,  p-value: 0.03222
>>> 
>>> summary(lm(y ~ x0 + x1 - 1))# or summary(lm(y ~ 0 + x0 + x1))
>>> # [...]
>>> # Residual standard error: 20.92 on 38 degrees of freedom
>>> # Multiple R-squared: 0.6888,   Adjusted R-squared: 0.6724
>>> # F-statistic: 42.05 on 2 and 38 DF,  p-value: 2.338e-10
>>> 
>>> 
>>> Thanks in advance,
>>> Jochen
>>> 
>>> 
>>> 
>>> Jochen Laubrock, Dept. of Psychology, University of Potsdam,
>>> Karl-Liebknecht-Strasse 24-25, 14476 Potsdam, Germany
>>> phone: +49-331-977-2346, fax: +49-331-977-2793
>>> 
>>> __
>>> 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.
>> 
>> David Winsemius, MD
>> West Hartford, CT
>> 
>> __
>> 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.
>> 
> 
> 
> 
> -- 
> Bert Gunter
> Genentech Nonclinical Biostatistics
> 467-7374
> http://devo.gene.com/groups/devo/depts/ncb/home.shtml


Jochen Laubrock, Dept. of Psychology, University of Potsdam,
Karl-Liebknecht-Strasse 24-25, 14476 Potsdam, Germany
phone: +49-331-977-2346, fax: +49-331-977-2793

__
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] about matrices merge and retrieve algorithm.

2011-01-21 Thread pratik wankhade
I have a problem as follows:

 1. If we have 3 matrices A,B,C and we merge them in a single matrix ABC by
any method like addition , subtraction division,multiplication,etc
 2. and then we want to retrieve original 3 matrices A,B,C from single ABC
matrix
What will be the algorithm?

[[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] Debian ?Ubuntu version of latest R using synaptic in Ubuntu 10.10

2011-01-21 Thread Ajay Ohri
Dear List

I use synaptic to download R on my Ubuntu 10.10. It seems latest version of
R on Ubuntu is 2.11.1

Even when I use debian.cran.r-project.org to update my packages the problem
remains (latest versions on CRAN are almost always 2 updates ahead of Debian
packages) This is also true for a lot of other packages as well

My specific problem is while I can use sudo apt-get to update packages from
Debian repository I get a permission denied when I am trying to update from
CRAN from within R. I am a Linux newbie

Please help

Regards

Ajay

Websites-
http://decisionstats.com

[[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] Accessing MySQL Database in R

2011-01-21 Thread Sascha Vieweg
I think this is not an R issue, but one of MAMP. On my server's 
sql service, I can connect using password, however, on my local 
MAMP, I need the socket:


dbCon <- dbConnect(dbdr, user="root", password="root", 
dbname="mydb", 
unix.socket="/Applications/MAMP/tmp/mysql/mysql.sock")


HTH, *S*


On 11-01-20 08:30, Spencer Graves wrote:


  The following worked for me recently:


library(RMySQL)
MySQL. <- MySQL()
MySQLcon <- dbConnect(MySQL., user='thisuser', password='thispassword',
  dbname='desiredDB')


 I have the following suggestions and questions for you:


   1.  Have you tried supplying "dbname" rather than "host"?


   2.  Please provide "sessionInfo()".  Many packages have a 
function named "dbConnect", and I don't know which one you are using.



   3.  I don't know if "MySQL()" is equivalent to dbDriver("MySQL"), 
which you used.  It might be;  I don't know.



   4.  The standard "install.packages('RMySQL')" may not work, 
because this package needs to be built to configure itself properly to your 
local operating system and versions of MySQL and R installed.  Installation 
instructions are available at 
"http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL";.  If you have not already 
followed those instructions, please do so.  There is a good chance that will 
fix your problem, I think.



   5.  If this is not adequate, I suggest you post this question to 
"r-sig...@stat.math.ethz.ch".  [I suggest you subscribe first.  This list has 
low volume and you can unsubscribe later if you prefer.  And please also 
provide "sessionInfo()".]



   6.  Or use RODBC as suggested by Ptit Bleu.  It comes highly 
recommended (including by Brian Ripley).  However, I had difficulties getting 
positive results from both RMySQL and RODBC.  I tried both, with each 
receiving similar quantities of expletives.  Finally, I got RMySQL to do what 
I wanted and suspended my schoolboy exercises with RODBC.



  Hope this helps.
  Spencer


On 1/20/2011 5:55 AM, PtitBleu wrote:

 Hello,

 I used to use RMySQL but as there is no more package for windows, I
 decided
 to move to RODBC.
 I installed ODBC driver for MySQL (downloaded on the MySQL website) and
 then
 the RODBC package.

 I finally discovered that it was not needed to "register" your database
 with
 ODBC before using it.
 These commands below work for me.

 library(RODBC)
 ch<-odbcDriverConnect(connection="SERVER=localhost;DRIVER=MySQL ODBC 5.1
 Driver;DATABASE=my_database;UID=root;PWD=my_password;case=tolower")
 resultdb<-sqlQuery(ch,"SELECT * from my_table")
 odbcClose(ch)

 Try to modify them for your case.
 I hope it will work for you.
 Good luck,
 Ptit Bleu.


 Re: Accessing MySQL Database in R
 Jan 18, 2011; 12:10am — by djmuseR [User is online] djmuseR
 Hi:

 Because R does not have a direct interface to MySQL?

 You need to load a communication package - the two most common ones are
 RODBC and RMySQL. The former requires that you register your MySQL
 database
 table(s) with ODBC before using the RODBC package on them, whereas the
 latter works with specific version combinations of MySQL and R. The RODBC
 package has a very informative vignette; for information re the RMySQL
 package, see
 http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL

 HTH,
 Dennis

 On Mon, Jan 17, 2011 at 1:30 PM, schlafly<[hidden email]>  wrote:

>  I have a local installation of MySQL on my computer.
> 
>  I enter the following to access MySQL from the command line:

>  /Applications/MAMP/Library/bin/mysql -h localhost -u root -p
>  I am then prompted for a password, and I use: root
>  This connects me to MySQL in the command line.
> 
>  I now want to access MySQL databases in R. I enter the following:

>  mysql<- dbDriver("MySQL")
>  conn<- dbConnect(mysql,user='root',host='localhost', password='root')
> 
>  I get the following error message: Error in mysqlNewConnection(drv, ...) 
>  :

>  RS-DBI driver: (Failed to connect to database: Error: Access denied for
>  user
>  'root'@'localhost' (using password: YES)
> 
>  Does anyone know why these aren't equivalent?

>  --
>  View this message in context:
>  
http://r.789695.n4.nabble.com/Accessing-MySQL-Database-in-R-tp3221264p3221264.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.




--
Sascha Vieweg, saschav...@gmail.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.