Re: [R] Creating ODS RTF-style output in R XXXX

2011-08-30 Thread Dieter Menne

Dan Abner wrote:
 
 I have been using the sink() function as follows:
 
 x-rnorm(100)
 sink(C:\\Users\\dan\\Desktop\\Current Events\\myhw.txt,
  append=TRUE,split=TRUE)
 m1-c(Mean=mean(x),SD=sd(x),Min=min(x),Max=max(x))
 m1
 sink()
 
 ===
 
 Is it possible to create tabular style output very much like the ODS RTF
 STYLE=JOURNAL protocol in SAS (which returns a nicely formatted table with
 table lines and easily opened in MS Word)?
 
 

Not with sink, but odfWeave can do this, but it's a bit more work initially.

Dieter


--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-ODS-RTF-style-output-in-R--tp314p3778018.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How do I get a weighted frequency table?

2011-08-30 Thread Luca Meyer
Thank you, that's works just fine.
Luca

Il giorno 29/ago/2011, alle ore 23.48, H. T. Reynolds ha scritto:

 Hi,
 
 I use xtabs with the weight variable on the left hand side of the formula as 
 in
 
   xtabs(weight ~ opinion + gender + ...)

__
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] Saving a graph

2011-08-30 Thread Prof Brian Ripley

On Mon, 29 Aug 2011, Dieter Menne wrote:



Gang Chen-4 wrote:


However, my problem is that the file generated
from a graph of fixed size is too large (in the order of 10MB) because of
many data points in multiple scatterplots. Any suggestions?



Generate pdf, open and save it in Adobe Acrobat which does a compression
when the setting are correct.


*If* compression is enough, pdf() in R-devel does it, as does 
cairo_pdf() in current R.  And there are other ways than Acrobat to 
compress/compact a PDF file: see ?tools::compactPDF  and the 'Writing 
R Extensions' manual.


However, compression will not make that much of a difference (maybe a 
factor of 3), and the real problem seems to be the inappropriate plot. 
If you really need a plot with hundreds of thousands of points (or 
more), use a format like PNG -- but there are better ways to display 
such plots for most statistical purposes.  E.g. image and contour 
plots of densities, hexplots, density-dependent thinning 


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] Ordinal logistic regression p-values

2011-08-30 Thread Rune Haubo
There is also clm() (for cumulative link models) from package ordinal
that has much the same interface that polr() has, but it does give you
p-values for the regression parameters. A simple example from
examples(clm):

library(ordinal)
data(wine)
fm1 - clm(rating ~ contact + temp, data=wine)
(summ - summary(fm1))

giving the output:

formula: rating ~ contact + temp
data:wine

 link  threshold nobs logLik AICniter max.grad cond.H
 logit flexible  72   -86.49 184.98 6(0)  4.01e-12 2.7e+01

Coefficients:
   Estimate Std. Error z value Pr(|z|)
contactyes   1.5278 0.4766   3.205  0.00135 **
tempwarm 2.5031 0.5287   4.735 2.19e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Threshold coefficients:
Estimate Std. Error z value
1|2  -1.3444 0.5171  -2.600
2|3   1.2508 0.4379   2.857
3|4   3.4669 0.5978   5.800
4|5   5.0064 0.7309   6.850

The p-values are extracted with:
 coef(summ)[5:6, 4]
  contactyes tempwarm
1.348440e-03 2.194605e-06

Cheers,
Rune

On 30 August 2011 03:30, Frank Harrell f.harr...@vanderbilt.edu wrote:
 Use the rms package to replace Design.  Run anova(fit object from lrm) which
 produces a matrix from which you can extract P-values.  This also handles
 the case of multiple degrees of freedom per predictor.
 Frank

 Debs Majumdar wrote:

 Hi,

    Are there any packages which prints out p-values for OLR's (like
 `ologit' from Stata)? I want to run a bunch of OLRs and print the p-value
 for the first coefficient from each of them.


   I checked polr() under MASS and it doesn't.

  There's a lrm() function under Design which does print out p-values but I
 couldn't extract p-values from the output.


   Thanks,

   Debs


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



 -
 Frank Harrell
 Department of Biostatistics, Vanderbilt University
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Ordinal-logistic-regression-p-values-tp3777674p368.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.




-- 
Rune Haubo Bojesen Christensen

Ph.D. Student, M.Sc. Eng.
Phone: (+45) 45 25 33 63
Mobile: (+45) 30 26 45 54

DTU Informatics, Section for Statistics
Technical University of Denmark, Build. 305, Room 122,
DK-2800 Kgs. Lyngby, Denmark

__
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] Differences in SAS and R defaults

2011-08-30 Thread Nikhil Abhyankar
Yes, something similar would be helpful but not among SAS proc but between
SAS and R.

Thanks

Nikhil

On Mon, Aug 29, 2011 at 11:08 PM, Jeremy Miles jeremy.mi...@gmail.comwrote:


 Do you mean things like treatment of categorical variables in regression
 procedures (which have different defaults in different procedures in SAS),
 and different default as to the reference category in logistic regression?

 Jeremy



 On 29 August 2011 04:46, n nikhil.abhyan...@gmail.com wrote:

 Hello all,

 I am looking for theories and statistical analyses where the defaults
 employed in R and SAS are different. As a result, the outputs under
 the defaults should (at least slightly) differ for the same input.

 Could anyone kindly point any such instance?

 Thanks

 Nikhil

 __
 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] Conditional plots in the soiltexture package

2011-08-30 Thread Julien Moeys
Dear Alessandro

I am not sure what you mean by conditional plot

But if it is about having a different symbol, for different soil parent 
materials, you can use the pch argument in TT.plot()

###
require( soiltexture ) 

# :: 1st create a dummy texture dataset 
my.text - data.frame( 
CLAY  = c(05,60,15,05,25,05,25,45,65,75,13,47), 
SILT  = c(05,08,15,25,55,85,65,45,15,15,17,43), 
SAND  = c(90,32,70,70,20,10,10,10,20,10,70,10), 
parent= rep(1:2,each=6) # parent material and symbol code
)   #
dim( my.text ) 

TT.plot( tri.data = my.text, pch = my.text[,parent] )
###

Is that what you need?
 
All the best

Julien



From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
samuel-rosa [alessandrosam...@yahoo.com.br]
Sent: 30 August 2011 03:48
To: r-help@r-project.org
Subject: [R] Conditional plots in the soiltexture package

Dear R users

I'd like to know if it is possible to create conditional plots in the
soiltexture package. I have data from the particle size distribution of
soils derived from two parent materials and I want to use the parent
material as conditioner.

Thanks a lot.

Alessandro Samuel-Rosa
Post-Graduation Program in Soil Science
Federal University of Santa Maria
Av. Roraima, nº 1000, CEP 97105-970
Santa Maria, RS, Brazil

--
View this message in context: 
http://r.789695.n4.nabble.com/Conditional-plots-in-the-soiltexture-package-tp383p383.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] R-Studio Question

2011-08-30 Thread Eran Eidinger
Hello,

I've switched to R studio from the StatET Eclipse plug-in.
I have a question regarding navigating between plots.
When I use x11() or windows() new devices are created and I know how to
switch back and forth between them.

However, when I plot on the device that stands for R-Studio's built-in plot
browser, is there a way to switch back between plots? Each new plot
command opens a new plot, and the number of devices does not change.

Thanks,
Eran.

[[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] Showing zero frequencies with xtabs

2011-08-30 Thread Luca Meyer
Hi,

Does anyone know how to show zero frequencies variable levels with the xtabs 
command? They show with the table(x,y) command but I need to apply weight to 
frequency tables and I also need to cbind several tables together, which 
implies that they all need to show the same number of rows. 

Alternatively, do you know how to column bind tables with different number of 
rows? I cannot use merge as it requires daata.frame and that modifies the look 
of the banner table I am trying to create...

Thanks,
Luca


Mr. Luca Meyer
www.lucameyer.com
R version 2.13.1 (2011-07-08)
Mac OS X 10.6.8







[[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] Showing zero frequencies with xtabs

2011-08-30 Thread peter dalgaard

On Aug 30, 2011, at 10:04 , Luca Meyer wrote:

 Hi,
 
 Does anyone know how to show zero frequencies variable levels with the xtabs 
 command? They show with the table(x,y) command but I need to apply weight to 
 frequency tables and I also need to cbind several tables together, which 
 implies that they all need to show the same number of rows. 

Are you sure you are doing the same thing as with table(). I'd expect it to 
work if you ensure that the variables are factors:

 library(ISwR)
 xtabs(~sex+menarche,data=juul)
   menarche
sex   1   2
  2 369 335

 juul$sex - factor(juul$sex,levels=1:2)
 xtabs(~sex+menarche,data=juul)
   menarche
sex   1   2
  1   0   0
  2 369 335



 
 Alternatively, do you know how to column bind tables with different number of 
 rows? I cannot use merge as it requires daata.frame and that modifies the 
 look of the banner table I am trying to create...
 
 Thanks,
 Luca
 
 
 Mr. Luca Meyer
 www.lucameyer.com
 R version 2.13.1 (2011-07-08)
 Mac OS X 10.6.8
 
 
 
 
 
 
 
   [[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.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@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.


Re: [R] Showing zero frequencies with xtabs

2011-08-30 Thread Petr PIKAL
Hi
 
 Hi,
 
 Does anyone know how to show zero frequencies variable levels with the 
 xtabs command? They show with the table(x,y) command but I need to apply 

 weight to frequency tables and I also need to cbind several tables 
 together, which implies that they all need to show the same number of 
rows. 

Do you use factors?

x-sample(letters[1:5], 20, replace=T)
xtabs(~x)
x
a b c d e 
2 1 5 4 8 

x.f-factor(x)
x[x==b]-NA
x.f[x.f==b]-NA

 xtabs(~x)
x
a c d e 
2 5 4 8 

 xtabs(~x.f)
x.f
a b c d e 
2 0 5 4 8 

With factors you can specify also non existent levels so they shall appear 
as zeroes in table or xtabs.

Regards
Petr

 
 Alternatively, do you know how to column bind tables with different 
number
 of rows? I cannot use merge as it requires daata.frame and that modifies 

 the look of the banner table I am trying to create...
 
 Thanks,
 Luca
 
 
 Mr. Luca Meyer
 www.lucameyer.com
 R version 2.13.1 (2011-07-08)
 Mac OS X 10.6.8
 
 
 
 
 
 
 
[[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] Configuring Proxy: Proxy Authentication Required with --internet2

2011-08-30 Thread behave
That was my first guess as well, but unfortunately this doesn't solve the
problem.

I is remarkably that IE requires authentification for every new instance I
open (even if another instance is already open)...

Any other hints?

--
View this message in context: 
http://r.789695.n4.nabble.com/Configuring-Proxy-Proxy-Authentication-Required-with-internet2-tp3776209p3778151.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] ARMA show different result between eview and R

2011-08-30 Thread Young Gyu Park
When I do ARMA(2,2) using one lag of LCPIH data



This is eview result


 *Dependent Variable: DLCPIH
 **Method: Least Squares
 **Date: 08/12/11   Time: 12:44
 **Sample (adjusted): 1970Q2 2010Q2
 **Included observations: 161 after adjustments
 **Convergence achieved after 14 iterations
 **MA Backcast: 1969Q4 1970Q1
 **
 **VariableCoefficientStd. Errort-StatisticProb.
 **
 **C0.0033610.0018141.8533520.0657
 **DLCPIH(-1)-0.1001500.053160-1.8839170.0614
 **DLCPIH(-2)0.8704560.05246616.590750.
 **MA(1)0.5322520.1001105.3166780.
 **MA(2)-0.3793830.099535-3.8115660.0002
 **
 **R-squared0.512067Mean dependent var0.014816
 **Adjusted R-squared0.499556S.D. dependent var0.016274
 **S.E. of regression0.011513Akaike info criterion
 -6.060182
 **Sum squared resid0.020676Schwarz criterion-5.964486
 **Log likelihood492.8446Hannan-Quinn criter.-6.021326
 **F-statistic40.92897Durbin-Watson stat2.012062
 **Prob(F-statistic)0.00
 **
 **Inverted MA Roots  .40 -.94 *



This is R result



 * dlcpihTsLen - length(ausT2Ts[,4])
 ** dlcpihArma22Fit - arima(ausT2Ts[,4], order=c(2,1,2),
 xreg=1:dlcpihTsLen)
 ** dlcpiArma22hFit - arima(ausT2Ts[,4], order=c(2,1,2))
 ** dlcpihArma22Fit
 *
 *Call:
 **arima(x = ausT2Ts[, 4], order = c(2, 1, 2), xreg = 1:dlcpihTsLen)
 *
 *Coefficients:
 **  ar1 ar2 ma1  ma2  1:dlcpihTsLen
 **  -0.1083  0.8673  0.5263  -0.3716 0.0146
 **s.e.   0.0493  0.0484  0.0894   0.0852 0.0041
 *
 *sigma^2 estimated as 0.0001282:  log likelihood = 498.38,  aic = -984.76*

*
*

*
*

I wonder why the coefficient values are little bit different between them.

*
*

Another thing I wonder is why the AIC value is so significantly different
each other*.*

*
*

Please help me, if anyone who have experience both of eview and R is in R
community.


Thank you.

[[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] Plotting multiple vectors in one window?

2011-08-30 Thread Joshua Wiley
Hi Caitlin,

I would probably convert the data to a long format so bsa, unknown1,
unknown2 are all in one variable and ditto for abs.  Then control the
plotting symbol using the variable indicator.  abline() will just keep
adding to the existing plot, so you could add all three lines of best
fit using it with three separate calls.  If you wanted to plot them
staying in wide format, try using ?points

## example data (it is polite for the person asking for help to sample
data (real or made up))
dat - as.data.frame(matrix(rnorm(60), ncol = 6))
colnames(dat) - c(bsa, unknown1, unknown2, abs, abs2, abs3)

## using a wide dataset. Note the use of with() to avoid retyping dat
over and over
## each time I use reference one of the variables
with(dat, {
plot(bsa, abs, col='blue', pch=16, xlim=c(-3, 3), ylim=c(-3, 3), xlab =
expression(paste(BSA,  (, mu, g), sep=)), ylab=expression(A[595]))

points(unknown1, abs2, col='blue', pch=17)
points(unknown2, abs3, col='blue', pch=18)

abline(lm(abs ~ bsa))
abline(lm(abs2 ~ unknown1))
abline(lm(abs3 ~ unknown2))

title(main=Quantifying Protein Content via Bradford Microassay, col='blue')
})

## A solution using long format with ggplot2 for graphing
require(ggplot2)
datlong - reshape(dat, varying = list(1:3, 4:6), v.names = c(bsa,
abs), direction = long)
datlong$time - factor(datlong$time)
head(datlong) ## look at the first few rows

ggplot(data = datlong, mapping = aes(x = bsa, y = abs, group = time)) +
  stat_smooth(aes(linetype = time), size = 1, method = lm, se=FALSE) +
  geom_point(aes(shape = time))

Cheers,

Josh

On Mon, Aug 29, 2011 at 9:53 PM, Caitlin bioprogram...@gmail.com wrote:
 Hi all.

 Using the following code:

 plot(bsa, abs, col='blue', pch=16, xlim=c(0, 25), ylim=c(0.0, 1.0), xlab =
 expression(paste(BSA,  (, mu, g), sep=)), ylab=expression(A[595]))

 plot(unknown1, abs2, col='blue', pch=16, xlim=c(0, 25), ylim=c(0.0, 1.0),
 xlab = expression(paste(Unknown_1,  (, mu, g), sep=)),
 ylab=expression(A[595]))

 plot(unknown2, abs3, col='blue', pch=16, xlim=c(0, 25), ylim=c(0.0, 1.0),
 xlab = expression(paste(Unknown_2,  (, mu, g), sep=)),
 ylab=expression(A[595]))


  myline.fit - lm(abs ~ bsa)
 summary(myline.fit)
 abline(myline.fit)

 axis(side=1, col=gray, tck=1, lty=dotted)
 axis(side=2, col=gray, tck=1, lty=dotted)
 box()
 minor.tick(nx=2, ny=2, tick.ratio=0.5)
 title(main=Quantifying Protein Content via Bradford Microassay,
 col='blue')

 ...I have constructed three individual plots. Is there a convenient way to
 plot three vectors (not from a file) into one window? With three individual
 lines of best fit? Probably using three symbols, e.g., pch=16, 17, 18, to
 distinguish them.

 Thanks,

 ~Caitlin

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




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R-Studio Question

2011-08-30 Thread Iain Gallagher
Above the graph on the left there are back and forward arrows. You can use 
those (like a browser).

This might have been better asked on the R-Studio forums. They're very friendly.

best

iain

--- On Tue, 30/8/11, Eran Eidinger e...@taykey.com wrote:

 From: Eran Eidinger e...@taykey.com
 Subject: [R] R-Studio Question
 To: r-help@r-project.org
 Date: Tuesday, 30 August, 2011, 8:59
 Hello,
 
 I've switched to R studio from the StatET Eclipse plug-in.
 I have a question regarding navigating between plots.
 When I use x11() or windows() new devices are created and I
 know how to
 switch back and forth between them.
 
 However, when I plot on the device that stands for
 R-Studio's built-in plot
 browser, is there a way to switch back between plots? Each
 new plot
 command opens a new plot, and the number of devices does
 not change.
 
 Thanks,
 Eran.
 
     [[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] Asking Favor For Remove element with Particular Value In Vector

2011-08-30 Thread Jim Lemon

On 08/30/2011 12:06 AM, Bert Gunter wrote:

Jim et. al:

This is the second time I've seen this advice recently. Use logical
indexing: which(), though not wrong, is superfluous:


x[ !x %in% c(0,255)]  will do, rather than:

By golly, you're right, and it works even if x is a logical vector. I 
should have checked the operator precedence.


Jim

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] execute R commands from Matlab

2011-08-30 Thread Daniel Malter
They seem to have a workaround. I don't know whether anything better is
available by now.

http://www.mathworks.com/matlabcentral/newsreader/view_thread/163726

HTH,
Daniel


sarak wrote:
 
 Is it possible for anyone to upload a youtube video showing how to execute
 R commands in Matlab , it's so vital for me ..
 

--
View this message in context: 
http://r.789695.n4.nabble.com/execute-R-commands-from-Matlab-tp3778263p3778281.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] execute R commands from Matlab

2011-08-30 Thread Daniel Malter
This seems to work, as well:
http://www.mathworks.com/matlabcentral/fx_files/5051/1/content/Rdemo.html

--
View this message in context: 
http://r.789695.n4.nabble.com/execute-R-commands-from-Matlab-tp3778263p3778282.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] ARMA show different result between eview and R

2011-08-30 Thread Daniel Malter
In your first line, you write ARMA(2,2). However, what you fit in R is
ARIMA(2,1,2). What you fit in eview, I can't tell. Could that explain the
difference?

HTH,
Daniel


Young Gyu Park wrote:
 
 When I do ARMA(2,2) using one lag of LCPIH data
 
 
 
 This is eview result
 

 *Dependent Variable: DLCPIH
 **Method: Least Squares
 **Date: 08/12/11   Time: 12:44
 **Sample (adjusted): 1970Q2 2010Q2
 **Included observations: 161 after adjustments
 **Convergence achieved after 14 iterations
 **MA Backcast: 1969Q4 1970Q1
 **
 **VariableCoefficientStd. Errort-StatisticProb.
 **
 **C0.0033610.0018141.8533520.0657
 **DLCPIH(-1)-0.1001500.053160-1.8839170.0614
 **DLCPIH(-2)0.8704560.05246616.590750.
 **MA(1)0.5322520.1001105.3166780.
 **MA(2)-0.3793830.099535-3.8115660.0002
 **
 **R-squared0.512067Mean dependent var0.014816
 **Adjusted R-squared0.499556S.D. dependent var   
 0.016274
 **S.E. of regression0.011513Akaike info criterion
 -6.060182
 **Sum squared resid0.020676Schwarz criterion-5.964486
 **Log likelihood492.8446Hannan-Quinn criter.-6.021326
 **F-statistic40.92897Durbin-Watson stat2.012062
 **Prob(F-statistic)0.00
 **
 **Inverted MA Roots  .40 -.94 *
 
 
 
 This is R result
 
 
 
 * dlcpihTsLen - length(ausT2Ts[,4])
 ** dlcpihArma22Fit - arima(ausT2Ts[,4], order=c(2,1,2),
 xreg=1:dlcpihTsLen)
 ** dlcpiArma22hFit - arima(ausT2Ts[,4], order=c(2,1,2))
 ** dlcpihArma22Fit
 *
 *Call:
 **arima(x = ausT2Ts[, 4], order = c(2, 1, 2), xreg = 1:dlcpihTsLen)
 *
 *Coefficients:
 **  ar1 ar2 ma1  ma2  1:dlcpihTsLen
 **  -0.1083  0.8673  0.5263  -0.3716 0.0146
 **s.e.   0.0493  0.0484  0.0894   0.0852 0.0041
 *
 *sigma^2 estimated as 0.0001282:  log likelihood = 498.38,  aic =
 -984.76*
 
 *
 *
 
 *
 *
 
 I wonder why the coefficient values are little bit different between them.
 
 *
 *
 
 Another thing I wonder is why the AIC value is so significantly different
 each other*.*
 
 *
 *
 
 Please help me, if anyone who have experience both of eview and R is in R
 community.
 
 
 Thank you.
 
   [[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.
 

--
View this message in context: 
http://r.789695.n4.nabble.com/ARMA-show-different-result-between-eview-and-R-tp3778217p3778299.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] R-Studio Question

2011-08-30 Thread Eran Eidinger
I meant navigating through the command line, using R commands (like
dev.set() for regular plots).

Thank you for the reference, I will ask There.

Eran.

On Tue, Aug 30, 2011 at 11:37 AM, Iain Gallagher 
iaingallag...@btopenworld.com wrote:

 Above the graph on the left there are back and forward arrows. You can use
 those (like a browser).

 This might have been better asked on the R-Studio forums. They're very
 friendly.

 best

 iain

 --- On Tue, 30/8/11, Eran Eidinger e...@taykey.com wrote:

  From: Eran Eidinger e...@taykey.com
  Subject: [R] R-Studio Question
  To: r-help@r-project.org
  Date: Tuesday, 30 August, 2011, 8:59
  Hello,
 
  I've switched to R studio from the StatET Eclipse plug-in.
  I have a question regarding navigating between plots.
  When I use x11() or windows() new devices are created and I
  know how to
  switch back and forth between them.
 
  However, when I plot on the device that stands for
  R-Studio's built-in plot
  browser, is there a way to switch back between plots? Each
  new plot
  command opens a new plot, and the number of devices does
  not change.
 
  Thanks,
  Eran.
 
  [[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] weird apply() behavior

2011-08-30 Thread Daniel Malter
#Do

apply(y,1,print)

#Note the space that is inserted before the 1. If you insert this space in
your function

apply(y,1,function(x){x-unlist(x); if (!is.na(x[2])  x[2]=='2k' 
!is.na(x[1])  x[1]==' 1') 1 else 0} )

#you get the result you expect.

#Also, note that your !is.na conditions are redundant for the given example
because if the other conditions are true, the !is.na conditions default to
true, as well.

apply(y,1,function(x){x-unlist(x); if (x[2]=='2k'  x[1]==' 1') 1 else 0} )

HTH,
Daniel




--
View this message in context: 
http://r.789695.n4.nabble.com/weird-apply-behavior-tp3777699p3778318.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] Asking Favor For Remove element with Particular Value In Vector

2011-08-30 Thread jim holtman
But that is a good reason to always use parentheses:

x[ !(x %in% c(0,255))]

since some of the 'precendences' vary between languages.

On Tue, Aug 30, 2011 at 4:47 AM, Jim Lemon j...@bitwrit.com.au wrote:
 On 08/30/2011 12:06 AM, Bert Gunter wrote:

 Jim et. al:

 This is the second time I've seen this advice recently. Use logical
 indexing: which(), though not wrong, is superfluous:


 x[ !x %in% c(0,255)]  will do, rather than:

 By golly, you're right, and it works even if x is a logical vector. I should
 have checked the operator precedence.

 Jim

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
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] Plotting multiple vectors in one window?

2011-08-30 Thread S Ellison
 

 -Original Message-
 From: r-help-boun...@r-project.org On Behalf Of Caitlin
 Subject: [R] Plotting multiple vectors in one window?

 ...I have constructed three individual plots. Is there a 
 convenient way to plot three vectors (not from a file) into 
 one window? 
?points

and then
With three individual lines of best fit? 
abline() or predict(), depending on what kind of best fit you had in mind

***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
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] Simulating distribution of max of two die

2011-08-30 Thread S Ellison
 

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Jaap van Wyk
 Sent: 30 August 2011 04:57
 To: r-help@r-project.org
 Subject: [R] Simulating distribution of max of two die

  how to find the distribution of the 
 maximum of rolling two balanced die. Is there perhaps a more 
 elegant way to do this, other than the way I am using below? 

#Perhaps
dice - matrix(sample(1:6, 4,replace=T), ncol=2)
dice.max - apply(dice, 1, max)
barplot(table(dice.max)) 

#and just for interest
mids-barplot(table(dice.max)/length(dice.max)) #gives proportions
all.pairs - expand.grid(1:6, 1:6)
dice.max.exact - apply(all.pairs, 1, max)

points(mids, table(dice.max.exact)/36, pch=_, cex=2, col=2)


***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
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] Why does loading saved/cached objects add significantly to RAM consumption?

2011-08-30 Thread Janko Thyson

Dear list,

I make use of cached objects extensively for time consuming computations 
and yesterday I happened to notice some very strange behavior in that 
respect:
When I execute a given computation whose result I'd like to cache (tried 
both saving it as '.Rdata' and via package 'R.cache' which uses a own 
filetype '.Rcache'), my R session consumes about 200 MB of RAM, which is 
fine. Now, when I make use of the previously cached object (i.e. loading 
it, assigning it to a certain field of a Reference Class object), I 
noticed that RAM consumption of my R process jumps to about 250 MB!

a
Each new loading of cached/saved objects adds to that consumption (in 
total, I have about 5-8 objects that are processed this way), so at some 
point I easily get a RAM consumption of over 2 GB where I'm only at 
about 200 MB of consumption when I compute each object directly! Object 
sizes (checked with 'object.size()') remain fairly constant. What's even 
stranger: after loading cached objects and removing them (either via 
'rm()' or by assigning a 'fresh' empty object to the respective 
Reference Class field, RAM consumption remains at this high level and 
never comes down again.


I checked the behavior also in a small example which is a simplification 
of my use case and which you'll find below (checked both on Win XP and 
Win 7 32 bit). I couldn't quite reproduce an immediate increase in RAM 
consumption, but what I still find really strange is

a) why do repeated 'load()' calls result in an increase in RAM consumption?
b) why does the latter not go down again after the objects have been 
removed from '.GlobalEnv'?


Did anyone of you experience a similar behavior? Or even better, does 
anyone know why this is happening and how it might be fixed (or be 
worked around)? ;-)


I really need your help on this one as it's crucial for my thesis, 
thanks a lot for anyone replying!!


Regards,
Janko

# EXAMPLE #

setRefClass(A, fields=list(.PRIMARY=environment))
setRefClass(Test, fields=list(a=A))

obj.1 - lapply(1:5000, function(x){
rnorm(x)
})
names(obj.1) - paste(sample, 1:5000, sep=.)
obj.1 - as.environment(obj.1)

test - new(Test, a=new(A, .PRIMARY=obj.1))
test$a$.PRIMARY$sample.10

#+

object.size(test)
object.size(test$a)
object.size(obj.1)
# RAM used by R session: 118 MB

save(obj.1, file=C:/obj.1.Rdata)
# Results in an object of ca. 94 MB
save(test, file=C:/test.Rdata)
# Results in an object of ca. 94 MB

# START A NEW R SESSION #

load(C:/test.Rdata)
# RAM consumption still fine at 115 - 118 MB

# But watch how it goes up as we repeatedly load objects
for(x in 1:5){
load(C:/test.Rdata)
}
for(x in 1:5){
load(C:/obj.1.Rdata)
}
# Somehow there seems to be an upper limit, though

# Removing the objects does not bring down RAM consumption
rm(obj.1)
rm(test)

##

 Sys.info()
 sysname  release
   Windows XP
 version nodename
build 2600, Service Pack 3   ASHB-109C-02
 machinelogin
   x86 wwa418
user
wwa418

 sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

loaded via a namespace (and not attached):
[1] codetools_0.2-8 tools_2.13.1

__
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] ddply from plyr package - any alternatives?

2011-08-30 Thread Matthew Dowle
Adam,

 because I did not have time to entirely test

Do you (or does your company) have an automated test suite in place?

R 2.10.0 is nearly two years old,  and R 2.12.0 is nearly one.

Matthew

AdamMarczak adam.marc...@gmail.com wrote in message 
news:1314385041626-3771731.p...@n4.nabble.com...
 No, it's not much faster. I'd say it's faster about 10-15% in my case.

 I dont want neither plyr or data.table package because our software on the
 server does not support R version  over 2.10 and both of them have
 dependency for R = 2.12. Also I do not want to use old archives because I
 did not have time to entirely test them as it was quick demand for
 workaround.

 Best regards,
 Adam.

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/ddply-from-plyr-package-any-alternatives-tp3765936p3771731.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] Choropleth in R

2011-08-30 Thread Oscar Perpiñan Lamigueiro
You can use spplot from sp. Some examples:

http://blog.revolutionanalytics.com/2009/10/geographic-maps-in-r.html
http://ryouready.wordpress.com/2009/11/16/infomaps-using-r-visualizing-german-unemployment-rates-by-color-on-a-map/
http://news.mrdwab.com/2010/05/16/choropleth-party-with-r/

Best,

Oscar.


---
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com

-
Hi all,
I would like to use R in order to generate a Heatmap/Choropleth
overlaid on the UK map. Can someone please help with finding the right
package/code? Any help is much appreciated.
Best, Reza

   [[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 with the 'reshape' package

2011-08-30 Thread Filipe Leme Botelho
Hi all,

I am reading previous posts and guidance on the 'reshape' package in order to 
solve the simple problem below. Thinking that this might be very trivial for 
most of you, I thought there could be a fast solution coming from you guys, and 
I´d be very thankful for that.

I have a matrix with dates, companies, prices, just like

DateCompany Price
set-11  A   3
dez-11  A   3,2
jan-12  A   3,3
fev-12  A   2,7
mar-12  A   2,7
abr-12  A   2,8
mai-12  A   2,9
jun-12  A   3
jul-12  A   3,1
mar-12  B   5
abr-12  B   5,5
mai-12  B   5,7
jun-12  B   7
jul-12  B   6,6
dez-11  C   1
jan-12  C   1,1
fev-12  C   1,11
mar-12  C   1,2
abr-12  C   1,3

and I want to convert it into something like below (missing data can be zeros 
or NAs)

A   B   C
set-11  3   NA  NA
dez-11  3,2 NA  1
jan-12  3,3 NA  1,1
fev-12  2,7 NA  1,11
mar-12  2,7 5   1,2
abr-12  2,8 5,5 1,3
mai-12  2,9 5,7 NA
jun-12  3   7   NA
jul-12  3,1 6,6 NA

Workspace is attached. Thanks in advance.

This message and its attachments may contain confidential and/or privileged 
information. If you are not the addressee, please, advise the sender 
immediately by replying to the e-mail and delete this message.

Este mensaje y sus anexos pueden contener información confidencial o 
privilegiada. Si ha recibido este e-mail por error por favor bórrelo y envíe un 
mensaje al remitente.

Esta mensagem e seus anexos podem conter informação confidencial ou 
privilegiada. Caso não seja o destinatário, solicitamos a imediata notificação 
ao remetente e exclusão da mensagem.__
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] R versions and PostScript files

2011-08-30 Thread Prof Brian Ripley

On Fri, 22 Jul 2011, James Cloos wrote:

Please do note the posting guide: the context you omitted (when 
explicitly asked not to) is in the thread starting:


https://stat.ethz.ch/pipermail/r-help/2011-July/284352.html


I suspect that a few s/def/bind def/ on that prologue might improve
things a bit.


No discernable difference on the viewers I tested.


The ps R creates freely switches between the sRGB ABC space and
setgray.  That is a good thing; it helps ensure that black will
be just black when sent to a CMYK device.  Without that you can
get CMY black from some devices.  But it does complicate things.

(CMYK devices often use CMY black rather than K black when the
source is RGB black because it is better when printing contone
images, such as photographs.  But it just wastes ink and toner
when printing charts and similar graphics.)


I've not seen a printer driver which does that for many years.  But 
remember that R's postscript() has origins in  the mid-1990s.


R's pdf() is newer (R 1.3.0, 2001) and even by then the optimization 
could safely be left to the driver.



The best improvement would be to have R keep track of the last
colorspace and only run the srgb procedure when switching from
DeviceGray, rather than every time it changes the RGB colour.


Actually no, as it can do that rather often.  Consider the pairs plots 
of the iris data in demo(graphics): that does (1200 times)


switch to red, blue or green
fill circle
switch to black
draw circle outline.

Some viewers are rather slow in running that procedure, and on those 
viewers this example is slow.


Workarounds:

1) Use pdf(), where the viewers seem to cache colorspaces.
2) In R-patched, use colormodel=rgb-nogray, which never switches 
colorspace (srgb-nogray in R-devel).
3) In R-devel, use colormodel=rgb (rather than srgb) and give up 
the colour accuracy (if your viewer is not already set for sRGB) for 
speed.



The SetColor() function in R/src/library/grDevices/src/devPS.c
looks to be the place to do that.  The Invalidate() function
and the PostScriptDesc struct there also need to track any
such changes.


Hmm, you seem not to understand how the code works.  The postscript 
macro /bg switches colour, and the macros /p3 and similar use 
different colorspaces during their execution.  It isn't just SetColor 
as its setting may not be used immediately.



-JimC
--
James Cloos cl...@jhcloos.com OpenPGP: 1024D/ED7DAEA6


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] url prep function (backslash issue)

2011-08-30 Thread Tyler Rinker



Greeting R
Community, 

I am a
windows user so this problem may be specific to windows. I often want to source
files from within R 

such as:
C:\Users\Rinker\Desktop\Research  Law\Data\School Data 09-10. To source
this file I need to go 

through the
path and replace all the backslashes (\) with forward slashes (/). I usually do
this in MS Word

using the
replace option, however, I'd like to do this in R. Attempting to write a
function to do this runs into 

problems: 

When I
enter the following:

readyPath
- function(path){

z - gsub(\, /, path)

return(z)

} 

I get:


readyPath - function(path){

+ z - gsub(\, /, path)

+ return(z)

+ }

+  

...meaning
R can't close the sequence (presumably because of the backslash which has
special meaning).

So I tried
(\\):



readyPath - function(path){

z - gsub(\\, /, path)

return(z)

}This allows
the function to be stored as an object but I'm not sure if this is correct.

When I try
the function the backslash gets me again: 


readyPath(C:\Users\Rinker\Desktop\Research  Law\Data\School Data
09-10)

Error: '\U' used without hex digits in character string starting
C:\U 

This is
what I'd like the function to return:

[1]
C:/Users/Rinker/Desktop/Research  Law/Data/School Data 09-10 

I want a
function in which I enter a path and it returns the path with backslashes 

replaced
with forward slashes. Is there a way to make a function to do this? 

Windows 7
user

R version
2.14 beta 

Thank you,

Tyler
Rinker

 

  
[[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] Help with the 'reshape' package

2011-08-30 Thread Petr PIKAL
Hi
 Hi all,
 
 I am reading previous posts and guidance on the 'reshape' package in 
order
 to solve the simple problem below. Thinking that this might be very 
 trivial for most of you, I thought there could be a fast solution coming 

 from you guys, and I´d be very thankful for that.
 
 I have a matrix with dates, companies, prices, just like
 
 Date   Company   Price
 set-11   A   3
 dez-11   A   3,2
 jan-12   A   3,3
 fev-12   A   2,7
 mar-12   A   2,7
 abr-12   A   2,8
 mai-12   A   2,9
 jun-12   A   3
 jul-12   A   3,1
 mar-12   B   5
 abr-12   B   5,5
 mai-12   B   5,7
 jun-12   B   7
 jul-12   B   6,6
 dez-11   C   1
 jan-12   C   1,1
 fev-12   C   1,11
 mar-12   C   1,2
 abr-12   C   1,3
 
 and I want to convert it into something like below (missing data can be 
 zeros or NAs)
 
   A   B   C
 set-11   3   NA   NA
 dez-11   3,2   NA   1
 jan-12   3,3   NA   1,1
 fev-12   2,7   NA   1,11
 mar-12   2,7   5   1,2
 abr-12   2,8   5,5   1,3
 mai-12   2,9   5,7   NA
 jun-12   3   7   NA
 jul-12   3,1   6,6   NA



You have already melted data (long format). So simply cast

 cast(test, Date~Company)
Using Price as value column.  Use the value argument to cast to override 
this choice
Date   A   BC
1 abr-12 2.8 5.5 1.30
2 dez-11 3.2  NA 1.00
3 fev-12 2.7  NA 1.11
4 jan-12 3.3  NA 1.10
5 jul-12 3.1 6.6   NA
6 jun-12 3.0 7.0   NA
7 mai-12 2.9 5.7   NA
8 mar-12 2.7 5.0 1.20
9 set-11 3.0  NA   NA

Shall be OK.

Regards
Petr



 
 Workspace is attached. Thanks in advance.
 
 This message and its attachments may contain confidential and/or 
 privileged information. If you are not the addressee, please, advise the 

 sender immediately by replying to the e-mail and delete this message.
 
 Este mensaje y sus anexos pueden contener información confidencial o 
 privilegiada. Si ha recibido este e-mail por error por favor bórrelo y 
 envíe un mensaje al remitente.
 
 Esta mensagem e seus anexos podem conter informação confidencial ou 
 privilegiada. Caso não seja o destinatário, solicitamos a imediata 
 notificação ao remetente e exclusão da 
 mensagem.__
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Error in f(x, ...) : could not find function f2

2011-08-30 Thread . .
Hi all,

I am getting the erro showed in the subject. I was strange the this
becomes to happen after a computer restar. I think after the restart
another function f2 was in memory and it scape from me.

func - Vectorize(FUN=
  function(y, frac, rate, sad, samp=Poisson, trunc=0, ...){
f0 - function(y,frac,n) {
f1 - function(y,frac,n){
dpois(y,frac*n)
}
dcom - paste(d,deparse(substitute(sad)),sep=)
dots - c(as.name(n),list(...))
f2 - call(dcom,dots)
f - function(n){
f1(y,frac,n)*f2(n)
}
myintegrate - function() {
r - 0
r1 - 1
x1 - 0
dx - 20
while(r1  10e-500) {
r1 - integrate(f,x1,x1+dx)$value
r - r + r1
x1 - x1 + dx
}
integrate(f,x1,Inf)$valu
}
myintegrate()
}
f0(y,frac,n)/(1-f0(trunc,frac,n))
},y)

func(10, 0.1, 0.1, exp)

Any idea?

Thanks in advance.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] url prep function (backslash issue)

2011-08-30 Thread Prof Brian Ripley

You seem to be looking for chartr(\\, /, path) (and FAQ Q7.8)

What does any of this have to do with 'url prep': URLs are never 
written with backslashes?


On Tue, 30 Aug 2011, Tyler Rinker wrote:





Greeting R
Community,

I am a
windows user so this problem may be specific to windows. I often want to source
files from within R

such as:
C:\Users\Rinker\Desktop\Research  Law\Data\School Data 09-10. To source
this file I need to go

through the
path and replace all the backslashes (\) with forward slashes (/). I usually do
this in MS Word

using the
replace option, however, I'd like to do this in R. Attempting to write a
function to do this runs into

problems:

When I
enter the following:

readyPath
- function(path){

z - gsub(\, /, path)

return(z)

}

I get:




readyPath - function(path){

+ z - gsub(\, /, path)

+ return(z)

+ }

+

...meaning
R can't close the sequence (presumably because of the backslash which has
special meaning).

So I tried
(\\):



readyPath - function(path){

z - gsub(\\, /, path)

return(z)

}This allows
the function to be stored as an object but I'm not sure if this is correct.


It isn't: please do read the help for gsub (\ is a metacharacter).


When I try
the function the backslash gets me again:




readyPath(C:\Users\Rinker\Desktop\Research  Law\Data\School Data
09-10)

Error: '\U' used without hex digits in character string starting
C:\U


You cannot do that: you have to scan a file or escape \


This is
what I'd like the function to return:

[1]
C:/Users/Rinker/Desktop/Research  Law/Data/School Data 09-10

I want a
function in which I enter a path and it returns the path with backslashes

replaced
with forward slashes. Is there a way to make a function to do this?


?normalizePath
chartr(\\, /, path)


Windows 7
user

R version
2.14 beta

Thank you,

Tyler
Rinker




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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] Saving a graph

2011-08-30 Thread Jannis
Chang Cheng,


this question has been asked on this list for several times. I would suggest 
you search the list archive (http://r.789695.n4.nabble.com/R-help-f789696.html 
or www.rseek.com) prior to posting in the future. graph size many points pdf 
would give you at least 10 threads with detailed description. There are 
numerous solutions and most of them point into Dieters or Brian Ripleys 
directions.


Jannis

--- Dieter Menne dieter.me...@menne-biomed.de schrieb am Di, 30.8.2011:

 Von: Dieter Menne dieter.me...@menne-biomed.de
 Betreff: Re: [R] Saving a graph
 An: r-help@r-project.org
 Datum: Dienstag, 30. August, 2011 05:57 Uhr
 
 Gang Chen-4 wrote:
  
  However, my problem is that the file generated
  from a graph of fixed size is too large (in the order
 of 10MB) because of
  many data points in multiple scatterplots. Any
 suggestions?
  
 
 Generate pdf, open and save it in Adobe Acrobat which does
 a compression
 when the setting are correct.
 
 Dieter
   
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Saving-a-graph-tp3777456p3778015.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org
 mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained,
 reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Conditional plots in the soiltexture package

2011-08-30 Thread samuel-rosa
Dear Julien

It is exactly what I need.

Thanks a lot.

-
Bc.Sc.Agri. Alessandro Samuel-Rosa
Postgraduate Program in Soil Science
Federal University of Santa Maria
Av. Roraima, nº 1000, Bairro Camobi, CEP 97105-970
Santa Maria, Rio Grande do Sul, Brazil
--
View this message in context: 
http://r.789695.n4.nabble.com/Conditional-plots-in-the-soiltexture-package-tp383p3778562.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] ATSP to TSP reformulation

2011-08-30 Thread Michael Hahsler

Hi Ian,

Your example runs for me without problems. It seems that you are using 
an older version of TSP. Please upgrade to the latest version TSP 
(update to TSP_1.0-3). I am using:


 sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] TSP_1.0-3

loaded via a namespace (and not attached):
[1] tools_2.13.1



Hint: use '-' instead of '=' for assignments.


Regards,
Michael

--
  Dr. Michael Hahsler, Visiting Assistant Professor
  Department of Computer Science and Engineering
  Lyle School of Engineering
  Southern Methodist University, Dallas, Texas

  (214) 768-8878 * mhahs...@lyle.smu.edu * http://lyle.smu.edu/~mhahsler

__
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] url prep function (backslash issue)

2011-08-30 Thread Tyler Rinker

Thank you Brian. When I wrote the email I typed url into the subject line by 
accident.  I mean path.   Thank you,Tyler

  Date: Tue, 30 Aug 2011 14:00:22 +0100
 From: rip...@stats.ox.ac.uk
 To: tyler_rin...@hotmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] url prep function (backslash issue)
 
 You seem to be looking for chartr(\\, /, path) (and FAQ Q7.8)
 
 What does any of this have to do with 'url prep': URLs are never 
 written with backslashes?
 
 On Tue, 30 Aug 2011, Tyler Rinker wrote:
 
 
 
 
  Greeting R
  Community,
 
  I am a
  windows user so this problem may be specific to windows. I often want to 
  source
  files from within R
 
  such as:
  C:\Users\Rinker\Desktop\Research  Law\Data\School Data 09-10. To source
  this file I need to go
 
  through the
  path and replace all the backslashes (\) with forward slashes (/). I 
  usually do
  this in MS Word
 
  using the
  replace option, however, I'd like to do this in R. Attempting to write a
  function to do this runs into
 
  problems:
 
  When I
  enter the following:
 
  readyPath
  - function(path){
 
  z - gsub(\, /, path)
 
  return(z)
 
  }
 
  I get:
 
 
  readyPath - function(path){
 
  + z - gsub(\, /, path)
 
  + return(z)
 
  + }
 
  +
 
  ...meaning
  R can't close the sequence (presumably because of the backslash which has
  special meaning).
 
  So I tried
  (\\):
 
 
 
  readyPath - function(path){
 
  z - gsub(\\, /, path)
 
  return(z)
 
  }This allows
  the function to be stored as an object but I'm not sure if this is correct.
 
 It isn't: please do read the help for gsub (\ is a metacharacter).
 
  When I try
  the function the backslash gets me again:
 
 
  readyPath(C:\Users\Rinker\Desktop\Research  Law\Data\School Data
  09-10)
 
  Error: '\U' used without hex digits in character string starting
  C:\U
 
 You cannot do that: you have to scan a file or escape \
 
  This is
  what I'd like the function to return:
 
  [1]
  C:/Users/Rinker/Desktop/Research  Law/Data/School Data 09-10
 
  I want a
  function in which I enter a path and it returns the path with backslashes
 
  replaced
  with forward slashes. Is there a way to make a function to do this?
 
 ?normalizePath
 chartr(\\, /, path)
 
  Windows 7
  user
 
  R version
  2.14 beta
 
  Thank you,
 
  Tyler
  Rinker
 
 
 
 
  [[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.
 
 
 -- 
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595
  
[[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] Configuring Proxy: Proxy Authentication Required with --internet2

2011-08-30 Thread Duncan Murdoch

On 30/08/2011 3:48 AM, behave wrote:

That was my first guess as well, but unfortunately this doesn't solve the
problem.

I is remarkably that IE requires authentification for every new instance I
open (even if another instance is already open)...

Any other hints?


You can read about how WinINet can be made to  handle authentication on 
this page:


http://msdn.microsoft.com/en-us/library/aa384220%28v=vs.85%29.aspx

(If that URL doesn't work, search for WinINet on microsoft.com, and 
navigate to Handling Authentication.)


To do any of this would require changes to the file 
https://svn.r-project.org/R/trunk/src/modules/internet/internet.c.  The 
USE_WININET_ASYNC macro is *not* defined, so ignore code in those 
ifdefs.  You could try changing the error handling code around line 791.


Since I don't use a proxy I can't test any of this and won't attempt it 
myself, but if you are able to make the changes and test them and they 
are reasonable looking, I'll consider incorporating them.


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.


Re: [R] url prep function (backslash issue)

2011-08-30 Thread Duncan Murdoch
Brian Ripley told you how to do the translation, but there's another 
problem:


On 30/08/2011 8:14 AM, Tyler Rinker wrote:

[ much deleted ]

When I try
the function the backslash gets me again:


readyPath(C:\Users\Rinker\Desktop\Research  Law\Data\School Data
09-10)


The problem is that you haven't entered a string containing backslashes, 
you've tried to enter a string containing escapes.  The parser sees a 
single backslash and attaches it to the next letter, so \U is taken to 
be the start of a Unicode character, and you get the error

Error: '\U' used without hex digits in character string starting
C:\U



The way around this is to avoid the parser, by something like this:

oldstring - readline()

C:\Users\Rinker\Desktop\Research  Law\Data\School Data 09-10


and then applying chartr to oldstring.

Duncan Murdoch



This is
what I'd like the function to return:

[1]
C:/Users/Rinker/Desktop/Research  Law/Data/School Data 09-10

I want a
function in which I enter a path and it returns the path with backslashes

replaced
with forward slashes. Is there a way to make a function to do this?

Windows 7
user

R version
2.14 beta

Thank you,

Tyler
Rinker




[[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] Showing zero frequencies with xtabs

2011-08-30 Thread Luca Meyer
Thanks Peter  Petr,

It was indeed an issue of having some character variables in there. Now it 
works just fine.

Cheers,
Luca

Il giorno 30/ago/2011, alle ore 10.15, peter dalgaard ha scritto:

 
 On Aug 30, 2011, at 10:04 , Luca Meyer wrote:
 
 Hi,
 
 Does anyone know how to show zero frequencies variable levels with the xtabs 
 command? They show with the table(x,y) command but I need to apply weight to 
 frequency tables and I also need to cbind several tables together, which 
 implies that they all need to show the same number of rows. 
 
 Are you sure you are doing the same thing as with table(). I'd expect it to 
 work if you ensure that the variables are factors:
 
 library(ISwR)
 xtabs(~sex+menarche,data=juul)
   menarche
 sex   1   2
  2 369 335
 
 juul$sex - factor(juul$sex,levels=1:2)
 xtabs(~sex+menarche,data=juul)
   menarche
 sex   1   2
  1   0   0
  2 369 335
 
 
 
 
 Alternatively, do you know how to column bind tables with different number 
 of rows? I cannot use merge as it requires daata.frame and that modifies the 
 look of the banner table I am trying to create...
 
 Thanks,
 Luca
 
 
 Mr. Luca Meyer
 www.lucameyer.com
 R version 2.13.1 (2011-07-08)
 Mac OS X 10.6.8
 
 
 
 
 
 
 
  [[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.
 
 -- 
 Peter Dalgaard, Professor
 Center for Statistics, Copenhagen Business School
 Solbjerg Plads 3, 2000 Frederiksberg, Denmark
 Phone: (+45)38153501
 Email: pd@cbs.dk  Priv: pda...@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.


[R] RES: Help with the 'reshape' package

2011-08-30 Thread Filipe Leme Botelho
Petr, many thanks. It´s very straightforward to to deal with the package, I had 
different sources of revenues for same company, same month, like below, and 
just by adding sum at the end of the function it collapsed values from all 
sources. Very useful! Cheers

cast(dta, Data~Company, value=Revenues, sum)

 Date  Company Revenues
 set-11A   3
 dez-11A   3,2
 jan-12A   3,3
 fev-12A   2,7
 mar-12A   2,7
 abr-12A   2,8
 mai-12A   2,9
 jun-12A   3
 jul-12A   3,1
 mar-12B   5
 abr-12B   5,5
 mai-12B   5,7
 jun-12B   7
 jul-12B   6,6
 dez-11C   1
 jan-12C   1,1
 fev-12C   1,11
 mar-12C   1,2
 abr-12C   1,3
 dez-11A   0,2
 jan-12A   4,3
 fev-12A   2,1
 mar-12A   2,2

A   B   C
01/09/2011  3   0   0
01/12/2011  3,4 0   1
01/01/2012  7,6 0   1,1
01/02/2012  4,8 0   1,11
01/03/2012  4,9 5   1,2
01/04/2012  2,8 5,5 1,3
01/05/2012  2,9 5,7 0
01/06/2012  3   7   0
01/07/2012  3,1 6,6 0

-Mensagem original-
De: Petr PIKAL [mailto:petr.pi...@precheza.cz] 
Enviada em: terça-feira, 30 de agosto de 2011 09:28
Para: Filipe Leme Botelho
Cc: r-help@r-project.org
Assunto: Re: [R] Help with the 'reshape' package

Hi
 Hi all,
 
 I am reading previous posts and guidance on the 'reshape' package in 
order
 to solve the simple problem below. Thinking that this might be very 
 trivial for most of you, I thought there could be a fast solution coming 

 from you guys, and I´d be very thankful for that.
 
 I have a matrix with dates, companies, prices, just like
 
 Date   Company   Price
 set-11   A   3
 dez-11   A   3,2
 jan-12   A   3,3
 fev-12   A   2,7
 mar-12   A   2,7
 abr-12   A   2,8
 mai-12   A   2,9
 jun-12   A   3
 jul-12   A   3,1
 mar-12   B   5
 abr-12   B   5,5
 mai-12   B   5,7
 jun-12   B   7
 jul-12   B   6,6
 dez-11   C   1
 jan-12   C   1,1
 fev-12   C   1,11
 mar-12   C   1,2
 abr-12   C   1,3
 
 and I want to convert it into something like below (missing data can be 
 zeros or NAs)
 
   A   B   C
 set-11   3   NA   NA
 dez-11   3,2   NA   1
 jan-12   3,3   NA   1,1
 fev-12   2,7   NA   1,11
 mar-12   2,7   5   1,2
 abr-12   2,8   5,5   1,3
 mai-12   2,9   5,7   NA
 jun-12   3   7   NA
 jul-12   3,1   6,6   NA



You have already melted data (long format). So simply cast

 cast(test, Date~Company)
Using Price as value column.  Use the value argument to cast to override 
this choice
Date   A   BC
1 abr-12 2.8 5.5 1.30
2 dez-11 3.2  NA 1.00
3 fev-12 2.7  NA 1.11
4 jan-12 3.3  NA 1.10
5 jul-12 3.1 6.6   NA
6 jun-12 3.0 7.0   NA
7 mai-12 2.9 5.7   NA
8 mar-12 2.7 5.0 1.20
9 set-11 3.0  NA   NA

Shall be OK.

Regards
Petr



 
 Workspace is attached. Thanks in advance.
 
 This message and its attachments may contain confidential and/or 
 privileged information. If you are not the addressee, please, advise the 

 sender immediately by replying to the e-mail and delete this message.
 
 Este mensaje y sus anexos pueden contener información confidencial o 
 privilegiada. Si ha recibido este e-mail por error por favor bórrelo y 
 envíe un mensaje al remitente.
 
 Esta mensagem e seus anexos podem conter informação confidencial ou 
 privilegiada. Caso não seja o destinatário, solicitamos a imediata 
 notificação ao remetente e exclusão da 
 mensagem.__
 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.


This message and its attachments may contain confidential and/or privileged 
information. If you are not the addressee, please, advise the sender 
immediately by replying to the e-mail and delete this message.

Este mensaje y sus anexos pueden contener información confidencial o 
privilegiada. Si ha recibido este e-mail por error por favor bórrelo y envíe un 
mensaje al remitente.

Esta mensagem e seus anexos podem conter informação confidencial ou 
privilegiada. Caso não seja o destinatário, solicitamos a imediata notificação 
ao remetente e exclusão da mensagem.

__
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] ATSP to TSP reformulation

2011-08-30 Thread Ian Deters
Dr. Hahsler,

Thank you so much for looking at my code.  I made sure that I had TSP_1.0-3
install and ran the code again (this time with - instead of = for my
assignments).  I received the same response.  I checked my sessionInfo and
did not see anything out of the ordinary.  Does anything look out of place
to you?  Thank you for your time.  Here is my sessionInfo:

R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

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

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

other attached packages:
[1] TSP_1.0-3

--
View this message in context: 
http://r.789695.n4.nabble.com/ATSP-to-TSP-reformulation-tp3777105p3778959.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] R cmd build error -- running 'zip' failed

2011-08-30 Thread Pitt, Joel
Hi All,
 
My attempts to build an R package on my Windows 7 computer using R V13.0 ir R 
V13.1 using 
 
R CMD build --binary  filename
 
have  been failing at the penultimate step with the error message running 
'zip' failed coming after the procedure has completed the MD5 sums step.The 
same build command on the same package completes successfully on my older Vista 
computer. 
 
Since I would prefer to do the builds on the Windows 7 computer I would 
appreciate any thoughts on why this maybe happening and what I can do to fix 
the problem.
 
Thanks and best regards,
Joel Pitt
 

[[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] Exception while using NeweyWest function with doMC

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 11:29 AM, Simon Zehnder wrote:


Hi David,

thank you very much for your advice! I updated R and all my  
packages. Regrettably it doesn't work yet. But, I think, that the  
parallel processing (using 32bit) does improve time, especially when  
it comes to higher dimensions:


system.time(simuFunctionSeq(0.03, 0.015, 1, 5, 1000, 100,/Users/ 
simon/Documents/R/BigMTest))
  system.time(simuFunctionPar(0.03, 0.015, 1, 5, 1000, 100,/Users/ 
simon/Documents/R/BigMTest))

[1] Sequential Processing with N =  1000  and K =  100
  user  system elapsed
 5.157   0.086   5.587
[1] Parallel Processing with N =  1000  and K =  100
  user  system elapsed
 6.069   0.220   3.895

: system.time(simuFunctionSeq(0.03, 0.015, 1, 5, 1, 100,/Users/ 
simon/Documents/R/BigMTest))
  system.time(simuFunctionPar(0.03, 0.015, 1, 5, 1, 100,/Users/ 
simon/Documents/R/BigMTest))

[1] Sequential Processing with N =  1  and K =  100
  user  system elapsed
 8.129   0.689  12.747
[1] Parallel Processing with N =  1  and K =  100
  user  system elapsed
 8.387   0.772  12.005

: system.time(simuFunctionSeq(0.03, 0.015, 1, 5, 1, 1000,/ 
Users/simon/Documents/R/BigMTest))
  system.time(simuFunctionPar(0.03, 0.015, 1, 5, 1, 1000,/Users/ 
simon/Documents/R/BigMTest))

[1] Sequential Processing with N =  1  and K =  1000
  user  system elapsed
71.295   6.330 109.656
[1] Parallel Processing with N =  1  and K =  1000
  user  system elapsed
50.943   6.347  89.115

Or are the times negligible?


I would think that for most applications getting a gain of efficiency  
of 20% would be considered unworthy of the effort at setting up and  
maintaining. I suppose if a simulation ran for 18 hours in sequential  
mode and you would be happier if it were done in the morning after  
leaving overnight and  finding it had completed in 15 hours, it might  
be worth the effort.


What happens if I use a supercomputer with several cores and much  
more memory?


Or even a MacPro with 4 or 8 cores and 32-64 GB?. Generally you hope  
to see halving or quartering in times when you apply these techniques.


--
David.



Thanks again!

Simon



On Aug 29, 2011, at 6:59 PM, David Winsemius wrote:



On Aug 27, 2011, at 3:37 PM, Simon Zehnder wrote:


Dear R users,

I am using R right now for a simulation of a model that needs a  
lot of
memory. Therefore I use the *bigmemory* package and - to make it  
faster -

the *doMC* package. See my code posted on http://pastebin.com/dFRGdNrG

Now, if I use the foreach loop with the addon %do% (for sequential  
run) I

have no problems at all - only here and there some singularities in
regressor matrices which should be ok.
BUT if I run the loop on multiple cores I get very often a bad  
exception. I
have posted the exception on http://pastebin.com/eMWF4cu0 The  
exception
comes from the NeweyWest function loaded within the sandwich  
library.


I have no clue, what it want to say me and why it is so weirdly  
printed to
the terminal. I am used to receive here and there errorsbut  
the messages

never look like this.

Does anyone have a useful answer for me, where to look for the  
cause of this

weird error?

Here some additional information:

Hardware: MacBook Pro 2.66 GHz Intel Core Duo, 4 GB Memory 1067  
MHz DDR3

Software System: Mac Os X Lion 10.7.1 (11B26)
Software App: R64 version 2.11.1 run via Mac terminal


Using the R64 version in a 4GB environment will reduce the  
effective memory capacity since the larger pointers take up more  
space, and using parallel methods is unlikely to improve  
performance very much with only two cores. It also seems likely  
that there have been several bug fixes in the last couple of years  
since that version of R was released, so the package authors are  
unlikely to be very interested in segfault errors thrown by  
outdated software.



I hope someone has a good suggestion!


Update R. Don't use features that only reduce performance and make  
unstable a machine that has limited resources.


--

David Winsemius, MD
West Hartford, CT





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] url prep function (backslash issue)

2011-08-30 Thread Tyler Rinker

Duncan, Thanks.  Combined with what Brian Ripley wrote it all works.   For 
future thread searchers this worked: oldstring - readline()
C:\Users\Rinker\Desktop\Research Law\Data\School Data 09-10
chartr(\\, /,oldstring) Thank you both,Tyler
 # Date: Tue, 30 Aug 2011 09:35:58 
-0400
 From: murdoch.dun...@gmail.com
 To: tyler_rin...@hotmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] url prep function (backslash issue)
 
 Brian Ripley told you how to do the translation, but there's another 
 problem:
 
 On 30/08/2011 8:14 AM, Tyler Rinker wrote:
 
 [ much deleted ]
  When I try
  the function the backslash gets me again:
 
  
  readyPath(C:\Users\Rinker\Desktop\Research  Law\Data\School Data
  09-10)
 
 The problem is that you haven't entered a string containing backslashes, 
 you've tried to enter a string containing escapes.  The parser sees a 
 single backslash and attaches it to the next letter, so \U is taken to 
 be the start of a Unicode character, and you get the error
  Error: '\U' used without hex digits in character string starting
  C:\U
 
 
 The way around this is to avoid the parser, by something like this:
 
 oldstring - readline()
 
 C:\Users\Rinker\Desktop\Research  Law\Data\School Data 09-10
 
 
 and then applying chartr to oldstring.
 
 Duncan Murdoch
 
 
  This is
  what I'd like the function to return:
 
  [1]
  C:/Users/Rinker/Desktop/Research  Law/Data/School Data 09-10
 
  I want a
  function in which I enter a path and it returns the path with backslashes
 
  replaced
  with forward slashes. Is there a way to make a function to do this?
 
  Windows 7
  user
 
  R version
  2.14 beta
 
  Thank you,
 
  Tyler
  Rinker
 
 
 
  
  [[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.


[R] multi-response regression with random forest

2011-08-30 Thread Cédric Mondy
Dear list,

I performed a multivariate analysis on freshwater invertebrates data. So
I obtained coordinates of my samples on the axes defining the first
factorial plane (F1 and F2).

I would like to see if the positions on my factorial plan could be
linked to levels of impairment ('low' vs 'significant') for several
water quality pressure categories and which pressure categories were the
most important to explain my data.

I first used random forests (package randomForest) to independently
regressed the F1 and F2 coordinates against my pressures levels. These
models explained around 13% of the variability for the first axis and
1.5% or the second axis. 

I heard about multi-response modelizations and tried to model the
bi-variate response F1+F2 from the same set of pressure levels. This
time, the model explained around 37% of the variability, that was great.

But I don't understand what is precisely modeled in such multi-response
regressions with random forest, when I used the predict() function on my
data I obtained only one value for each sample. What correspond to this
prediction? F1, F2, some combination of the both?

Any advice and links to helpful litterature would be appreciated,

Thanks,

Cédric

___

Here is a small extract of my input data :

ID  F1   F2  WQ1  WQ2  WQ3  WQ4
423007 -0.181720936 -0.031683254 Impaired Impaired Impaired Impaired
423432 -0.013823243 -0.044562244 Good Good Impaired Good
382886 -0.062171083  0.095592402 Good Impaired Good Impaired
349067  0.165199490 -0.006247771 Impaired Good Impaired Good
350787 -0.086522253 -0.001156491 Good Good Impaired Good
423700 -0.094519496  0.058552236 Good Good Impaired Good
1473   -0.030547960  0.041201208 Good Good Impaired Good
422893 -0.381074618 -0.108488149 Good Good Good Good
424323 -0.200710868  0.008960769 Good Impaired Impaired Impaired
351117 -0.026336697 -0.011788642 Good Good Impaired Good
423356 -0.095307898  0.032821813 Good Good Impaired Good
52  0.181933163 -0.070008234 Good Good Good Good
529 0.201013553 -0.039925550 Good Good Good Good
123 0.049202307 -0.255373209 Good Good Good Good
424332 -0.201756587 -0.007161893 Good Good Impaired Good
423925  0.182053115 -0.163286598 Good Good Good Good
422967  0.009489423  0.078132841 Good Good Impaired Good
423899  0.042904501  0.022193773 Good Good Good Good
350912  0.031308796  0.066608196 Good Good Good Good
422988 -0.049664431  0.063449869 Good Good Impaired Good

This is the formula I used for my model:

mod=randomForest((F1+F2)~., data=data, ntree = 500, mtry =
sqrt(ncol(data)-1))

The model summary:

Call:
 randomForest(formula = (F1 + F2) ~ ., data = data, ntree = 500,
mtry = sqrt(ncol(data) - 1)) 

   Type of random forest: regression
 Number of trees: 500
No. of variables tried at each split: 4

  Mean of squared residuals: 0.01772612
% Var explained: 37.98


And finally the predictions:

  prediction
423007  -0.256445319
423432  -0.078636802
382886  -0.088890538
349067  -0.118654211
350787  -0.112655013
423700   0.018815905
1473-0.032085983
422893  -0.303123232
424323  -0.226793376
351117   0.008599632
423356  -0.038947801
52   0.120712909
529  0.043381647
123 -0.087297539
424332  -0.180140229
423925   0.078654535
422967  -0.012138644
423899   0.078367004
350912   0.078654535
422988   0.014915818

__
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] character vector to text with returns

2011-08-30 Thread Ben qant
Hello,

I need to clarify, Henrique's suggestion worked great for getting the text
that I needed via cat(), but I haven't sorted out how to get cat() like
output into a variable so I can pass it into the message body variable I am
using.

Here is what I mean:
 x
[1] a b c d
 paste(x,collapse='\n')
[1] a\nb\nc\nd
 y = paste(x,collapse='\n')
 cat(y)
a
b
c
d

This is the problem with 'y' has the msg body:

paste(msg = MIMEText(',y,'),sep=)
[1] msg = MIMEText('a\nb\nc\nd')

This is what I am after (I think!):

paste(msg = MIMEText(',y,'),sep=)
[1] msg = MIMEText('a
b
c
d')


Here is how I am actually using it (with sensitive items generalized):

 require(rJython)
 rJython - rJython()
 rJython$exec( import smtplib )
 rJython$exec(from email.MIMEText import MIMEText)
 rJython$exec(import email.utils)

 mail-c(
 #Email settings
 fromaddr = 'ccqu...@gmail.com',
 toaddrs  = 'userna...@somethinghere.com',
 #msg = MIMEText('test message from R'),
 paste(msg = MIMEText(',y,'),sep=),# my message in this example is
'y'
 msg['From'] = email.utils.formataddr(('gmail acct', fromaddr)),
 msg['To'] = email.utils.formataddr(('cc email!', toaddrs)),
 msg['Subject'] = 'test with y',

 #SMTP server credentials
 username = 'ccqu...@gmail.com',
 password = 'a password here',

 #Set SMTP server and send email, e.g., google mail SMTP server
 server = smtplib.SMTP('smtp.gmail.com:587'),
 server.ehlo(),
 server.starttls(),
 server.ehlo(),
 server.login(username,password),
 server.sendmail(fromaddr, toaddrs, msg.as_string()),
 server.quit())

jython.exec(rJython,mail)  # and here is the error I get.
Error in ls(envir = envir, all.names = private) :
  invalid 'envir' argument


Just in case someone asks, I can do this:

y = a test

...and the above email sends fine with 'a test' as the msg body.

Any ideas?

PS - I received lots of suggestions. Thank you very much for your
effort/input.

Ben

On Mon, Aug 29, 2011 at 9:29 PM, Bert Gunter gunter.ber...@gene.com wrote:

 Is something like this what you want?

 x - letters[1:4]
 x
 y -do.call(paste,c( paste('',x[1]), as.list(x[2:3]),
 paste(x[4],''),sep=\n))
 y
 cat(y,\n)

 -- Bert


 On Mon, Aug 29, 2011 at 6:59 PM, Ben qant ccqu...@gmail.com wrote:
  Unfortunately that didn't work. I just says the text is an invalid
 argument.
  I also tried saving it in a variable name and passed that in, but that
  didn't work. I get:
 
  Error in ls(envir = envir, all.names = private) :
   invalid 'envir' argument
 
  ...when I try to send the message.
 
  Any other ideas?
 
  Thanks,
  Ben
 
  On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna www...@gmail.com
 wrote:
 
  Try:
 
  paste(c(a, b, c), collapse = \n)
 
  On Mon, Aug 29, 2011 at 8:56 PM, Ben qant ccqu...@gmail.com wrote:
 
  Hello,
 
  Does anyone know how to convert this:
   msg
   [1] a
   [2] b
   [3] c
 
 
  To:
 
   msg
  a
   b
   c
 
  In other words, I need to convert a character vector to a single string
  with
  carriage returns for each row.
 
  Functionally, I'm attempting to send an email of a character vector in
 a
  way
  that is readable in the email body. I can only input one string as the
  message body parameter. I'm using rJython to send the email because I
 need
  authentication.
 
  Thanks!
 
 [[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.
 
 



 --
 Men by nature long to get on to the ultimate truths, and will often
 be impatient with elementary studies or fight shy of them. If it were
 possible to reach the ultimate truths without the elementary studies
 usually prefixed to them, these would not be preparatory studies but
 superfluous diversions.

 -- Maimonides (1135-1204)

 Bert Gunter
 Genentech Nonclinical Biostatistics


[[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] Negative length vector error in simple merge

2011-08-30 Thread DimmestLemming
Hi,

I'm trying to take a vector (length almost 2,000,000) and merge it with a
data frame of the same length. I'm trying to do it solely based on index,
and not any other factors.

The vector is called offense, and the data frame is just called data. I
went with the simplest option:

merge(data,offense)

but it always gives me the same error:

Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) : 
  negative length vectors are not allowed

Solutions that haven't worked:
- Changing offense into a data frame
- Data doesn't exceed the 2^31 (2 billion) limit for length. When combined
with offense, it will have about 68 million items total

Thanks! DL

--
View this message in context: 
http://r.789695.n4.nabble.com/Negative-length-vector-error-in-simple-merge-tp3778980p3778980.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] test message

2011-08-30 Thread Gabor Grothendieck
Please ignore this message.

__
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] Help with the 'reshape' package

2011-08-30 Thread Gabor Grothendieck
On Tue, Aug 30, 2011 at 7:42 AM, Filipe Leme Botelho
filipe.bote...@vpar.com.br wrote:
 Hi all,

 I am reading previous posts and guidance on the 'reshape' package in order to 
 solve the simple problem below. Thinking that this might be very trivial for 
 most of you, I thought there could be a fast solution coming from you guys, 
 and I´d be very thankful for that.



Here is a zoo solution:

# first set up input

Lines - DateCompany Price
set-11  A   3
dez-11  A   3,2
jan-12  A   3,3
fev-12  A   2,7
mar-12  A   2,7
abr-12  A   2,8
mai-12  A   2,9
jun-12  A   3
jul-12  A   3,1
mar-12  B   5
abr-12  B   5,5
mai-12  B   5,7
jun-12  B   7
jul-12  B   6,6
dez-11  C   1
jan-12  C   1,1
fev-12  C   1,11
mar-12  C   1,2
abr-12  C   1,3

Sys.setlocale(LC_ALL, Portuguese)

library(zoo)

# The read.zoo command converts first column to yearmon class
# and reads it into a zoo object.

#  in next line we would normally
# replace textConnection(Lines) with file name, e.g. myfile.txt
# but here we do it this way to keep it self contained

z - read.zoo(textConnection(Lines), header = TRUE, dec = ,,
   split = 2, FUN = function(x) as.yearmon(x, format = %b-%y))

This gives the following zoo object:

 z
  A   BC
set 2011 3.0  NA   NA
dez 2011 3.2  NA 1.00
jan 2012 3.3  NA 1.10
fev 2012 2.7  NA 1.11
mar 2012 2.7 5.0 1.20
abr 2012 2.8 5.5 1.30
mai 2012 2.9 5.7   NA
jun 2012 3.0 7.0   NA

It may be more convenient to keep as a zoo object so you can do other
time series manipulations, e.g.

plot(z)
plot(z, screen = 1)

but you want it as a data frame:

DF - data.frame(Date = time(z), coredata(z))

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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.


[R] GMM with panel data

2011-08-30 Thread Cecilia Carmo
Hi everyone,

 

I´m starting with GMM estimator for panel data in R. In fact I’m starting
with GMM estimation with panel data, my research area is accounting and
finance, so I’ve been reading many «econometric» books but I have some
difficulties in applying GMM estimation. 

 

I’ve also read the article «Panel data econometrics in R: the plm package»
(Croissant  Millo) and my question is: 

Does the pggm() function performs the estimation based in Arellano and Bond
(1991)? If yes, is there any way to perform the estimation based in Blundell
and Bond (1998) (that seems to be a better estimator)?

 

Thank you,

Cecília Carmo (Universidade de Aveiro)

 

 


[[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] Exception while using NeweyWest function with doMC

2011-08-30 Thread Simon Zehnder
Hi Jay,

first: thank u very much for your comments! U made some very important points 
clear. I tried immediately to write directly the sample function from 

trade-as.big.matrix(matrix(sample(c(1,-1), (N+1)*K, replace=TRUE),ncol=K), 
backingpath=backingpath, backingfile=trade.bin,descriptorfile=trade.desc)

into the big matrix:

trade-big.matrix(sample(c(1,-1), (10+1), replace=TRUE),nrow=(10+1), ncol=10, 
type=double,backingpath=/Users/simon/Documents/R/BigMTest/, 
backingfile=terminaltest.bin, descriptorfile=terminaltest.desc)

But I either get only 1s:

trade[,]  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]111111111 1
 [2,]111111111 1
 [3,]111111111 1
 [4,]111111111 1
 [5,]111111111 1
 [6,]111111111 1
 [7,]111111111 1
 [8,]111111111 1
 [9,]111111111 1
[10,]111111111 1
[11,]111111111 1

or only -1s:

trade[,]  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [2,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [3,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [4,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [5,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [6,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [7,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [8,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [9,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
[10,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
[11,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1

Is there another possibility? In addition I found under ?as.big.matrix, for the 
second example the usage of matrix() inside of as.big.matrix(). But if I 
understood u correctly: usage is possible but does not save memory? I used the 
big.memory package because I always got  - using simply matrix() - exceptions, 
telling me, that memory has reached its limits. After using big.memory all 
worked fine, BUT running http://pastebin.com/UxSkzrae and  
http://pastebin.com/MErGQsQd , I got this: http://pastebin.com/KrEncrSz. It 
seems, as there is a problem with memory allocation inside the underlying 
C-code, maybe a result from my matrix generation inside of the big matrix?

Any suggestions?

 

On Aug 29, 2011, at 6:24 PM, Jay Emerson wrote:

 Simon,
 
 Though we're please to see another use of bigmemory, it really isn't
 clear that it is gaining you
 anything in your example; anything like as.big.matrix(matrix(...))
 still consumes full RAM for both
 the inner matrix() and the new big.matrix -- is the filebacking really
 necessary.  It also doesn't
 appear that you are making use of shared memory, so I'm unsure what
 the gains are.  However,
 I don't have any particular insight as to the subsequent problem with
 NeweyWest (which doesn't
 seem to be using the big.matrix objects).
 
 Jay
 
 --
 Message: 32
 Date: Sat, 27 Aug 2011 21:37:55 +0200
 From: Simon Zehnder simon.zehn...@googlemail.com
 To: r-help@r-project.org
 Subject: [R] Exception while using NeweyWest function with doMC
 Message-ID:
   cagqvrp_gk+t0owbv1ste-y0zafmi9s_zwqrxyxugsui18ms...@mail.gmail.com
 Content-Type: text/plain
 
 Dear R users,
 
 I am using R right now for a simulation of a model that needs a lot of
 memory. Therefore I use the *bigmemory* package and - to make it faster -
 the *doMC* package. See my code posted on http://pastebin.com/dFRGdNrG
 
  snip 
 -
 
 -- 
 John W. Emerson (Jay)
 Associate Professor of Statistics
 Department of Statistics
 Yale University
 http://www.stat.yale.edu/~jay


[[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] R crash

2011-08-30 Thread Ivan Calandra

Dear users,

By running the script below, R crashes systematically at the last 
command, namely dev.off(), on Windows 7, but not on Windows XP.
I therefore don't provide a reproducible example and do not really 
extract the relevant parts of the script because it has most likely 
nothing to do with the script itself. I can do it though if you think it 
might be relevant.


R crashes on Windows 7, sessionInfo():
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
 [1] doBy_4.4.0 MASS_7.3-13snow_0.3-7 
lme4_0.999375-41
 [5] Matrix_0.9996875-3 lattice_0.19-30multcomp_1.2-7 
mvtnorm_0.9-9991
 [9] R2HTML_2.2 survival_2.36-9RSvgDevice_0.6.4.1 
R.utils_1.7.8

[13] R.oo_1.8.1 R.methodsS3_1.2.1

loaded via a namespace (and not attached):
[1] grid_2.13.1   nlme_3.1-101  stats4_2.13.1

But it works perfectly on Windows XP, sessionInfo():
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

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

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

other attached packages:
 [1] doBy_4.4.0 MASS_7.3-14snow_0.3-6 
lme4_0.999375-41
 [5] Matrix_0.9996875-3 lattice_0.19-33multcomp_1.2-7 
mvtnorm_0.9-9991
 [9] R2HTML_2.2 survival_2.36-9RSvgDevice_0.6.4.1 
R.utils_1.7.8

[13] R.oo_1.8.1 R.methodsS3_1.2.1

loaded via a namespace (and not attached):
[1] grid_2.13.1   nlme_3.1-102  stats4_2.13.1

Except the locale, I don't see any difference and I don't really 
understand how that would make R crash by running dev.off(). Is there 
anything else than sessionInfo()?


Thank you for your help,
Ivan



 script -

library(R.utils)
library(RSvgDevice)
library(doBy)
primate_med - loadObject(primate_med.Rbin)

select - primate_med   #data object to use
seq.yvar - c(5,12,8,9)
ind.xvar - 4

 filename - paste(regression, names(datobj)[ind.xvar], 
paste(names(datobj)[seq.yvar],collapse=_), 
paste(selvarstr,collapse=_), sep=_)

 filename - gsub(.median, , filename)

 select_mean - 
summaryBy(as.formula(paste(.~,names(select)[ind.xvar])), data=select, 
FUN=mean)


 devSVG(file=paste(filename, .svg, sep=))
 par(mfrow=c(2,2))
 diff_len - length(select)-length(select_mean)

 for (i in seq_along(seq.yvar)){
  k - seq.yvar[i]
  plot(select[[k]]~select[[ind.xvar]], type=p, pch=1, 
xlab=names(select)[ind.xvar], ylab=names(select)[k], las=1)
  points(select_mean[[ind.xvar-diff_len]], select_mean[[k-diff_len]], 
pch=18, cex=2)

  two_reg(dat=select, xvar=ind.xvar, yvar=k)
 }

 dev.off()

-

--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Dept. Mammalogy
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

__
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] Negative length vector error in simple merge

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 11:08 AM, DimmestLemming wrote:


Hi,

I'm trying to take a vector (length almost 2,000,000) and merge it  
with a
data frame of the same length. I'm trying to do it solely based on  
index,

and not any other factors.

The vector is called offense, and the data frame is just called  
data.


Bad name. There is a function named 'data'.


I
went with the simplest option:

merge(data,offense)


It wouldn't make much sense to merge a vector with a dataframe. The  
matching column should not appear any different except perhaps  
shorter. Sounds like you want cbind() rather than merge.


(You really should have posted str(.) on both objects.)

--
David.



but it always gives me the same error:

Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) :
 negative length vectors are not allowed

Solutions that haven't worked:
- Changing offense into a data frame
- Data doesn't exceed the 2^31 (2 billion) limit for length. When  
combined

with offense, it will have about 68 million items total

Thanks! DL

--
View this message in context: 
http://r.789695.n4.nabble.com/Negative-length-vector-error-in-simple-merge-tp3778980p3778980.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.


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] algorithm to merge same entries in a matrix

2011-08-30 Thread Martin Batholdy
Hi,

I have the following, rather unorthodox problem:


I have a matrix that looks like this:

m1 - matrix(c('a','b','d',NA,'c','c'), 2,3, byrow=TRUE)


[,1] [,2] [,3]
[1,]  a  b  d 
[2,] NA   c  c 


now I would like to transform this matrix into this matrix:

[,1] [,2] [,3] [,4]
[1,]  a  b  c  d 
[2,] NA NA NA NA


so the rule is:

if I find the same value (above: 'c') in neighbored cells (here: row wise) put 
this value in row 1 in a new column between
column of neighbor a and column of neighbor b.





too make it even more complicated:
the definition of neighbored cells is not exclusively row wise.




So for example I could encounter this kind of matrix:

m2 - matrix(c('a','b','d',NA,NA,'c',NA, 'c', NA), 3,3, byrow=TRUE)


   [,1] [,2] [,3]
[1,] a  b  d 
[2,] NA NA  c 
[3,] NA c  NA  

which should also be transformed into:

[,1] [,2] [,3] [,4]
[1,]  a  b  c  d 
[2,] NA NA NA NA


(or m3 - matrix(c('a','b','d',NA,'c',NA,NA, NA, 'c'), 3,3, byrow=TRUE) ).



Can perhaps someone give me some hints how to solve this efficiently?

I think I could solve that with some loops … but I also need to make sure that 
it is efficient / not taking too much time.


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] R cmd build error -- running 'zip' failed

2011-08-30 Thread Duncan Murdoch

On 30/08/2011 11:05 AM, Pitt, Joel wrote:

Hi All,

My attempts to build an R package on my Windows 7 computer using R V13.0 ir R 
V13.1 using

R CMD build --binaryfilename

have  been failing at the penultimate step with the error message running 'zip' 
failed coming after the procedure has completed the MD5 sums step.The same build 
command on the same package completes successfully on my older Vista computer.

Since I would prefer to do the builds on the Windows 7 computer I would 
appreciate any thoughts on why this maybe happening and what I can do to fix 
the problem.


Sounds like a problem with your PATH.

Duncan Murdoch



Thanks and best regards,
Joel Pitt


[[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] character vector to text with returns

2011-08-30 Thread Ben qant
Hello,

(Sorry if this is a dup post...)

I need to clarify, Henrique's suggestion worked great for getting the text
that I needed via cat(), but I haven't sorted out how to get cat() like
output into a variable so I can pass it into the message body variable I am
using.

Here is what I mean:
 x
[1] a b c d
 paste(x,collapse='\n')
[1] a\nb\nc\nd
 y = paste(x,collapse='\n')
 cat(y)
a
b
c
d

This is the problem with 'y' has the msg body:

paste(msg = MIMEText(',y,'),sep=)
[1] msg = MIMEText('a\nb\nc\nd')

This is what I am after (I think!):

paste(msg = MIMEText(',y,'),sep=)
[1] msg = MIMEText('a
b
c
d')


Here is how I am actually using it (with sensitive items generalized):

 require(rJython)
 rJython - rJython()
 rJython$exec( import smtplib )
 rJython$exec(from email.MIMEText import MIMEText)
 rJython$exec(import email.utils)

 mail-c(
 #Email settings
 fromaddr = 'ccqu...@gmail.com',
 toaddrs  = 'userna...@somethinghere.com'
- Show quoted text -
jython.exec(rJython,mail)  # and here is the error I get.

Error in ls(envir = envir, all.names = private) :
  invalid 'envir' argument


Just in case someone asks, I can do this:

y = a test

...and the above email sends fine with 'a test' as the msg body.

Any ideas?

PS - I received lots of suggestions. Thank you very much for your
effort/input.

Ben


On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna www...@gmail.comwrote:

 Try:

 paste(c(a, b, c), collapse = \n)

 On Mon, Aug 29, 2011 at 8:56 PM, Ben qant ccqu...@gmail.com wrote:

 Hello,

 Does anyone know how to convert this:
  msg
  [1] a
  [2] b
  [3] c


 To:

  msg
 a
  b
  c

 In other words, I need to convert a character vector to a single string
 with
 carriage returns for each row.

 Functionally, I'm attempting to send an email of a character vector in a
 way
 that is readable in the email body. I can only input one string as the
 message body parameter. I'm using rJython to send the email because I need
 authentication.

 Thanks!

[[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] Negative length vector error in simple merge

2011-08-30 Thread DimmestLemming
Thanks! I'd just never heard of cbind or rbind... bit new.

--
View this message in context: 
http://r.789695.n4.nabble.com/Negative-length-vector-error-in-simple-merge-tp3778980p3779267.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] character vector to text with returns

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 1:09 PM, Ben qant wrote:


Hello,

(Sorry if this is a dup post...)

I need to clarify, Henrique's suggestion worked great for getting  
the text
that I needed via cat(), but I haven't sorted out how to get cat()  
like
output into a variable so I can pass it into the message body  
variable I am

using.


cat() is not the right function to get text assgned to an object. It's  
entire purpose is to have a side-effect and _not_ return anything into  
R's workspace. Why are you not assigning the result of that paste  
operation to the variable?





Here is what I mean:
x
[1] a b c d
paste(x,collapse='\n')
[1] a\nb\nc\nd
y = paste(x,collapse='\n')
cat(y)
a
b
c
d

This is the problem with 'y' has the msg body:

paste(msg = MIMEText(',y,'),sep=)
[1] msg = MIMEText('a\nb\nc\nd')

This is what I am after (I think!):

paste(msg = MIMEText(',y,'),sep=)
[1] msg = MIMEText('a
b
c
d')


Here is how I am actually using it (with sensitive items generalized):

require(rJython)
rJython - rJython()
rJython$exec( import smtplib )
rJython$exec(from email.MIMEText import MIMEText)
rJython$exec(import email.utils)

mail-c(
#Email settings
fromaddr = 'ccqu...@gmail.com',
toaddrs  = 'userna...@somethinghere.com'
- Show quoted text -
jython.exec(rJython,mail)  # and here is the error I get.

Error in ls(envir = envir, all.names = private) :
 invalid 'envir' argument


Just in case someone asks, I can do this:

y = a test

...and the above email sends fine with 'a test' as the msg body.

Any ideas?

PS - I received lots of suggestions. Thank you very much for your
effort/input.

Ben


On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna www...@gmail.com 
wrote:



Try:

paste(c(a, b, c), collapse = \n)

On Mon, Aug 29, 2011 at 8:56 PM, Ben qant ccqu...@gmail.com wrote:


Hello,

Does anyone know how to convert this:

msg

[1] a
[2] b
[3] c


To:


msg

a
b
c

In other words, I need to convert a character vector to a single  
string

with
carriage returns for each row.

Functionally, I'm attempting to send an email of a character  
vector in a

way
that is readable in the email body. I can only input one string as  
the
message body parameter. I'm using rJython to send the email  
because I need

authentication.

Thanks!

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


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] having trouble extracting week from chron object

2011-08-30 Thread Christopher W Ryan
Running R 2.13.1 on Windows XP.
I would like to get week of the year (1-52) for each date.

library(chron)
dts - dates(c(02/27/92, 02/27/92, 01/14/92,02/28/92, 02/01/92))
dts
dts.chron - as.chron(dts)
dts.chron
class(dts.chron)
# all of these component extractions work:
months(dts.chron)
weekdays(dts.chron)
years(dts.chron)
quarters(dts.chron)
# but weeks() doesn't seem to work
weeks(dts.chron)

?chron tells me: . . . The functions days(), months(), quarters(),
years(), weeks(), weekdays(), hours(), minutes(), and seconds() take
any chron object as input and extract the corresponding time interval
. . . .

Any advice?

Thanks.

Chris Ryan
SUNY Upstate Medical University Clinical Campus at Binghamton
Binghamton, NY

__
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] Negative length vector error in simple merge

2011-08-30 Thread Nordlund, Dan (DSHS/RDA)
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of DimmestLemming
 Sent: Tuesday, August 30, 2011 10:20 AM
 To: r-help@r-project.org
 Subject: Re: [R] Negative length vector error in simple merge
 
 Thanks! I'd just never heard of cbind or rbind... bit new.
 

If you had never heard of cbind or rbind, then would be doing yourself a BIG 
favor by reading the Introduction to R that comes with every copy of R.

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


__
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] column names with rbind loop

2011-08-30 Thread Vining, Kelly
Hello R  users.

This is a fairly basic question:

I am concatenating data from sets of files in a directory using a loop. The 
column names in all files are exactly the same. My understanding is that rbind 
takes column names from the first file it reads. However, my output is showing 
that the column names are treated as a first data row, not treated as headers.

I compile my file names like this:

 all.files - list.files()
 all.files
 [1] 1.rpkm  10.rpkm 11.rpkm 12.rpkm 13.rpkm 14.rpkm
 [7] 15.rpkm 16.rpkm 17.rpkm 18.rpkm 19.rpkm 2.rpkm 
[13] 3.rpkm  4.rpkm  5.rpkm  6.rpkm  7.rpkm  8.rpkm 
[19] 9.rpkm 

Then loop through them like this:
 new.data - NULL
 for(i in all.files) {
+ in.data - read.table(i)
+ new.data - rbind(new.data, in.data)}
 head(new.data)
 V1   V2V3 V4 V5V6 V7
1 seq_id   source  type  startend score strand
2 scaffold_1 Ptrichocarpav2_0 gene_body  12639  13384 .  +
3 scaffold_1 Ptrichocarpav2_0 gene_body  22190  22516 .  +
4 scaffold_1 Ptrichocarpav2_0 gene_body  74076  75893 .  +
5 scaffold_1 Ptrichocarpav2_0 gene_body  80207  81289 .  -
6 scaffold_1 Ptrichocarpav2_0 gene_body 105236 107712 .  +


As you can see, R is putting a V1, V2... header row here because I didn't say 
header=TRUE in my read.table command. But if I do this within the loop, I get 
an error. If I try to delete the V1, V2 row after the fact by 

new.data - new.data[-1,]

R deletes my real header row. 

How can I get the header that I want?

Thanks for any help,
--Kelly V.

__
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] Gradient function in OPTIMX

2011-08-30 Thread Ravi Varadhan
Hi Kathie,

The gradient check in optimx checks if the user specified gradient (at 
starting parameters) is within roughly 1.e-05 * (1 + fval) of the numerically 
computed gradient. It is likely that you have correctly coded up the gradient, 
but still there can be significant differences b/w numerical and exact 
gradients.  This can happen when the gradients are very large.  

I would check this again separately as follows:

require(numDeriv)

mygrad -  gr.fy(theta0)

numgrad - grad(x=theta0, func=gr.fy)

cbind(mygrad, numgrad)

all.equal(mygrad, numgrad)

Can you report these gradients to us?

In optimx, we should probably change this into a warning rather than a 
stop. 

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

__
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] having trouble extracting week from chron object

2011-08-30 Thread Jannis
Well, there is no function called weeks in chron. Funny that the help 
mentions it.


You can, however, use normal POSIXct objects and extract the week with:

 dts - dates(c(02/27/92, 02/27/92))
 dts.posx - as.POSIXct(dts)
 result   - as.integer(format(dts.posx,format=%W))



HTH
Jannis

--- Christopher W Ryan cr...@binghamton.edu schrieb am Di, 30.8.2011:

 Von: Christopher W Ryan cr...@binghamton.edu
 Betreff: [R] having trouble extracting week from chron object
 An: R-help@r-project.org
 Datum: Dienstag, 30. August, 2011 17:36 Uhr
 Running R 2.13.1 on Windows XP.
 I would like to get week of the year (1-52) for each date.
 
 library(chron)
 dts - dates(c(02/27/92, 02/27/92,
 01/14/92,02/28/92, 02/01/92))
 dts
 dts.chron - as.chron(dts)
 dts.chron
 class(dts.chron)
 # all of these component extractions work:
 months(dts.chron)
 weekdays(dts.chron)
 years(dts.chron)
 quarters(dts.chron)
 # but weeks() doesn't seem to work
 weeks(dts.chron)
 
 ?chron tells me: . . . The functions days(), months(),
 quarters(),
 years(), weeks(), weekdays(), hours(), minutes(), and
 seconds() take
 any chron object as input and extract the corresponding
 time interval
 . . . .
 
 Any advice?
 
 Thanks.
 
 Chris Ryan
 SUNY Upstate Medical University Clinical Campus at
 Binghamton
 Binghamton, NY
 
 __
 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] having trouble extracting week from chron object

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 1:36 PM, Christopher W Ryan wrote:


Running R 2.13.1 on Windows XP.
I would like to get week of the year (1-52) for each date.

library(chron)
dts - dates(c(02/27/92, 02/27/92, 01/14/92,02/28/92,  
02/01/92))

dts
dts.chron - as.chron(dts)
dts.chron
class(dts.chron)
# all of these component extractions work:
months(dts.chron)
weekdays(dts.chron)
years(dts.chron)
quarters(dts.chron)
# but weeks() doesn't seem to work


It doesn't work for me either but since I also have the package  
lubridate loaded, and ?weeks brings up a lubridate help page, I don't  
feel I have any right to complain. I get an error message what did  
you get?:


Error in Ops.dates(pieces$week, 7) : * not defined for chron objects

If I were posting I would also have had the good sense to include the  
output of sessionInfo().



weeks(dts.chron)


Try type just:

 weeks  # I get a lubridate function.



?chron tells me:



Bur what does ?weeks tell you?


. . . The functions days(), months(), quarters(),
years(), weeks(), weekdays(), hours(), minutes(), and seconds() take
any chron object as input and extract the corresponding time interval
. . . .

Any advice?

Thanks.

Chris Ryan
SUNY Upstate Medical University Clinical Campus at Binghamton
Binghamton, NY

__
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] RPostgreSQL Loading Issues

2011-08-30 Thread Rich Shepard

  I'm starting to seriously use R and have tried to solve this issue using
my reference books but I'm missing something simple. Running R-2.13.1 on
Slackware-13.1.

  Trying to invoke RPostgreSQL so I can copy data from a postgres table to
an R data-frame. I installed RPostgreSQL and the library() command shows
it's present:

Packages in library
'/home/rshepard/R/i486-slackware-linux-gnu-library/2.13':

DBI R Database Interface
RPostgreSQL R interface to the PostgreSQL database system

  Yet, trying to load it fails:


library(RPostgreSQL)

Loading required package: DBI
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object
'/home/rshepard/R/i486-slackware-linux-gnu-library/2.13/RPostgreSQL/libs/RPostgreSQL.so':
  libR.so: cannot open shared object file: No such file or directory
Error: package/namespace load failed for 'RPostgreSQL'

  The shared library, of course, is present:

[rshepard@salmo ~/R/i486-slackware-linux-gnu-library/2.13/RPostgreSQL/libs]$ ll
-rwxr-xr-x 1 rshepard users 44385 2011-08-03 20:13 RPostgreSQL.so*

  Can someone explain to me what's going on and how I fix it?

Rich

__
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] lubridate and intervals

2011-08-30 Thread Justin Haynes
Hiya,

maybe there is a native R function for this and if so please let me know!

I have 2 data.frames with start and end dates, they read in as strings and I
am converting to POSIXct.  How can I check for overlap?

The end result ideally will be a single data.frame containing all the
columns of the other two with rows where there were date overlaps.


df1-data.frame(start=as.POSIXct(paste('2011-06-01 ',1:20,':00',sep='')),
end=as.POSIXct(paste('2011-06-01 ',1:20,':30',sep='')))
df2-data.frame(start=as.POSIXct(paste('2011-06-01
',rep(seq(1,20,2),2),':',sample(1:19,20,replace=T),sep='')),
end=as.POSIXct(paste('2011-06-01
',rep(seq(1,20,2),2),':',sample(20:50,20),sep='')))

I tried:
library(lubridate)

df1$interval-new_interval(df1$start,df1$end)

 df1$interval[1]
[1] 2011-06-01 01:00:00 -- 2011-06-01 01:30:00
 df2$start[1]
[1] 2011-06-01 01:17:00 PDT

but

 df2$start[1] %in% df1$interval[1]
[1] FALSE


This must be fairly straight forward and I just don't know where to look!


Thanks,
Justin

[[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] character vector to text with returns

2011-08-30 Thread Ben qant
David,

Yes, I understand that cat() won't do what I want, but that is the only way
I can illustrate what I am after. Note the phrasing in my question:
'...cat() like...'

Regarding assigning the paste  to a variable: it produces the same error.
I've already tried that.

Thanks for your suggestion!

Ben

On Tue, Aug 30, 2011 at 11:24 AM, David Winsemius dwinsem...@comcast.netwrote:


 On Aug 30, 2011, at 1:09 PM, Ben qant wrote:

  Hello,

 (Sorry if this is a dup post...)

 I need to clarify, Henrique's suggestion worked great for getting the text
 that I needed via cat(), but I haven't sorted out how to get cat() like
 output into a variable so I can pass it into the message body variable I
 am
 using.


 cat() is not the right function to get text assgned to an object. It's
 entire purpose is to have a side-effect and _not_ return anything into R's
 workspace. Why are you not assigning the result of that paste operation to
 the variable?




 Here is what I mean:
 x
 [1] a b c d
 paste(x,collapse='\n')
 [1] a\nb\nc\nd
 y = paste(x,collapse='\n')
 cat(y)
 a
 b
 c
 d

 This is the problem with 'y' has the msg body:

 paste(msg = MIMEText(',y,'),sep=)
 [1] msg = MIMEText('a\nb\nc\nd')

 This is what I am after (I think!):

 paste(msg = MIMEText(',y,'),sep=)
 [1] msg = MIMEText('a
 b
 c
 d')


 Here is how I am actually using it (with sensitive items generalized):

 require(rJython)
 rJython - rJython()
 rJython$exec( import smtplib )
 rJython$exec(from email.MIMEText import MIMEText)
 rJython$exec(import email.utils)

 mail-c(
 #Email settings
 fromaddr = 'ccqu...@gmail.com',
 toaddrs  = 'userna...@somethinghere.com'
 - Show quoted text -
 jython.exec(rJython,mail)  # and here is the error I get.

 Error in ls(envir = envir, all.names = private) :
  invalid 'envir' argument


 Just in case someone asks, I can do this:

 y = a test

 ...and the above email sends fine with 'a test' as the msg body.

 Any ideas?

 PS - I received lots of suggestions. Thank you very much for your
 effort/input.

 Ben


 On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna www...@gmail.com
 wrote:

  Try:

 paste(c(a, b, c), collapse = \n)

 On Mon, Aug 29, 2011 at 8:56 PM, Ben qant ccqu...@gmail.com wrote:

  Hello,

 Does anyone know how to convert this:

 msg

 [1] a
 [2] b
 [3] c


 To:

  msg

 a
 b
 c

 In other words, I need to convert a character vector to a single string
 with
 carriage returns for each row.

 Functionally, I'm attempting to send an email of a character vector in a
 way
 that is readable in the email body. I can only input one string as the
 message body parameter. I'm using rJython to send the email because I
 need
 authentication.

 Thanks!

  [[alternative HTML version deleted]]

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/**posting-guide.htmlhttp://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-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 David Winsemius, MD
 West Hartford, CT



[[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] ATSP to TSP reformulation

2011-08-30 Thread Michael Hahsler

Hi Ian,

I checked your example again and found the problem in tsp. fix(x) seems 
to create column names but not row names which exposes a bug in as.ATSP 
in tsp.


This code replicates your error message:

library(TSP)
x - rbind(c(1,2,3,4), c(1,0,11,5), c(2,4,0,6), c(3,5,6,0))
colnames(x) - 1:4
#rownames(x) - 1:4
atsp - ATSP(x)
tsp - reformulate_ATSP_as_TSP(atsp)

if you uncomment the rownames line then it works. I already fixed the 
code in tsp to check for missing col/row names in the matrix. This fix 
will be part of the next release. For now please just add row names to 
the matrix.


Thanks for the bug report!

-Michael

--
  Dr. Michael Hahsler, Visiting Assistant Professor
  Department of Computer Science and Engineering
  Lyle School of Engineering
  Southern Methodist University, Dallas, Texas

  (214) 768-8878 * mhahs...@lyle.smu.edu * http://lyle.smu.edu/~mhahsler

__
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] rpart: apply tree to new data to get counts

2011-08-30 Thread Stephen Milborrow

Jay josip.2...@gmail.com het geskryf

When I have made a decision tree with rpart, is it possible to apply
this tree to a new set of data in order to find out the distribution
of observations? Ideally I would like to plot my original tree, with
the counts (at each node) of the new data.


Sadly, neither plot.rpart or rpart.plot support plotting a tree trained on 
one set of data but showing results predicted for a new set of data.  Page 
21 of the vignette for the rpart.plot package has this to say


Arguably the most serious limitation of the current implementation is its 
inability to display results on test data (on the tree derived from the 
training data).


One way of implementing this (quite a lot of work) would be to extend the 
rpart function to include a newdata argument.  If given such an argument, 
rpart would additionally return new.frame, new.where, and new.y fields 
(corresponding to the existing frame, where, and y fields).  The plotting 
functions could then trivially be extended to use these new fields.


__
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] locate the needed columns

2011-08-30 Thread Hui Du

Hi All,

I have a data frame, whose colnames like A.x, B.x, C.x, A.y, 
B.y, C.y. There could be many columns like this pattern. I want to compare 
data in columns A.x with A.y, B.x with B.y and C.x with C.y etc.
Suppose my data frame is d,
names(d) = c(A.x, B.x, C.x, A.y, B.y, C.y);

If I want to
D1 = data.frame(d$A.x, d$A.y);
D2 = data.frame(d$B.x, d$B.y); etc. or do other operation for each pair,


What is elegant way to do it rather than use a loop?

Thanks.

HXD


[[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] having trouble extracting week from chron object

2011-08-30 Thread Christopher W Ryan
Here it is with the output:

 library(chron)
 dts - dates(c(02/27/92, 02/27/92, 01/14/92,02/28/92, 02/01/92))
 dts
[1] 02/27/92 02/27/92 01/14/92 02/28/92 02/01/92
 dts.chron - as.chron(dts)
 dts.chron
[1] 02/27/92 02/27/92 01/14/92 02/28/92 02/01/92
 class(dts.chron)
[1] dates times
 # all of these component extractions work:
 months(dts.chron)
[1] Feb Feb Jan Feb Feb
12 Levels: Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  ...  Dec
 weekdays(dts.chron)
[1] Thu Thu Tue Fri Sat
Levels: Sun  Mon  Tue  Wed  Thu  Fri  Sat
 years(dts.chron)
[1] 1992 1992 1992 1992 1992
Levels: 1992
 quarters(dts.chron)
[1] 1Q 1Q 1Q 1Q 1Q
Levels: 1Q  2Q  3Q  4Q
 # but weeks() doesn't seem to work
 weeks(dts.chron)
Error: could not find function weeks
 ?weeks
No documentation for 'weeks' in specified packages and libraries:
you could try '??weeks'
 weeks
Error: object 'weeks' not found
 week
Error: object 'week' not found

 sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

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

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

other attached packages:
[1] chron_2.3-42

Thanks.

--Chris Ryan


On Tue, Aug 30, 2011 at 1:54 PM, David Winsemius dwinsem...@comcast.net wrote:

 On Aug 30, 2011, at 1:36 PM, Christopher W Ryan wrote:

 Running R 2.13.1 on Windows XP.
 I would like to get week of the year (1-52) for each date.

 library(chron)
 dts - dates(c(02/27/92, 02/27/92, 01/14/92,02/28/92, 02/01/92))
 dts
 dts.chron - as.chron(dts)
 dts.chron
 class(dts.chron)
 # all of these component extractions work:
 months(dts.chron)
 weekdays(dts.chron)
 years(dts.chron)
 quarters(dts.chron)
 # but weeks() doesn't seem to work

 It doesn't work for me either but since I also have the package lubridate
 loaded, and ?weeks brings up a lubridate help page, I don't feel I have any
 right to complain. I get an error message what did you get?:

 Error in Ops.dates(pieces$week, 7) : * not defined for chron objects

 If I were posting I would also have had the good sense to include the output
 of sessionInfo().

 weeks(dts.chron)

 Try type just:

  weeks  # I get a lubridate function.


 ?chron tells me:


 Bur what does ?weeks tell you?

 . . . The functions days(), months(), quarters(),
 years(), weeks(), weekdays(), hours(), minutes(), and seconds() take
 any chron object as input and extract the corresponding time interval
 . . . .

 Any advice?

 Thanks.

 Chris Ryan
 SUNY Upstate Medical University Clinical Campus at Binghamton
 Binghamton, NY

 __
 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] Why does loading saved/cached objects add significantly to RAM consumption?

2011-08-30 Thread Henrik Bengtsson
Hi.

On Tue, Aug 30, 2011 at 3:59 AM, Janko Thyson
janko.thyson.rst...@googlemail.com wrote:
 Dear list,

 I make use of cached objects extensively for time consuming computations and
 yesterday I happened to notice some very strange behavior in that respect:
 When I execute a given computation whose result I'd like to cache (tried
 both saving it as '.Rdata' and via package 'R.cache' which uses a own
 filetype '.Rcache'),

Just to clarify, it is just the filename extension that is custom;
it uses base::save() internally.  It is very unlikely that R.cache has
to do with your problem.

 my R session consumes about 200 MB of RAM, which is
 fine. Now, when I make use of the previously cached object (i.e. loading it,
 assigning it to a certain field of a Reference Class object), I noticed that
 RAM consumption of my R process jumps to about 250 MB!
 a
 Each new loading of cached/saved objects adds to that consumption (in total,
 I have about 5-8 objects that are processed this way), so at some point I
 easily get a RAM consumption of over 2 GB where I'm only at about 200 MB of
 consumption when I compute each object directly! Object sizes (checked with
 'object.size()') remain fairly constant. What's even stranger: after loading
 cached objects and removing them (either via 'rm()' or by assigning a
 'fresh' empty object to the respective Reference Class field, RAM
 consumption remains at this high level and never comes down again.

 I checked the behavior also in a small example which is a simplification of
 my use case and which you'll find below (checked both on Win XP and Win 7 32
 bit). I couldn't quite reproduce an immediate increase in RAM consumption,

I couldn't reproduce it either using sessionInfo():

R version 2.13.1 Patched (2011-08-29 r56823)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
loaded via a namespace (and not attached):
[1] tools_2.13.1

 but what I still find really strange is
 a) why do repeated 'load()' calls result in an increase in RAM consumption?
 b) why does the latter not go down again after the objects have been removed
 from '.GlobalEnv'?

Removed objects may still sit in memory - it is only when R's garbage
collector (GC) comes around and removes them that the memory usage
goes down.  You can force the garbage collector to run by calling
gc(), but normally it is automatically triggered whenever needed.

Note that the GC will only be able to clean up the memory of removed
objects IFF there are no other references to that object/piece of
memory.  When you use References classes (cf. setRefClass()) and
environments, you end up keeping references internally in objects
without being aware of it.  My guess is that your other code may have
such issues, whereas the code below does not.

There is also the concept of promises [see 'R Language Definition'
document], which *may* also be involved.

FYI, the Sysinternals Process Explorer
[http://technet.microsoft.com/en-us/sysinternals/bb896653] is a useful
tool for studying individual processes such as R.

My $.02

Henrik


 Did anyone of you experience a similar behavior? Or even better, does anyone
 know why this is happening and how it might be fixed (or be worked around)?
 ;-)

 I really need your help on this one as it's crucial for my thesis, thanks a
 lot for anyone replying!!

 Regards,
 Janko

 # EXAMPLE #

 setRefClass(A, fields=list(.PRIMARY=environment))
 setRefClass(Test, fields=list(a=A))

 obj.1 - lapply(1:5000, function(x){
    rnorm(x)
 })
 names(obj.1) - paste(sample, 1:5000, sep=.)
 obj.1 - as.environment(obj.1)

 test - new(Test, a=new(A, .PRIMARY=obj.1))
 test$a$.PRIMARY$sample.10

 #+

 object.size(test)
 object.size(test$a)
 object.size(obj.1)
 # RAM used by R session: 118 MB

 save(obj.1, file=C:/obj.1.Rdata)
 # Results in an object of ca. 94 MB
 save(test, file=C:/test.Rdata)
 # Results in an object of ca. 94 MB

 # START A NEW R SESSION #

 load(C:/test.Rdata)
 # RAM consumption still fine at 115 - 118 MB

 # But watch how it goes up as we repeatedly load objects
 for(x in 1:5){
    load(C:/test.Rdata)
 }
 for(x in 1:5){
    load(C:/obj.1.Rdata)
 }
 # Somehow there seems to be an upper limit, though

 # Removing the objects does not bring down RAM consumption
 rm(obj.1)
 rm(test)

 ##

 Sys.info()
                     sysname                      release
                   Windows                         XP
                     version                     nodename
 build 2600, Service Pack 3               ASHB-109C-02
                     machine                        login
                       x86                     wwa418
                        user
                    wwa418

 sessionInfo()
 R version 

Re: [R] Error in f(x, ...) : could not find function f2

2011-08-30 Thread Uwe Ligges



On 30.08.2011 14:31, . . wrote:

Hi all,

I am getting the erro showed in the subject. I was strange the this
becomes to happen after a computer restar. I think after the restart
another function f2 was in memory and it scape from me.

func- Vectorize(FUN=
   function(y, frac, rate, sad, samp=Poisson, trunc=0, ...){
f0- function(y,frac,n) {
f1- function(y,frac,n){
dpois(y,frac*n)
}
dcom- paste(d,deparse(substitute(sad)),sep=)
dots- c(as.name(n),list(...))
f2- call(dcom,dots)
f- function(n){
f1(y,frac,n)*f2(n)
}


. ., obviously f2 is a call rather than a function.

Uwe Ligges




myintegrate- function() {
r- 0
r1- 1
x1- 0
dx- 20
while(r1  10e-500) {
r1- integrate(f,x1,x1+dx)$value
r- r + r1
x1- x1 + dx
}
integrate(f,x1,Inf)$valu
}
myintegrate()
}
f0(y,frac,n)/(1-f0(trunc,frac,n))
},y)

func(10, 0.1, 0.1, exp)

Any idea?

Thanks in advance.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-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] ATSP to TSP reformulation

2011-08-30 Thread Ian Deters
It worked fabulously.  Thank you so much for help and time.

--
View this message in context: 
http://r.789695.n4.nabble.com/ATSP-to-TSP-reformulation-tp3777105p3779476.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] column names with rbind loop

2011-08-30 Thread Weidong Gu
How about to add a conditional statement to get the header from 1st file

for(i in all.files) {
if (i==all.files[1]) new.data - read.table(i,header=TRUE) else {
new.data - rbind(new.data, read.table(i))}}


Weidong Gu


On Tue, Aug 30, 2011 at 1:42 PM, Vining, Kelly
kelly.vin...@oregonstate.edu wrote:
 Hello R  users.

 This is a fairly basic question:

 I am concatenating data from sets of files in a directory using a loop. The 
 column names in all files are exactly the same. My understanding is that 
 rbind takes column names from the first file it reads. However, my output is 
 showing that the column names are treated as a first data row, not treated as 
 headers.

 I compile my file names like this:

 all.files - list.files()
 all.files
  [1] 1.rpkm  10.rpkm 11.rpkm 12.rpkm 13.rpkm 14.rpkm
  [7] 15.rpkm 16.rpkm 17.rpkm 18.rpkm 19.rpkm 2.rpkm
 [13] 3.rpkm  4.rpkm  5.rpkm  6.rpkm  7.rpkm  8.rpkm
 [19] 9.rpkm

 Then loop through them like this:
 new.data - NULL
 for(i in all.files) {
 + in.data - read.table(i)
 + new.data - rbind(new.data, in.data)}
 head(new.data)
         V1               V2        V3     V4     V5    V6     V7
 1     seq_id           source      type  start    end score strand
 2 scaffold_1 Ptrichocarpav2_0 gene_body  12639  13384     .      +
 3 scaffold_1 Ptrichocarpav2_0 gene_body  22190  22516     .      +
 4 scaffold_1 Ptrichocarpav2_0 gene_body  74076 75893     .      +
 5 scaffold_1 Ptrichocarpav2_0 gene_body  80207  81289     .      -
 6 scaffold_1 Ptrichocarpav2_0 gene_body 105236 107712     .      +


 As you can see, R is putting a V1, V2... header row here because I didn't 
 say header=TRUE in my read.table command. But if I do this within the loop, 
 I get an error. If I try to delete the V1, V2 row after the fact by

 new.data - new.data[-1,]

 R deletes my real header row.

 How can I get the header that I want?

 Thanks for any help,
 --Kelly V.

 __
 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] Multiple Traveling Salesperson Problem

2011-08-30 Thread Michael Hahsler

Hi Ian,

There is currently no support for the mTSP in tsp.
The paper

Tolga Bektas, The multiple traveling salesman problem: an overview of 
formulations and solution procedures, Omega, 34(3), June 2006, Pages 209-219


describes some methods to reformulate a mTSP as a regular TSP. However, 
I had no time to look at those...


-Michael

--
  Dr. Michael Hahsler, Visiting Assistant Professor
  Department of Computer Science and Engineering
  Lyle School of Engineering
  Southern Methodist University, Dallas, Texas

  (214) 768-8878 * mhahs...@lyle.smu.edu * http://lyle.smu.edu/~mhahsler

__
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] ROC plot for KNN

2011-08-30 Thread Qian Liu
Hi I need some help with ploting the ROC for K-nearest neighbors. Since KNN
is a non-parametric classification methods, the predicted value will be
either 0 or 1.
It will not be able to test for different cutoff to plot ROC. What is the
package or functions I should use to plot ROC for KNN?

Thanks.
Qian

[[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] splitting into multiple dataframes and then create a loop to work

2011-08-30 Thread Nilaya Sharma
Thank you for the help. My focus was to split data frame for a different
function, not lm. I could provide detail of that lengthy function instead I
provided the lm function.

The comment were very helpful.

Thanks;

NIL

On Mon, Aug 29, 2011 at 3:37 PM, Dimitris Rizopoulos 
d.rizopou...@erasmusmc.nl wrote:

 well, if a pooled estimate of the residual standard error is not desirable,
 then you just need to set argument 'pool' of lmList() to FALSE, e.g.,

 mlis - lmList(yvar ~ .  - clvar | clvar, data = df, pool = FALSE)
 summary(mlis)


 Best,
 Dimitris



 On 8/29/2011 9:20 PM, Dennis Murphy wrote:

 Hi:

 Dimitris' solution is appropriate, but it needs to be mentioned that
 the approach I offered earlier in this thread differs from the
 lmList() approach. lmList() uses a pooled measure of error MSE (which
 you can see at the bottom of the output from summary(mlis) ), whereas
 the plyr approach subdivides the data into distinct sub-data frames
 and analyzes them as separate entities. As a result, the residual MSEs
 will differ between the two approaches, which in turn affects the
 significance tests on the model coefficients. You need to decide which
 approach is better for your purposes.

 Cheers,
 Dennis

 On Mon, Aug 29, 2011 at 12:02 PM, Dimitris Rizopoulos
 d.rizopou...@erasmusmc.nl  wrote:

 You can do this using function lmList() from package nlme, without having
 to
 split the data frames, e.g.,

 library(nlme)

 mlis- lmList(yvar ~ .  - clvar | clvar, data = df)
 mlis
 summary(mlis)


 I hope it helps.

 Best,
 Dimitris


 On 8/29/2011 5:37 PM, Nilaya Sharma wrote:


 Dear All

 Sorry for this simple question, I could not solve it by spending days.

 My data looks like this:

 # data
 set.seed(1234)
 clvar- c( rep(1, 10), rep(2, 10), rep(3, 10), rep(4, 10)) # I have 100
 level for this factor var;
 yvar-  rnorm(40, 10,6);
 var1- rnorm(40, 10,4); var2- rnorm(40, 10,4); var3- rnorm(40, 5, 2);
 var4- rnorm(40, 10, 3); var5- rnorm(40, 15, 8) # just example
 df- data.frame(clvar, yvar, var1, var2, var3, var4, var5)

 # manual splitting
 df1- subset(df, clvar == 1)
 df2- subset(df, clvar == 2)
 df3- subset(df, clvar == 3)
 df4- subset(df, clvar == 4)
 df5- subset(df, clvar == 5)

 # i tried to mechanize it
 *

 for(i in 1:5) {

   df[i]- subset(df, clvar == i)

 }

 I know it should not work as df[i] is single variable, do it did. But I
 could not find away to output multiple dataframes from this loop. My
 limited
 R knowledge, did not help at all !

 *

 # working on each of variable, just trying simple function
  a- 3:8
 out1- lapply(1:5, function(ind){
lm(df1$yvar ~ df1[, a[ind]])
  })
 p1- lapply(out1, function(m)summary(m)$**coefficients[,4][2])
 p1- do.call(rbind, p1)


 My ultimate objective is to apply this function to all the dataframes
 created (i.e. df1, df2, df3, df4, df5) and create five corresponding
 p-value
 vectors (p1, p2, p3, p4, p5). Then output would be a matrix of clvar and
 correponding p values
 clvar   var1   var2  var3  var4   var5
 1
 2
 3
 4

 Please help me !

 Thanks

 NIL

[[alternative HTML version deleted]]

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/**posting-guide.htmlhttp://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 --
 Dimitris Rizopoulos
 Assistant Professor
 Department of Biostatistics
 Erasmus University Medical Center

 Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
 Tel: +31/(0)10/7043478
 Fax: +31/(0)10/7043014
 Web: 
 http://www.erasmusmc.nl/**biostatistiek/http://www.erasmusmc.nl/biostatistiek/

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



 --
 Dimitris Rizopoulos
 Assistant Professor
 Department of Biostatistics
 Erasmus University Medical Center

 Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
 Tel: +31/(0)10/7043478
 Fax: +31/(0)10/7043014
 Web: 
 http://www.erasmusmc.nl/**biostatistiek/http://www.erasmusmc.nl/biostatistiek/


[[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] column names with rbind loop

2011-08-30 Thread Vining, Kelly
Thanks much for your help! This almost works. However, now I am getting the 
following error:

 for(i in all.files) {
+ if (i==all.files[1]) new.data - read.table(i,header=TRUE) else {
+ new.data - rbind(new.data, read.table(i))}}
Error in match.names(clabs, names(xi)) : 
  names do not match previous names

I am wondering if this is because R adds row numbers as a numerical column to 
the table of the first file it reads?



From: Weidong Gu [anopheles...@gmail.com]
Sent: Tuesday, August 30, 2011 12:00 PM
To: Vining, Kelly
Cc: r-help@r-project.org
Subject: Re: [R] column names with rbind loop

How about to add a conditional statement to get the header from 1st file

for(i in all.files) {
if (i==all.files[1]) new.data - read.table(i,header=TRUE) else {
new.data - rbind(new.data, read.table(i))}}


Weidong Gu


On Tue, Aug 30, 2011 at 1:42 PM, Vining, Kelly
kelly.vin...@oregonstate.edu wrote:
 Hello R  users.

 This is a fairly basic question:

 I am concatenating data from sets of files in a directory using a loop. The 
 column names in all files are exactly the same. My understanding is that 
 rbind takes column names from the first file it reads. However, my output is 
 showing that the column names are treated as a first data row, not treated as 
 headers.

 I compile my file names like this:

 all.files - list.files()
 all.files
  [1] 1.rpkm  10.rpkm 11.rpkm 12.rpkm 13.rpkm 14.rpkm
  [7] 15.rpkm 16.rpkm 17.rpkm 18.rpkm 19.rpkm 2.rpkm
 [13] 3.rpkm  4.rpkm  5.rpkm  6.rpkm  7.rpkm  8.rpkm
 [19] 9.rpkm

 Then loop through them like this:
 new.data - NULL
 for(i in all.files) {
 + in.data - read.table(i)
 + new.data - rbind(new.data, in.data)}
 head(new.data)
 V1   V2V3 V4 V5V6 V7
 1 seq_id   source  type  startend score strand
 2 scaffold_1 Ptrichocarpav2_0 gene_body  12639  13384 .  +
 3 scaffold_1 Ptrichocarpav2_0 gene_body  22190  22516 .  +
 4 scaffold_1 Ptrichocarpav2_0 gene_body  74076 75893 .  +
 5 scaffold_1 Ptrichocarpav2_0 gene_body  80207  81289 .  -
 6 scaffold_1 Ptrichocarpav2_0 gene_body 105236 107712 .  +


 As you can see, R is putting a V1, V2... header row here because I didn't 
 say header=TRUE in my read.table command. But if I do this within the loop, 
 I get an error. If I try to delete the V1, V2 row after the fact by

 new.data - new.data[-1,]

 R deletes my real header row.

 How can I get the header that I want?

 Thanks for any help,
 --Kelly V.

 __
 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] locate the needed columns

2011-08-30 Thread Weidong Gu
If the pattern is characterized by capital letters as your sample
suggests. The following code may help

df-list()
names(d) = c(A.x, B.x, C.x, A.y, B.y, C.y)
group.v-matrix(NA,nrow=3,ncol=2) ### you may need to modify nrow and ncol
for (i in 1:3) {
group.v[i,]-names(d)[grep(LETTERS[i],names(d))]
df[i]-d[,names(d)%in% group.v[i]]
}


Weidong Gu

On Tue, Aug 30, 2011 at 2:31 PM, Hui Du hui...@dataventures.com wrote:

 Hi All,

                I have a data frame, whose colnames like A.x, B.x, C.x, A.y, 
 B.y, C.y. There could be many columns like this pattern. I want to compare 
 data in columns A.x with A.y, B.x with B.y and C.x with C.y etc.
 Suppose my data frame is d,
 names(d) = c(A.x, B.x, C.x, A.y, B.y, C.y);

 If I want to
 D1 = data.frame(d$A.x, d$A.y);
 D2 = data.frame(d$B.x, d$B.y); etc. or do other operation for each pair,


 What is elegant way to do it rather than use a loop?

 Thanks.

 HXD


        [[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] gradient function in OPTIMX

2011-08-30 Thread Rubén Roa
Hi,

In my package CatDyn, which uses optimx, I included the gradients of 20 version 
of the model involved.
I estimate model parameters with numerical gradients, and at the final 
estimates I calculate the analytical gradients.
In the simplest version of the model the analytical gradients computed post hoc 
are almost identical to the numerical gradients. This shows that the analytical 
gradients (whose formulas were obtained by the CAS Maxima) are correct, at 
least for those simple versions of my model. However, if I try to pass the 
analytical gradients to optimx in a new optimization, I invariably get the 
error message that you got: Gradient function might be wrong - check it!
This happens regardless of the method used (BFGS, spg, Rcgmin).
Same as you, when I try to pass the gradients to optim, instead of optimx, the 
gradients are accepted and computed correctly, but then I cann't use the very 
nice other features of optimx.
I wanted to report this to Ravi and Prof. Nash but I haven't got the time for a 
full report with several examples and variations.
So now that you report it, here I am, seconding you in calling the attention to 
this apparent problem in optimx.

Rubén H. Roa-Ureta, Ph. D.
AZTI Tecnalia, Txatxarramendi Ugartea z/g,
Sukarrieta, Bizkaia, SPAIN

-Original Message-
From: r-help-boun...@r-project.org on behalf of Kathie
Sent: Mon 8/29/2011 11:10 AM
To: r-help@r-project.org
Subject: [R] gradient function in OPTIMX
 
Dear R users

When I use OPTIM with BFGS, I've got a significant result without an error
message.  However, when I use OPTIMX with BFGS( or spg), I've got the
following an error message.



  optimx(par=theta0, fn=obj.fy, gr=gr.fy, method=BFGS,
 control=list(maxit=1))

Error: Gradient function might be wrong - check it! 



I checked and checked my gradient function line by line. I could not find
anything wrong.

Is it a bug or something?  I prefer OPTIMX, so I'd like to know why.

Thanks a lot in advance

Regards,

Kathryn Lord 

--
View this message in context: 
http://r.789695.n4.nabble.com/gradient-function-in-OPTIMX-tp3775791p3775791.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.


[[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] Fwd: help with by command

2011-08-30 Thread amalka
Thanks very much for the help.

I ended up getting it to work with one small change:

by(foo, foo$V2, function(foo) mean(foo$trust, na.rm=T)) 

thanks again,
Ari

--
View this message in context: 
http://r.789695.n4.nabble.com/help-with-by-command-tp3766285p3779622.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] Generating a sequence of diagonal matrices

2011-08-30 Thread meddee
I am trying to generate a sequence of diagonal matrices.

In the scalar case I would use something like, seq(0,100,by=1).

How do I generalise the above for , say a 2 dimensional diagonal matrix. In
other words how do I produce the series of diagonal matrices {
diag(0,2),diag(1,2), diag(2,2),...,diag(100,2)}?

Thanks
Meddee

--
View this message in context: 
http://r.789695.n4.nabble.com/Generating-a-sequence-of-diagonal-matrices-tp3779623p3779623.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] column names with rbind loop

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 3:46 PM, Vining, Kelly wrote:

Thanks much for your help! This almost works. However, now I am  
getting the following error:



for(i in all.files) {

+ if (i==all.files[1]) new.data - read.table(i,header=TRUE) else {
+ new.data - rbind(new.data, read.table(i))}}
Error in match.names(clabs, names(xi)) :
 names do not match previous names


You need to decide if you are going to use the V-names or the original  
names because rbind requires that the names for its two arguments  
match. Perhaps you want to read the names in separately with  
readLines? Also look at the skip argument to read.tables.




I am wondering if this is because R adds row numbers as a numerical  
column to the table of the first file it reads?


It does so by default. It needs to have some sort of character vector  
to use, so if there is none, it makes up names. I don't understand why  
you didn't use, ... header =TRUE, for both read operations.


--
David.





From: Weidong Gu [anopheles...@gmail.com]
Sent: Tuesday, August 30, 2011 12:00 PM
To: Vining, Kelly
Cc: r-help@r-project.org
Subject: Re: [R] column names with rbind loop

How about to add a conditional statement to get the header from 1st  
file


for(i in all.files) {
if (i==all.files[1]) new.data - read.table(i,header=TRUE) else {
new.data - rbind(new.data, read.table(i))}}


Weidong Gu


On Tue, Aug 30, 2011 at 1:42 PM, Vining, Kelly
kelly.vin...@oregonstate.edu wrote:

Hello R  users.

This is a fairly basic question:

I am concatenating data from sets of files in a directory using a  
loop. The column names in all files are exactly the same. My  
understanding is that rbind takes column names from the first file  
it reads. However, my output is showing that the column names are  
treated as a first data row, not treated as headers.


I compile my file names like this:


all.files - list.files()
all.files

[1] 1.rpkm  10.rpkm 11.rpkm 12.rpkm 13.rpkm 14.rpkm
[7] 15.rpkm 16.rpkm 17.rpkm 18.rpkm 19.rpkm 2.rpkm
[13] 3.rpkm  4.rpkm  5.rpkm  6.rpkm  7.rpkm  8.rpkm
[19] 9.rpkm

Then loop through them like this:

new.data - NULL
for(i in all.files) {

+ in.data - read.table(i)
+ new.data - rbind(new.data, in.data)}

head(new.data)

   V1   V2V3 V4 V5V6 V7
1 seq_id   source  type  startend score strand
2 scaffold_1 Ptrichocarpav2_0 gene_body  12639  13384 .  +
3 scaffold_1 Ptrichocarpav2_0 gene_body  22190  22516 .  +
4 scaffold_1 Ptrichocarpav2_0 gene_body  74076 75893 .  +
5 scaffold_1 Ptrichocarpav2_0 gene_body  80207  81289 .  -
6 scaffold_1 Ptrichocarpav2_0 gene_body 105236 107712 .  +


As you can see, R is putting a V1, V2... header row here because  
I didn't say header=TRUE in my read.table command. But if I do  
this within the loop, I get an error. If I try to delete the V1, V2  
row after the fact by


new.data - new.data[-1,]

R deletes my real header row.

How can I get the header that I want?

Thanks for any help,
--Kelly V.

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


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] RPostgreSQL Loading Issues

2011-08-30 Thread Rich Shepard

On Tue, 30 Aug 2011, Joe Conway wrote:


Just a guess, but possibly because libpq.so (the postgres client
library) is not being found.


Joe,

  My initial thought, too. But, that's not it.


1) Do you have libpq.so installed on your system?
2) If so, where?
3) If it is not in a standard system location (e.g. /usr/lib), try
adding an entry either to /etc/ld.so.conf or a file with the appropriate
entry in /etc/ld.so.conf.d/ and then run ldconfig


/usr/local/pgsql/lib/libpq.so
/usr/local/pgsql/lib/libpq.so.5
/usr/local/pgsql/lib/libpq.so.5.3
/usr/lib/libpq.so
/usr/lib/libpq.so.5

  The softlinks in /usr/lib/ are to /usr/local/pgsql/lib/libpq.so.5.3.

  Since postgres-9.0.4 runs quite well here there must be some other factor
in play.

Thanks,

Rich

__
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] Generating a sequence of diagonal matrices

2011-08-30 Thread Joshua Wiley
Hi Meddee,

Try this:

dmat - lapply(1:100, function(d) diag(d, 2))

That will give you a list of all 100 matrices.

Cheers,

Josh

On Tue, Aug 30, 2011 at 1:00 PM, meddee meddee1...@gmail.com wrote:
 I am trying to generate a sequence of diagonal matrices.

 In the scalar case I would use something like, seq(0,100,by=1).

 How do I generalise the above for , say a 2 dimensional diagonal matrix. In
 other words how do I produce the series of diagonal matrices {
 diag(0,2),diag(1,2), diag(2,2),...,diag(100,2)}?

 Thanks
 Meddee

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Generating-a-sequence-of-diagonal-matrices-tp3779623p3779623.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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] having trouble extracting week from chron object

2011-08-30 Thread David Winsemius

You did read jannis' reply didn't you?

--  
David.

On Aug 30, 2011, at 2:34 PM, Christopher W Ryan wrote:


Here it is with the output:


library(chron)
dts - dates(c(02/27/92, 02/27/92, 01/14/92,02/28/92,  
02/01/92))

dts

[1] 02/27/92 02/27/92 01/14/92 02/28/92 02/01/92

dts.chron - as.chron(dts)
dts.chron

[1] 02/27/92 02/27/92 01/14/92 02/28/92 02/01/92

class(dts.chron)

[1] dates times

# all of these component extractions work:
months(dts.chron)

[1] Feb Feb Jan Feb Feb
12 Levels: Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  ...  
 Dec

weekdays(dts.chron)

[1] Thu Thu Tue Fri Sat
Levels: Sun  Mon  Tue  Wed  Thu  Fri  Sat

years(dts.chron)

[1] 1992 1992 1992 1992 1992
Levels: 1992

quarters(dts.chron)

[1] 1Q 1Q 1Q 1Q 1Q
Levels: 1Q  2Q  3Q  4Q

# but weeks() doesn't seem to work
weeks(dts.chron)

Error: could not find function weeks

?weeks

No documentation for 'weeks' in specified packages and libraries:
you could try '??weeks'

weeks

Error: object 'weeks' not found

week

Error: object 'week' not found


sessionInfo()

R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

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

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

other attached packages:
[1] chron_2.3-42

Thanks.

--Chris Ryan


On Tue, Aug 30, 2011 at 1:54 PM, David Winsemius dwinsem...@comcast.net 
 wrote:


On Aug 30, 2011, at 1:36 PM, Christopher W Ryan wrote:


Running R 2.13.1 on Windows XP.
I would like to get week of the year (1-52) for each date.

library(chron)
dts - dates(c(02/27/92, 02/27/92, 01/14/92,02/28/92,  
02/01/92))

dts
dts.chron - as.chron(dts)
dts.chron
class(dts.chron)
# all of these component extractions work:
months(dts.chron)
weekdays(dts.chron)
years(dts.chron)
quarters(dts.chron)
# but weeks() doesn't seem to work


It doesn't work for me either but since I also have the package  
lubridate
loaded, and ?weeks brings up a lubridate help page, I don't feel I  
have any

right to complain. I get an error message what did you get?:

Error in Ops.dates(pieces$week, 7) : * not defined for chron objects

If I were posting I would also have had the good sense to include  
the output

of sessionInfo().


weeks(dts.chron)


Try type just:

 weeks  # I get a lubridate function.



?chron tells me:



Bur what does ?weeks tell you?


. . . The functions days(), months(), quarters(),
years(), weeks(), weekdays(), hours(), minutes(), and seconds() take
any chron object as input and extract the corresponding time  
interval

. . . .

Any advice?

Thanks.

Chris Ryan
SUNY Upstate Medical University Clinical Campus at Binghamton
Binghamton, NY

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


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] having trouble extracting week from chron object

2011-08-30 Thread Gabor Grothendieck
On Tue, Aug 30, 2011 at 1:36 PM, Christopher W Ryan
cr...@binghamton.edu wrote:
 Running R 2.13.1 on Windows XP.
 I would like to get week of the year (1-52) for each date.

 library(chron)
 dts - dates(c(02/27/92, 02/27/92, 01/14/92,02/28/92, 02/01/92))

Try this:

as.numeric(cut(dts, weeks))


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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.


Re: [R] RPostgreSQL Loading Issues

2011-08-30 Thread Joe Conway
On 08/30/2011 10:53 AM, Rich Shepard wrote:
 Error in dyn.load(file, DLLpath = DLLpath, ...) :
   unable to load shared object
 '/home/rshepard/R/i486-slackware-linux-gnu-library/2.13/RPostgreSQL/libs/RPostgreSQL.so':
 
   libR.so: cannot open shared object file: No such file or directory
 Error: package/namespace load failed for 'RPostgreSQL'
 
   The shared library, of course, is present:
 
 [rshepard@salmo
 ~/R/i486-slackware-linux-gnu-library/2.13/RPostgreSQL/libs]$ ll
 -rwxr-xr-x 1 rshepard users 44385 2011-08-03 20:13 RPostgreSQL.so*
 
   Can someone explain to me what's going on and how I fix it?

Just a guess, but possibly because libpq.so (the postgres client
library) is not being found.

1) Do you have libpq.so installed on your system?
2) If so, where?
3) If it is not in a standard system location (e.g. /usr/lib), try
adding an entry either to /etc/ld.so.conf or a file with the appropriate
entry in /etc/ld.so.conf.d/ and then run ldconfig

HTH,

Joe


-- 
Joe Conway
credativ LLC: http://www.credativ.us
Linux, PostgreSQL, and general Open Source
Training, Service, Consulting,  24x7 Support

__
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] having trouble extracting week from chron object

2011-08-30 Thread Gabor Grothendieck
On Tue, Aug 30, 2011 at 4:43 PM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 On Tue, Aug 30, 2011 at 1:36 PM, Christopher W Ryan
 cr...@binghamton.edu wrote:
 Running R 2.13.1 on Windows XP.
 I would like to get week of the year (1-52) for each date.

 library(chron)
 dts - dates(c(02/27/92, 02/27/92, 01/14/92,02/28/92, 02/01/92))

 Try this:

 as.numeric(cut(dts, weeks))

although that won't label the weeks from the beginning of the year but
rather the earliest date will be labelled week 1 so you need to add a
date in the first of the year if you want that.  Alternately  try
this: as.numeric(format(as.Date(dts), %w)) or use %W.  See ?strptime
for details.


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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.


[R] Fwd: ARMA show different result between eview and R

2011-08-30 Thread John C Frain
-- Forwarded message --
From: John C Frain fra...@gmail.com
Date: 30 August 2011 21:52
Subject: Re: [R] ARMA show different result between eview and R
To: Young Gyu Park ygpa...@gmail.com


If you check your manuals you will find that R uses full maximum
likelihood while Eviews uses an alternative non-linear method.  Many
programs use different versions of information criteria but these are
monotone transformations (ie they all have an extreme value with the
same model. Again you need to check your manuals.

Best Regards

John

On 30 August 2011 08:21, Young Gyu Park ygpa...@gmail.com wrote:
 When I do ARMA(2,2) using one lag of LCPIH data



 This is eview result


 *Dependent Variable: DLCPIH
 **Method: Least Squares
 **Date: 08/12/11   Time: 12:44
 **Sample (adjusted): 1970Q2 2010Q2
 **Included observations: 161 after adjustments
 **Convergence achieved after 14 iterations
 **MA Backcast: 1969Q4 1970Q1
 **
 **Variable    Coefficient    Std. Error    t-Statistic    Prob.
 **
 **C    0.003361    0.001814    1.853352    0.0657
 **DLCPIH(-1)    -0.100150    0.053160    -1.883917    0.0614
 **DLCPIH(-2)    0.870456    0.052466    16.59075    0.
 **MA(1)    0.532252    0.100110    5.316678    0.
 **MA(2)    -0.379383    0.099535    -3.811566    0.0002
 **
 **R-squared    0.512067        Mean dependent var        0.014816
 **Adjusted R-squared    0.499556        S.D. dependent var        0.016274
 **S.E. of regression    0.011513        Akaike info criterion
 -6.060182
 **Sum squared resid    0.020676        Schwarz criterion        -5.964486
 **Log likelihood    492.8446        Hannan-Quinn criter.        -6.021326
 **F-statistic    40.92897        Durbin-Watson stat        2.012062
 **Prob(F-statistic)    0.00
 **
 **Inverted MA Roots          .40             -.94 *



 This is R result



 * dlcpihTsLen - length(ausT2Ts[,4])
 ** dlcpihArma22Fit - arima(ausT2Ts[,4], order=c(2,1,2),
 xreg=1:dlcpihTsLen)
 ** dlcpiArma22hFit - arima(ausT2Ts[,4], order=c(2,1,2))
 ** dlcpihArma22Fit
 *
 *Call:
 **arima(x = ausT2Ts[, 4], order = c(2, 1, 2), xreg = 1:dlcpihTsLen)
 *
 *Coefficients:
 **          ar1     ar2     ma1      ma2  1:dlcpihTsLen
 **      -0.1083  0.8673  0.5263  -0.3716         0.0146
 **s.e.   0.0493  0.0484  0.0894   0.0852         0.0041
 *
 *sigma^2 estimated as 0.0001282:  log likelihood = 498.38,  aic = -984.76*

 *
 *

 *
 *

 I wonder why the coefficient values are little bit different between them.

 *
 *

 Another thing I wonder is why the AIC value is so significantly different
 each other*.*

 *
 *

 Please help me, if anyone who have experience both of eview and R is in R
 community.


 Thank you.

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




--
John C Frain
Economics Department
Trinity College Dublin
Dublin 2
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:fra...@tcd.ie
mailto:fra...@gmail.com



-- 
John C Frain
Economics Department
Trinity College Dublin
Dublin 2
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:fra...@tcd.ie
mailto:fra...@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.


[R] Descriptive Stats from Data Frame

2011-08-30 Thread Rich Shepard

  I don't find how to do what I need to do in Dalgaard or 'R Cookbook', so
I'm asking here.

  I have a data frame with water chemistry data and I want to start
exploring these data. There are three factors (site, date, chemical)
associated with each measurement. The data frame looks like this:


summary(chemdata)

 site_id.sample_date.param.quant
 BC-0.5|1996-04-19|Arsenic|0.01  :1
 BC-0.5|1996-04-19|Calcium|76.56 :1
 BC-0.5|1996-04-19|Chloride|12   :1
 BC-0.5|1996-04-19|Magnesium|43.23   :1
 BC-0.5|1996-04-19|Sulfate|175   :1
 BC-0.5|1996-04-19|Total Dissolved Solids|460:1
 (Other) :14880

  I want first to calculate (and plot) descriptive stats by chemical,
ignoring site and date and telling R to ignore missing data. (Incorporating
those factors will occur later.) What I have not been able to figure out is
how to specify the command to, for example, calculate mean and sd for
Arsenic. My floundering and thrashing includes attempts like these:


mean(chemdata.param=Arsenic)

Error in is.numeric(x) : 'x' is missing

mean(chemdata.quant, param=Arsenic)

Error in mean(chemdata.quant, param = Arsenic) :
  object 'chemdata.quant' not found

mean(chemdata$quant, param=Arsenic)

[1] NA
Warning message:
In mean.default(chemdata$quant, param = Arsenic) :
  argument is not numeric or logical: returning NA

  As a newcomer to R I've done a lot of reading, yet all the examples use
nicely structured data to illustrate the point being made. I need to work
with my data and learn how to specify columns and write correct commands for
the analyses I need. Please point me in the right direction.

Rich

__
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] Descriptive Stats from Data Frame

2011-08-30 Thread Tal Galili
Hi Rich,

It is a bit hard to read the summary you are using.  Consider please
pasting the output of:
ls.str(chemdata)

Regarding your question, please start and see if this work (I'm not sure,
since it seems you have made some changes to the summary output, and I am
only guessing how things look):
mean(chemdata$quant[chemdata$param ==Arsenic])
sd(chemdata$quant[chemdata$param ==Arsenic])


Cheers,
Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Wed, Aug 31, 2011 at 12:00 AM, Rich Shepard rshep...@appl-ecosys.comwrote:

 mean(chemdata.param=Arsenic)

[[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] Descriptive Stats from Data Frame

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 5:00 PM, Rich Shepard wrote:

 I don't find how to do what I need to do in Dalgaard or 'R  
Cookbook', so

I'm asking here.

 I have a data frame with water chemistry data and I want to start
exploring these data. There are three factors (site, date, chemical)
associated with each measurement. The data frame looks like this:


summary(chemdata)

site_id.sample_date.param.quant


It appears that your original file was delimited by | and your used  
something else, perhaps the default white-space setting? I think you  
need to go back and do your input operations again with sep=|


(Or you could provide str() on the data.frame rather than making us  
guess.)

--
David


BC-0.5|1996-04-19|Arsenic|0.01  :1
BC-0.5|1996-04-19|Calcium|76.56 :1
BC-0.5|1996-04-19|Chloride|12   :1
BC-0.5|1996-04-19|Magnesium|43.23   :1
BC-0.5|1996-04-19|Sulfate|175   :1
BC-0.5|1996-04-19|Total Dissolved Solids|460:1
(Other) :14880

 I want first to calculate (and plot) descriptive stats by chemical,
ignoring site and date and telling R to ignore missing data.  
(Incorporating
those factors will occur later.) What I have not been able to figure  
out is

how to specify the command to, for example, calculate mean and sd for
Arsenic. My floundering and thrashing includes attempts like these:


mean(chemdata.param=Arsenic)

Error in is.numeric(x) : 'x' is missing

mean(chemdata.quant, param=Arsenic)

Error in mean(chemdata.quant, param = Arsenic) :
 object 'chemdata.quant' not found

mean(chemdata$quant, param=Arsenic)

[1] NA
Warning message:
In mean.default(chemdata$quant, param = Arsenic) :
 argument is not numeric or logical: returning NA

 As a newcomer to R I've done a lot of reading, yet all the examples  
use
nicely structured data to illustrate the point being made. I need to  
work
with my data and learn how to specify columns and write correct  
commands for

the analyses I need. Please point me in the right direction.

Rich

__
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] Descriptive Stats from Data Frame

2011-08-30 Thread Rich Shepard

On Wed, 31 Aug 2011, Tal Galili wrote:


It is a bit hard to read the summary you are using.  Consider please
pasting the output of:
ls.str(chemdata)


Tal,

  Yes, summary() is inappropriate. I do want str() instead. And what that
shows is:


str(chemdata)

'data.frame':   14886 obs. of  1 variable:
 $ site_id.sample_date.param.quant: Factor w/ 14886 levels
BC-0.5|1996-04-19|Arsenic|0.01,..: 11579 14219 13298 11982 11909 13371
13082 111 12 23 ...


Regarding your question, please start and see if this work (I'm not sure,
since it seems you have made some changes to the summary output, and I am
only guessing how things look):



mean(chemdata$quant[chemdata$param  ==Arsenic])



mean(chemdata$quant[chemdata$param  ==Arsenic])

Error: unexpected '==' in mean(chemdata$quant[chemdata$param  ==

mean(chemdata$quant[chemdata$param ==Arsenic])

[1] NA
Warning message:
In mean.default(chemdata$quant[chemdata$param == Arsenic]) :
  argument is not numeric or logical: returning NA

  I find it easy following the syntax in the half-dozen or more books I've
read, but quite difficult to apply what I read to my own real-world data.
:-)

Thanks,

Rich

__
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] Descriptive Stats from Data Frame

2011-08-30 Thread Rich Shepard

On Tue, 30 Aug 2011, David Winsemius wrote:

It appears that your original file was delimited by | and your used 
something else, perhaps the default white-space setting?


David,

  Yes, the csv file separator is the pipe.


I think you need to go back and do your input operations again with
sep=|

(Or you could provide str() on the data.frame rather than making us guess.)



str(chemdata)

'data.frame':   14886 obs. of  1 variable:
 $ site_id.sample_date.param.quant: Factor w/ 14886 levels
BC-0.5|1996-04-19|Arsenic|0.01,..: 11579 14219 13298 11982 11909 13371
13082 111 12 23 ...

Thanks,

Rich

__
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] Descriptive Stats from Data Frame

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 5:30 PM, Rich Shepard wrote:


On Tue, 30 Aug 2011, David Winsemius wrote:

It appears that your original file was delimited by | and your  
used something else, perhaps the default white-space setting?


David,

 Yes, the csv file separator is the pipe.


It is _not_ a csv file. You need to use read.table with sep = |.




I think you need to go back and do your input operations again with
sep=|

(Or you could provide str() on the data.frame rather than making us  
guess.)



str(chemdata)

'data.frame':   14886 obs. of  1 variable:
$ site_id.sample_date.param.quant: Factor w/ 14886 levels
BC-0.5|1996-04-19|Arsenic|0.01,..: 11579 14219 13298 11982 11909  
13371

13082 111 12 23 ...

Thanks,

Rich

__
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] Descriptive Stats from Data Frame

2011-08-30 Thread Rich Shepard

On Tue, 30 Aug 2011, David Winsemius wrote:


I think you need to go back and do your input operations again with
sep=|


David,

  Yes, that's better. I did not know of the sep option. The new results:


str(chemdata)

'data.frame':   14886 obs. of  4 variables:
 $ site_id: Factor w/ 148 levels BC-0.5,BC-1,..: 104 145 126 115 114
128 124 2 3 3 ...
 $ sample_date: Factor w/ 1012 levels 1980-03-01,1980-05-01,..: 432 410
423 405 398 408 401 360 366 407 ...
 $ param  : Factor w/ 8 levels Arsenic,Calcium,..: 1 1 1 1 1 1 1 1 1
1 ...
 $ quant  : num  0.06 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 ...

  Now I can work on the commands I need.

Many thanks,

Rich

__
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] Descriptive Stats from Data Frame

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 5:38 PM, Rich Shepard wrote:


On Tue, 30 Aug 2011, David Winsemius wrote:


I think you need to go back and do your input operations again with
sep=|


David,

 Yes, that's better. I did not know of the sep option. The new  
results:



str(chemdata)

'data.frame':   14886 obs. of  4 variables:
$ site_id: Factor w/ 148 levels BC-0.5,BC-1,..: 104 145 126  
115 114

128 124 2 3 3 ...
$ sample_date: Factor w/ 1012 levels 1980-03-01,1980-05-01,..:  
432 410

423 405 398 408 401 360 366 407 ...
$ param  : Factor w/ 8 levels Arsenic,Calcium,..: 1 1 1 1 1  
1 1 1 1

1 ...
$ quant  : num  0.06 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01  
0.01 ...


 Now I can work on the commands I need.


That does look more workable. You might consider changing the dates  
with:


chemadata$samp_date - as.Date(as.character(chemdata$sample_date) )




Many thanks,

Rich

__
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] putting in special characters in print statements

2011-08-30 Thread Erin Hodgess
Dear R People:

Here is a question which probably has a very simple answer.  I want to
print \end{verbatim} in the output of a sink file.  If I put in

\end{verbatim}
I get an unrecognized escape sequence.  If I put in \\end{verbatim},
it runs fine, but the output is \\end{verbatim}

How do I get just one bracket, please?

Thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@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.


  1   2   >