Re: [R] Unexpected returned value from a function

2008-09-16 Thread p

Quoting "Hutchinson,David [PYR]" <[EMAIL PROTECTED]>:


I wrote a simple function to change values of a matrix or vector to NA
based on the element value being - or -99. I don't understand
why the function returns a unit vector (NA) instead of setting all
values in the vector which have - or -99 to NA. When I apply the
function in line, it appears to work correctly?

Can someone enlighten me what I am doing wrong?



  return ( values[ values == - | values == -99] <- NA )


the assignment itself evaluates to the assigned value, in this case NA;
that's what your function returns. Check this:


foo <- (a <- 3)
a

[1] 3

foo

[1] 3

foo <- (a <- NA)
a

[1] NA

foo

[1] NA

this way your function should work as intended:

ConvertMissingToNA <- function(values)
{
values[ values == - | values == -99] <- NA
return values
}

Peter

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


Re: [R] Unexpected returned value from a function

2008-09-16 Thread p

Sorry, there was a stupid cut & paste mistake (missing parentheses in
return statement...)

ConvertMissingToNA <- function(values)
{
values[values == - | values == -99] <- NA
return(values)
}


Peter

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Multiple plots per window

2008-09-21 Thread p

Hi all,

I'm currently working through "The Analysis of Time Series" by Chris
Chatfield. In order to also get a better understanding of R, I play
around with the examples and Exercises (no homework or assignement,
just selfstudy!!).

Exercise 2.1 gives the following dataset (sales figures for 4 week
intervals):


sales2.1.dataframe

   1995 1996 1997 1998
1   153  133  145  111
2   189  177  200  170
3   221  241  187  243
4   215  228  201  178
5   302  283  292  248
6   223  255  220  202
7   201  238  233  163
8   173  164  172  139
9   121  128  119  120
10  106  108   81   96
11   86   87   65   95
12   87   74   76   53
13  108   95   74   94

I want to plot the histograms/densities for all four years in one window.
After trying out a couple of things, I finally ended up with the following
(it took me two hours - Ouch!):

sales2.1 <- c(153,189,221,215,302,223,201,173,121,106,86,87,108,
133,177,241,228,283,255,238,164,128,108,87,74,95,
145,200,187,201,292,220,233,172,119,81,65,76,74,
111,170,243,178,248,202,163,139,120,96,95,53,94)
sales2.1.matrix <- sales2.1
dim(sales2.1.matrix) <- c(4,13)
sales2.1.dataframe <- as.data.frame(sales2.1.matrix)
names(sales2.1.dataframe) <- c("1995","1996","1997","1998")

X11()
split.screen(c(2,2))
for (i in 1:4)
{
screen(i)
hist(sales2.1.dataframe[[i]],
probability=T,
xlim=c(0,400),
ylim=c(0,0.006),
main=names(sales2.1.dataframe)[i],
xlab="Sales")
lines(density(sales2.1.dataframe[[i]]))
}
close.screen(all=TRUE)

Although I'm happy that I finally got something that is pretty close
to what I wanted, I'm not sure whether this is the best or most elegant
way to do it. How would you do it? What functions/packages should I
look into, in order to improve these plots?

Thanks in advance for your comments and suggestions,

Peter

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 plots per window

2008-09-21 Thread p

sorry, as Mark Leeds pointed out to me, the row/column numbers where
mixed up in my example... happens when you cut & paste like mad from
your history... it should read as follows:

sales2.1 <- c(153,189,221,215,302,223,201,173,121,106,86,87,108,
133,177,241,228,283,255,238,164,128,108,87,74,95,
145,200,187,201,292,220,233,172,119,81,65,76,74,
111,170,243,178,248,202,163,139,120,96,95,53,94)

sales2.1.matrix <- sales2.1
dim(sales2.1.matrix) <- c(13,4)

sales2.1.dataframe <- as.data.frame(sales2.1.matrix)
names(sales2.1.dataframe) <- c("1995","1996","1997","1998")

Peter

Quoting [EMAIL PROTECTED]:


Hi all,

I'm currently working through "The Analysis of Time Series" by Chris
Chatfield. In order to also get a better understanding of R, I play
around with the examples and Exercises (no homework or assignement,
just selfstudy!!).

Exercise 2.1 gives the following dataset (sales figures for 4 week
intervals):


sales2.1.dataframe

   1995 1996 1997 1998
1   153  133  145  111
2   189  177  200  170
3   221  241  187  243
4   215  228  201  178
5   302  283  292  248
6   223  255  220  202
7   201  238  233  163
8   173  164  172  139
9   121  128  119  120
10  106  108   81   96
11   86   87   65   95
12   87   74   76   53
13  108   95   74   94

I want to plot the histograms/densities for all four years in one window.
After trying out a couple of things, I finally ended up with the following
(it took me two hours - Ouch!):

sales2.1 <- c(153,189,221,215,302,223,201,173,121,106,86,87,108,
133,177,241,228,283,255,238,164,128,108,87,74,95,
145,200,187,201,292,220,233,172,119,81,65,76,74,
111,170,243,178,248,202,163,139,120,96,95,53,94)
sales2.1.matrix <- sales2.1
dim(sales2.1.matrix) <- c(4,13)
sales2.1.dataframe <- as.data.frame(sales2.1.matrix)
names(sales2.1.dataframe) <- c("1995","1996","1997","1998")

X11()
split.screen(c(2,2))
for (i in 1:4)
{
screen(i)
hist(sales2.1.dataframe[[i]],
probability=T,
xlim=c(0,400),
ylim=c(0,0.006),
main=names(sales2.1.dataframe)[i],
xlab="Sales")
lines(density(sales2.1.dataframe[[i]]))
}
close.screen(all=TRUE)

Although I'm happy that I finally got something that is pretty close
to what I wanted, I'm not sure whether this is the best or most elegant
way to do it. How would you do it? What functions/packages should I
look into, in order to improve these plots?

Thanks in advance for your comments and suggestions,

Peter

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Newbie help: Data in an arma fit

2007-10-22 Thread p
On Tue 23 Oct 07, 10:56 AM, Gad Abraham <[EMAIL PROTECTED]> said:
> caffeine wrote:
>> I'd like to fit an ARMA(1,1) model to some data (Federal Reserve Bank
>> interest rates) that looks like:
>> ...
>> 30JUN2006, 5.05
>> 03JUL2006, 5.25
>> 04JUL2006, N  < here!
>> 05JUL2006, 5.25
>> ...
>> One problem is that holidays have that "N" for their data.  As a test, I
>> tried fitting ARMA(1,1) with and without the holidays deleted.  In other
>> words, I fit the above data as well as this data:
>> ...
>> 30JUN2006, 5.05
>> 03JUL2006, 5.25
>> 05JUL2006, 5.25
>> ...
>> and the ARMA coefficients came out different.   My question is: Should I
>> delete all the holidays from my data file?   What exactly does R do with 
>> the
>> "N" values in the fit for the ARMA coefficients?
>> As a related question, the weekends don't have entries (since the FRB is
>> closed on all weekends).  Does the fact that my data is not regularly 
>> spaced
>> pose a problem for ARMA fitting?
>
> A few comments:
>
> * Is the time series stationary? You can't fit ARIMA to nonstationary data.
>
> * One thing you could try is linear regression of interest rate on time and 
> indicator variables for day of week and special days like holidays. Then 
> fit an ARIMA to the regression residuals.
>
> * Any specific reason why ARMA(1,1)? Have you looked at the acf and pacf of 
> the time series?
>
> Cheers,
> Gad

Hi Gad,

This is supposed to be more of an exercise in R than fitting models.  Since
the goal is to simply learn R, we're assuming stationarity.  The series is
nearly weakly stationary, but for the purpose of this exercise, we're to
assume that it is stationary.

The choice of order is pretty arbitrary too.  Just an exercise in getting to
feel comfortable with R.

I guess my question is not so much about the FRB rates themselves but in how
R interprets data.   If I have a time series in a file:

1   .5
2   .6
3   .4
4   No data
5   .3
6   .8

Would it be appropriate to delete the line that says "No data"?  Or does R
ignore non-numerical data?

Sorry if my question was misleading!

Pete

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Is there a way to get R script line number

2017-04-06 Thread Brad P
Hello,

Is there a way to get the current line number in an R script?

As a silly example, if I have the following script and a function called
getLineNumber (suppose one exists!), then the result would be 3.

1 # This is start of script
2
3 print( getLineNumber() )
4
5 # End of script

Thanks for any ideas!

[[alternative HTML version deleted]]

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


[R] Is there a way to open R terminal running in the background

2017-04-19 Thread Brad P
Hello,

I am working on a GUI, which is working well so far.
I am working on a Windows 7 machine with 64 bit R (Microsoft R Open 3.3.2)

Essentially:
1) a VBS executable is used to open the GUI leaving the R terminal running
in the background but not showing using:

CreateObject("Wscript.Shell").Run R.exe CMD BATCH MyGUI.R , 0, TRUE

2) for the GUI I use code similar to that shown below

My question is, when the GUI is opened, an instance of R runs in the
background.
Is there a way to show ('open') that R terminal?  And similarly put it back
as invisible.
I am imagining that I can write an R function to either open this directly
or by using Windows OS commands

I have found  a way to open a terminal using the code at this link, but it
is not ideal (I want an actual R terminal):
http://freesourcecode.net/rprojects/104/sourcecode/ex-RGtk2-terminal.R



# MyGUI.R ##
library(RGtk2)

# initiate main window
main_window <<- gtkWindow(show = FALSE)
main_window["title"] <- "My GUI"
main_window$setDefaultSize(800, 600) # (width, height)

# problem: red [X] in top-right leaves underlying R instance open
main_window$deletable <- FALSE  # makes the top-right [X] delete option not
work ...
# Can this button be reprogrammed??

# function to read in data file
open_cb <- function(widget, window) {
  dialog <- gtkFileChooserDialog("Choose a CSV file", window, "open",
 "gtk-cancel", GtkResponseType["cancel"],
"gtk-open",
 GtkResponseType["accept"])
  if (dialog$run() == GtkResponseType["accept"]) {
fileName <<- dialog$getFilename()
dat <<- read.csv(fileName, header=TRUE, na.strings=c("","NA"))
  }
  dialog$destroy()
  statusbar$push(info, paste("Dataset", fileName, "is currently loaded."))
}

# variable to indicate whether it is time to stop R
StopNOW <<- 0

quit_cb <- function(widget, window){
  StopNOW <<- 1
  window$destroy()
  quit(save = "no")
}

# Lists actions in dropdown or toolbar menus
actions <- list(
  list("FileMenu", NULL, "Input File"),
  list("Open", "gtk-open", "_Import CSV File", "O",
   "Select a CSV file to load as a spreadsheet", open_cb),
  list("Quit", "gtk-quit", "_Quit", "Q",
   "Quit the application", quit_cb)
)
action_group <- gtkActionGroup("spreadsheetActions")
action_group$addActions(actions, main_window)

ui_manager <- gtkUIManager()
ui_manager$insertActionGroup(action_group, 0)
merge <- ui_manager$newMergeId()
ui_manager$addUi(merge.id = merge, path = "/", name = "menubar", action =
NULL, type = "menubar", top = FALSE)
ui_manager$addUi(merge, "/menubar", "file", "FileMenu", "menu", FALSE)
ui_manager$addUi(merge, "/menubar/file", "open", "Open", "menuitem", FALSE)
ui_manager$addUi(merge, "/", "toolbar", NULL, "toolbar", FALSE)
ui_manager$addUi(merge, "/toolbar", "quit", "Quit", "toolitem", FALSE)

menubar <- ui_manager$getWidget("/menubar")
toolbar <- ui_manager$getWidget("/toolbar")
main_window$addAccelGroup(ui_manager$getAccelGroup())

# Status bar shown at bottom left of GUI
statusbar <- gtkStatusbar()
info <- statusbar$getContextId("info")
statusbar$push(info, "Ready")

notebook <- gtkNotebook()
notebook$setTabPos("bottom")

vbox <- gtkVBox(homogeneous = FALSE, spacing = 0)
vbox$packStart(menubar, expand = FALSE, fill = FALSE, padding = 0)
vbox$packStart(toolbar, FALSE, FALSE, 0) # Uncomment if toolbar is used
vbox$packStart(notebook, TRUE, TRUE, 0)
vbox$packStart(statusbar, FALSE, FALSE, 0)
main_window$add(vbox)

# open GUI window
main_window$show()

gtkWidgetGrabFocus(main_window)

# This repeat loop & stopNOW variable keeps the GUI window open until closed
repeat {
Sys.sleep(0.001)
if (StopNOW == 1) break
  }
# End GUI Code

[[alternative HTML version deleted]]

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


Re: [R] Is there a way to open R terminal running in the background

2017-04-19 Thread Brad P
Duncan,

I was thinking to have an additional button in the GUI which would use an R
function to open the window/process running in the background.
I don't think this is a VBS question, as it is simply used to start the GUI
without opening R and calling it directly.
I suppose this may be considered a Windows question - I will look further
into opening a process running in the background using DOS commands.

Thank you for your time.


On Wed, Apr 19, 2017 at 12:14 PM, Duncan Murdoch 
wrote:

> On 19/04/2017 11:44 AM, Brad P wrote:
>
>> Hello,
>>
>> I am working on a GUI, which is working well so far.
>> I am working on a Windows 7 machine with 64 bit R (Microsoft R Open 3.3.2)
>>
>> Essentially:
>> 1) a VBS executable is used to open the GUI leaving the R terminal running
>> in the background but not showing using:
>>
>> CreateObject("Wscript.Shell").Run R.exe CMD BATCH MyGUI.R , 0, TRUE
>>
>
> I think this is more of a Microsoft question than anything specific to R.
> How do you ask VBS to show you a process that it is running?
>
> No idea where to go with VBS questions.
>
> Duncan Murdoch
>
>
>> 2) for the GUI I use code similar to that shown below
>>
>> My question is, when the GUI is opened, an instance of R runs in the
>> background.
>> Is there a way to show ('open') that R terminal?  And similarly put it
>> back
>> as invisible.
>> I am imagining that I can write an R function to either open this directly
>> or by using Windows OS commands
>>
>> I have found  a way to open a terminal using the code at this link, but it
>> is not ideal (I want an actual R terminal):
>> http://freesourcecode.net/rprojects/104/sourcecode/ex-RGtk2-terminal.R
>>
>>
>>
>> # MyGUI.R 
>> ##
>> library(RGtk2)
>>
>> # initiate main window
>> main_window <<- gtkWindow(show = FALSE)
>> main_window["title"] <- "My GUI"
>> main_window$setDefaultSize(800, 600) # (width, height)
>>
>> # problem: red [X] in top-right leaves underlying R instance open
>> main_window$deletable <- FALSE  # makes the top-right [X] delete option
>> not
>> work ...
>> # Can this button be reprogrammed??
>>
>> # function to read in data file
>> open_cb <- function(widget, window) {
>>   dialog <- gtkFileChooserDialog("Choose a CSV file", window, "open",
>>  "gtk-cancel", GtkResponseType["cancel"],
>> "gtk-open",
>>  GtkResponseType["accept"])
>>   if (dialog$run() == GtkResponseType["accept"]) {
>> fileName <<- dialog$getFilename()
>> dat <<- read.csv(fileName, header=TRUE, na.strings=c("","NA"))
>>   }
>>   dialog$destroy()
>>   statusbar$push(info, paste("Dataset", fileName, "is currently loaded."))
>> }
>>
>> # variable to indicate whether it is time to stop R
>> StopNOW <<- 0
>>
>> quit_cb <- function(widget, window){
>>   StopNOW <<- 1
>>   window$destroy()
>>   quit(save = "no")
>> }
>>
>> # Lists actions in dropdown or toolbar menus
>> actions <- list(
>>   list("FileMenu", NULL, "Input File"),
>>   list("Open", "gtk-open", "_Import CSV File", "O",
>>"Select a CSV file to load as a spreadsheet", open_cb),
>>   list("Quit", "gtk-quit", "_Quit", "Q",
>>"Quit the application", quit_cb)
>> )
>> action_group <- gtkActionGroup("spreadsheetActions")
>> action_group$addActions(actions, main_window)
>>
>> ui_manager <- gtkUIManager()
>> ui_manager$insertActionGroup(action_group, 0)
>> merge <- ui_manager$newMergeId()
>> ui_manager$addUi(merge.id = merge, path = "/", name = "menubar", action =
>> NULL, type = "menubar", top = FALSE)
>> ui_manager$addUi(merge, "/menubar", "file", "FileMenu", "menu", FALSE)
>> ui_manager$addUi(merge, "/menubar/file", "open", "Open", "menuitem",
>> FALSE)
>> ui_manager$addUi(merge, "/", "toolbar", NULL, "toolbar", FALSE)
>> ui_manager$addUi(merge, "/toolbar", "quit", "Quit", "toolitem", FALSE)
>>
>> menubar

[R] Need help with renaming sub-directories and its files after attribute vales from a shapefile

2016-09-14 Thread P Mads
Hello,
Keep in mind I am VERY new to using R... What I am trying to do is package
hundreds of files into a new sub-directory. I was able to accomplish this
with the code below. HOWEVER, I have come to find that instead of merely
having to name the new sub-directory after the 7-digit numeric prefix in
the file names, the sub-directories AND the corresponding files all have to
be named after a certain attribute value in a shapefile ("DOQ_Index").
Basically, what I need to do is 1) match the filenames' 7-digit prefix to
the "ID" attribute field in the shapefile (eg. 4310950 = '4310950' - "ID"
field); then, 2) for those matches, I need to create a sub-directory based
on a DIFFERENT attribute field value ("CODE" field) and then 3) rename the
matching files based on the "CODE" attribute field and move those files to
the new sub-directory. Whew. Does that make sense?? Anyway, can someone
help me with this while keeping the basic code structure below?
Thank you! - Pmads

#read in the QuadIndex *-- I recently added this step thinking this is how
to read the shapefile*
q<- readOGR(dsn="C:/GeoHub/Test", layer="DOQ_Index")

#set the working directory
setwd("C:/GeoHub/Test/TestZip")

#get a list of directories
dlist<- list.dirs()
#remove the first vector
dlist<- dlist[-1]

#If the files are all in the working directory
  vec1 <-  list.files()
  vec1

  lst1 <- split(vec1,substr(vec1,3,9))

  #Create the sub-directory based on the first 7 numeric prefix
  sapply(file.path(getwd(),names(lst1)),dir.create)

  #Move the files to the sub-directory
  lapply(seq_along(lst1), function(i)
file.rename(lst1[[i]],paste(file.path(names(lst1[i])), lst1[[i]],sep="/")))
  list.files(recursive=TRUE)

[[alternative HTML version deleted]]

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


[R] fields package question

2018-12-24 Thread M P
Hello,
I used commands below to obtain a surface, can plot it and all looks as
expected.
How do I evaluate values at new point. I tried as below but that produces
errors.
Thanks for suggestions/help.

x <- log(lambda)
y <- rh
z <- qext[,,2]

grid.l <- list(abcissa=x,ordinate=y)
xg <- make.surface.grid(grid.l)
out.p <- as.surface(xg,z)
plot.surface(out.p,type="p")

tried:
grid_new.l <- list(abcissa=c(-15.0,-10.),ordinate=y)
xg_new <- make.surface.grid(grid_new.l)

out_new.p <- predict.surface(out.p,xg_new)

results in this prompt:
predict.surface is now the function predictSurface>

[[alternative HTML version deleted]]

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


Re: [R] fields package question

2018-12-25 Thread M P
Thanks, Eric, for looking into that.
The values are below and since I subset the new abcissa  is smaller range
grid_new.l <- list(abcissa=c(-15.0,-14.),ordinate=y)
I am emailing form gmail - don't know why is using html to format when all
is in ascii

x
 [1] -15.20180 -15.01948 -14.86533 -14.73180 -14.61402 -14.50866 -14.41335
 [8] -14.32634 -14.24629 -14.17219
y
 [1] 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45
z
[5,] 0.6467642 0.6467642 0.6467642 0.6467642 0.6467642 0.6467642 0.6467642
 [6,] 0.5597143 0.5597143 0.5597143 0.5597143 0.5597143 0.5597143 0.5597143
 [7,] 0.4854133 0.4854133 0.4854133 0.4854133 0.4854133 0.4854133 0.4854133
 [8,] 0.4278326 0.4278326 0.4278326 0.4278326 0.4278326 0.4278326 0.4278326
 [9,] 0.3834149 0.3834149 0.3834149 0.3834149 0.3834149 0.3834149 0.3834149
[10,] 0.3433031 0.3433031 0.3433031 0.3433031 0.3433031 0.3433031 0.3433031
   [,8]  [,9] [,10]
 [1,] 1.1900951 1.1900951 1.1900951
 [2,] 1.0636935 1.0636935 1.0636935
 [3,] 0.8927228 0.8927228 0.8927228
 [4,] 0.7554456 0.7554456 0.7554456
 [5,] 0.6467642 0.6467642 0.6467642
 [6,] 0.5597143 0.5597143 0.5597143
 [7,] 0.4854133 0.4854133 0.4854133
 [8,] 0.4278326 0.4278326 0.4278326
 [9,] 0.3834149 0.3834149 0.3834149
[10,] 0.3433031 0.3433031 0.3433031



On Tue, Dec 25, 2018 at 12:45 AM Eric Berger  wrote:

> Since you don't provide lambda, rh or qext it is impossible to reproduce
> what you are seeing.
> Also note that in this mailing list HTML formatted emails are not passed
> along.
>
>
>
> On Tue, Dec 25, 2018 at 4:13 AM M P  wrote:
>
>> Hello,
>> I used commands below to obtain a surface, can plot it and all looks as
>> expected.
>> How do I evaluate values at new point. I tried as below but that produces
>> errors.
>> Thanks for suggestions/help.
>>
>> x <- log(lambda)
>> y <- rh
>> z <- qext[,,2]
>>
>> grid.l <- list(abcissa=x,ordinate=y)
>> xg <- make.surface.grid(grid.l)
>> out.p <- as.surface(xg,z)
>> plot.surface(out.p,type="p")
>>
>> tried:
>> grid_new.l <- list(abcissa=c(-15.0,-10.),ordinate=y)
>> xg_new <- make.surface.grid(grid_new.l)
>>
>> out_new.p <- predict.surface(out.p,xg_new)
>>
>> results in this prompt:
>> predict.surface is now the function predictSurface>
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

[[alternative HTML version deleted]]

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


Re: [R] fields package question

2018-12-25 Thread M P
Actually, let's set it
grid_new.l <- list(abcissa=c(-15.0,-14.5),ordinate=y)
to avoid out of bounds

On Tue, Dec 25, 2018 at 4:41 PM M P  wrote:

> Thanks, Eric, for looking into that.
> The values are below and since I subset the new abcissa  is smaller range
> grid_new.l <- list(abcissa=c(-15.0,-14.),ordinate=y)
> I am emailing form gmail - don't know why is using html to format when all
> is in ascii
>
> x
>  [1] -15.20180 -15.01948 -14.86533 -14.73180 -14.61402 -14.50866 -14.41335
>  [8] -14.32634 -14.24629 -14.17219
> y
>  [1] 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45
> z
> [5,] 0.6467642 0.6467642 0.6467642 0.6467642 0.6467642 0.6467642 0.6467642
>  [6,] 0.5597143 0.5597143 0.5597143 0.5597143 0.5597143 0.5597143 0.5597143
>  [7,] 0.4854133 0.4854133 0.4854133 0.4854133 0.4854133 0.4854133 0.4854133
>  [8,] 0.4278326 0.4278326 0.4278326 0.4278326 0.4278326 0.4278326 0.4278326
>  [9,] 0.3834149 0.3834149 0.3834149 0.3834149 0.3834149 0.3834149 0.3834149
> [10,] 0.3433031 0.3433031 0.3433031 0.3433031 0.3433031 0.3433031 0.3433031
>[,8]  [,9] [,10]
>  [1,] 1.1900951 1.1900951 1.1900951
>  [2,] 1.0636935 1.0636935 1.0636935
>  [3,] 0.8927228 0.8927228 0.8927228
>  [4,] 0.7554456 0.7554456 0.7554456
>  [5,] 0.6467642 0.6467642 0.6467642
>  [6,] 0.5597143 0.5597143 0.5597143
>  [7,] 0.4854133 0.4854133 0.4854133
>  [8,] 0.4278326 0.4278326 0.4278326
>  [9,] 0.3834149 0.3834149 0.3834149
> [10,] 0.3433031 0.3433031 0.3433031
>
>
>
> On Tue, Dec 25, 2018 at 12:45 AM Eric Berger 
> wrote:
>
>> Since you don't provide lambda, rh or qext it is impossible to reproduce
>> what you are seeing.
>> Also note that in this mailing list HTML formatted emails are not passed
>> along.
>>
>>
>>
>> On Tue, Dec 25, 2018 at 4:13 AM M P  wrote:
>>
>>> Hello,
>>> I used commands below to obtain a surface, can plot it and all looks as
>>> expected.
>>> How do I evaluate values at new point. I tried as below but that produces
>>> errors.
>>> Thanks for suggestions/help.
>>>
>>> x <- log(lambda)
>>> y <- rh
>>> z <- qext[,,2]
>>>
>>> grid.l <- list(abcissa=x,ordinate=y)
>>> xg <- make.surface.grid(grid.l)
>>> out.p <- as.surface(xg,z)
>>> plot.surface(out.p,type="p")
>>>
>>> tried:
>>> grid_new.l <- list(abcissa=c(-15.0,-10.),ordinate=y)
>>> xg_new <- make.surface.grid(grid_new.l)
>>>
>>> out_new.p <- predict.surface(out.p,xg_new)
>>>
>>> results in this prompt:
>>> predict.surface is now the function predictSurface>
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>

[[alternative HTML version deleted]]

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


Re: [R] About reshape dataset

2016-10-23 Thread P Tennant
You could convert your data from a wide format to a long format using 
the reshape function in base R:


DF2 <- reshape(DF, direction="long",
idvar=names(DF)[1:3],
varying=c("site1_elev", "site1_temp", "site2_elev", "site2_temp"),
v.names=c("elev", "temp"),
times=1:2,
timevar = "siteID")

rownames(DF2) <- NULL
DF2

  year month day siteID elev temp
1 2000 5   6  1 1300   20
2 2000 5   7  1 1300   21
3 2000 5   8  1 1300   19
4 2000 5   9  1 1300   22
5 2000 5   6  2 1500   21
6 2000 5   7  2 1500   22
7 2000 5   8  2 1500   20
8 2000 5   9  2 1500   23

Philip


On 23/10/2016 4:50 AM, lily li wrote:

Hi R users,

I want to melt a dataframe, but it mixed up the variables.

DF is the original dataset:
year  month  day  site1_elev  site2_elev  site1_temp  site2_temp
2000 561300  150020  21

2000 571300  150021  22
2000 581300  150019  20
2000 591300  150022  23

How to melt the dataframe and get the following dataset? Thanks for your
help.

year  month  day  siteID   elev   temp
20005 6   1  130020
20005 6   2  150021
20005 7   1  130021
20005 7   2  150022

[[alternative HTML version deleted]]

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


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


Re: [R] difference

2016-10-28 Thread P Tennant

Hi,

You could use an anonymous function to operate on each `year-block' of 
your dataset, then assign the result as a new column:


d <- data.frame(year=c(rep(2001, 3), rep(2002, 3)),
num=c(25,75,150,30,85,95))

d$diff <- unlist(by(d$num, d$year, function(x) x - x[1]))
d

  year num diff
1 2001  250
2 2001  75   50
3 2001 150  125
4 2002  300
5 2002  85   55
6 2002  95   65


Philip

On 28/10/2016 3:20 PM, Ashta wrote:

Hi all,

I want to calculate the difference  between successive row values to
the first row value within year.
How do I get that?

  Here isthe sample of data
Year   Num
200125
200175
2001   150
200230
200285
200295

Desired output
Year   Num  diff
200125   0
200175  50
2001  150125
2002300
200285  55
200295  65

Thank you.

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


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


Re: [R] difference

2016-10-29 Thread P Tennant

Hi,

As Jeff said, more than one grouping variable can be supplied, and there 
is an example at the bottom of the help page for ave(). The same goes 
for by(), but the order that you supply the grouping variables becomes 
important. Whichever grouping variable is supplied first to by() will 
change its levels first in the output sequence. You can see from your 
dataset:


d2 <- data.frame(city=rep(1:2, ea=6),
year=c(rep(2001, 3), rep(2002, 3), rep(2001, 3), rep(2002, 3)),
num=c(25,75,150,35,65,120,25,95,150,35,110,120))

d2
   # city year num
# 1 1 2001  25
# 2 1 2001  75
# 3 1 2001 150
# 4 1 2002  35
# 5 1 2002  65
# 6 1 2002 120
# 7 2 2001  25
# 8 2 2001  95
# 9 2 2001 150
# 102 2002  35
# 112 2002 110
# 122 2002 120

that `year' changes its levels through the sequence down the table 
first, and then `city' changes. You want your new column to align with 
this sequence. If you put city first in the list of grouping variables 
for by(), rather than `year', you won't get the sequence reflected in 
your dataset:


by(d2$num, d2[c('city', 'year')], function(x) x - x[1])

# city: 1
# year: 2001
# [1]   0  50 125
# -
# city: 2
# year: 2001
# [1]   0  70 125
# -
# city: 1
# year: 2002
# [1]  0 30 85
# -
# city: 2
# year: 2002
# [1]  0 75 85

In contrast to using by() as I've suggested, using match() to create 
indices that flag when a new `city/year' category is encountered seems a 
more explicit, secure way to do the calculation. Adapting an earlier 
solution provided in this thread:


year.city <- with(d2, interaction(year, city))
indexOfFirstYearCity <- match(year.city, year.city)
indexOfFirstYearCity
# [1]  1  1  1  4  4  4  7  7  7 10 10 10

d2$diff <- d2$num - d2$num[indexOfFirstYearCity]
d2

  city year num diff
1 1 2001  250
2 1 2001  75   50
3 1 2001 150  125
4 1 2002  350
5 1 2002  65   30
6 1 2002 120   85
7 2 2001  250
8 2 2001  95   70
9 2 2001 150  125
102 2002  350
112 2002 110   75
122 2002 120   85


Philip

On 29/10/2016 3:15 PM, Jeff Newmiller wrote:

Now would be an excellent time to read the help page for ?ave. You can specify 
multiple grouping variables.


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


Re: [R] lattice graph with free scales and reversed axis values

2016-11-05 Thread P Tennant

Hi Naresh,

You could calculate the ranges explicitly and then supply to scales():

holdRange <- vector('list', length(unique(my.df$name)))
for(i in 1:length(holdRange)){
holdRange[[i]] <- 
rev(range(my.df$x[my.df$name==unique(my.df$name)[i]]))

}

holdRange

# [[1]]
# [1] -5.052890 -9.967671

# [[2]]
# [1]  2.648870 -2.629866

xyplot(y ~ x | name, data = my.df,
type = c("p", "g"),
scales = list(relation="free", limits=holdRange))


Philip


On 6/11/2016 9:59 AM, Naresh Gurbuxani wrote:

I want to draw a lattice graph where different panels have different ranges AND 
the order of values is reversed.  I am struggling to achieve both at the same 
time.  Can you help?

Thanks,
Naresh

# Create dummy data for illustration
my.df<- data.frame(x = runif(100, min = -10, max = -5), name = "A")
my.df<- rbind(my.df, data.frame(x = rnorm(100), name = "B"))
my.df<- within(my.df, {y<- x + 0.2 * rnorm(200)})

# This works.  Both x and y axes show values in reverse order.
xyplot(y ~ x, groups = name, data = my.df, xlim = rev(range(my.df$x)), ylim = rev(range(my.df$y)), 
type = c("p", "g"))

# This works.  Both x and y axes show values in reverse order.
xyplot(y ~ x | name, data = my.df, xlim = rev(range(my.df$x)), ylim = rev(range(my.df$y)), type = 
c("p", "g"))

# This does not work as intended.  x and y values are in reverse order.  But 
both panels have the same and x and y ranges.  scales argument does not seem to 
have any effect.
xyplot(y ~ x | name, data = my.df, xlim = rev(range(my.df$x)), ylim = rev(range(my.df$y)), scales = list(x = 
"free", y = "free"), type = c("p", "g"))

# This does not work at all.  panel.xyplot does not see to take xlim or ylim 
arguments.
xyplot(y ~ x | name, data = my.df, scales = list(x = "free", y = "free"), panel 
= function(x,y,subscripts, ...) {
panel.xyplot(x,y, ylim = rev(range(y[subscripts]), xlim = 
rev(range(x[subscripts]
})

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


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


Re: [R] About data manipulation

2016-11-26 Thread P Tennant

Hi,

It may help that:

aggregate(DF$total, list(DF$note, DF$id, DF$month), mean)

should give you means broken down by time slice (note), id and month. 
You could then subset means for GA or GB from the aggregated dataframe.


Philip

On 27/11/2016 3:11 AM, lily li wrote:

Hi R users,

I'm trying to manipulate a dataframe and have some difficulties.

The original dataset is like this:

DF
year   month   total   id note
2000 1 98GA   1
2001 1100   GA   1
2002 2 99GA   1
2002 2 80GB   1
...
2012 1 78GA   2
...

The structure is like this: when year is between 2000-2005, note is 1; when
year is between 2006-2010, note is 2; GA, GB, etc represent different
groups, but they all have years 2000-2005, 2006-2010, 2011-2015.
I want to calculate one average value for each month in each time slice.
For example, between 2000-2005, when note is 1, for GA, there is one value
in month 1, one value in month 2, etc; for GB, there is one value in month
1, one value in month 2, between this time period. So later, there is no
'year' column, but other columns.
I tried the script: DF_GA = aggregate(total~year+month,data=subset(DF,
id==GA¬e==1)), but it did not give me the ideal dataframe. How to do
then?
Thanks for your help.

[[alternative HTML version deleted]]

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


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


Re: [R] remove

2017-02-11 Thread P Tennant

Hi Val,

The by() function could be used here. With the dataframe dfr:

# split the data by first name and check for more than one last name for 
each first name

res <- by(dfr, dfr['first'], function(x) length(unique(x$last)) > 1)
# make the result more easily manipulated
res <- as.table(res)
res
# first
 # Alex   Bob  Cory
 # TRUE FALSE FALSE

# then use this result to subset the data
nw.dfr <- dfr[!dfr$first %in% names(res[res]) , ]
# sort if needed
nw.dfr[order(nw.dfr$first) , ]

  first week last
2   Bob1 John
5   Bob2 John
6   Bob3 John
3  Cory1 Jack
4  Cory2 Jack


Philip

On 12/02/2017 4:02 PM, Val wrote:

Hi all,
I have a big data set and want to  remove rows conditionally.
In my data file  each person were recorded  for several weeks. Somehow
during the recording periods, their last name was misreported.   For
each person,   the last name should be the same. Otherwise remove from
the data. Example, in the following data set, Alex was found to have
two last names .

Alex   West
Alex   Joseph

Alex should be removed  from the data.  if this happens then I want
remove  all rows with Alex. Here is my data set

df<- read.table(header=TRUE, text='first  week last
Alex1  West
Bob 1  John
Cory1  Jack
Cory2  Jack
Bob 2  John
Bob 3  John
Alex2  Joseph
Alex3  West
Alex4  West ')

Desired output

   first  week last
1 Bob 1   John
2 Bob 2   John
3 Bob 3   John
4 Cory 1   Jack
5 Cory 2   Jack

Thank you in advance

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


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


Re: [R] remove

2017-02-11 Thread P Tennant

Hi Jeff,

Why do you say ave() is better suited *because* it always returns a 
vector that is just as long as the input vector? Is it because that 
feature (of equal length), allows match() to be avoided, and as a 
result, the subsequent subsetting is faster with very large datasets?


Thanks, Philip


On 12/02/2017 5:42 PM, Jeff Newmiller wrote:
The "by" function aggregates and returns a result with generally fewer 
rows than the original data. Since you are looking to index the rows 
in the original data set, the "ave" function is better suited because 
it always returns a vector that is just as long as the input vector:


# I usually work with character data rather than factors if I plan
# to modify the data (e.g. removing rows)
DF <- read.table( text=
'first  week last
Alex1  West
Bob 1  John
Cory1  Jack
Cory2  Jack
Bob 2  John
Bob 3  John
Alex2  Joseph
Alex3  West
Alex4  West
', header = TRUE, as.is = TRUE )

err <- ave( DF$last
  , DF[ , "first", drop = FALSE]
  , FUN = function( lst ) {
  length( unique( lst ) )
}
  )
result <- DF[ "1" == err, ]
result

Notice that the ave function returns a vector of the same type as was 
given to it, so even though the function returns a numeric the err

vector is character.

If you wanted to be able to examine more than one other column in 
determining the keep/reject decision, you could do:


err2 <- ave( seq_along( DF$first )
   , DF[ , "first", drop = FALSE]
   , FUN = function( n ) {
  length( unique( DF[ n, "last" ] ) )
 }
   )
result2 <- DF[ 1 == err2, ]
result2

and then you would have the option to re-use the "n" index to look at 
other columns as well.


Finally, here is a dplyr solution:

library(dplyr)
result3 <- (   DF
   %>% group_by( first ) # like a prep for ave or by
   %>% mutate( err = length( unique( last ) ) ) # similar to ave
   %>% filter( 1 == err ) # drop the rows with too many last 
names

   %>% select( -err ) # drop the temporary column
   %>% as.data.frame # convert back to a plain-jane data frame
   )
result3

which uses a small set of verbs in a pipeline of functions to go from 
input to result in one pass.


If your data set is really big (running out of memory big) then you 
might want to investigate the data.table or sqlite packages, either of 
which can be combined with dplyr to get a standardized syntax for 
managing larger amounts of data. However, most people actually aren't 
running out of memory so in most cases the extra horsepower isn't 
actually needed.


On Sun, 12 Feb 2017, P Tennant wrote:


Hi Val,

The by() function could be used here. With the dataframe dfr:

# split the data by first name and check for more than one last name 
for each first name

res <- by(dfr, dfr['first'], function(x) length(unique(x$last)) > 1)
# make the result more easily manipulated
res <- as.table(res)
res
# first
# Alex   Bob  Cory
# TRUE FALSE FALSE

# then use this result to subset the data
nw.dfr <- dfr[!dfr$first %in% names(res[res]) , ]
# sort if needed
nw.dfr[order(nw.dfr$first) , ]

 first week last
2   Bob1 John
5   Bob2 John
6   Bob3 John
3  Cory1 Jack
4  Cory2 Jack


Philip

On 12/02/2017 4:02 PM, Val wrote:

Hi all,
I have a big data set and want to  remove rows conditionally.
In my data file  each person were recorded  for several weeks. Somehow
during the recording periods, their last name was misreported.   For
each person,   the last name should be the same. Otherwise remove from
the data. Example, in the following data set, Alex was found to have
two last names .

Alex   West
Alex   Joseph

Alex should be removed  from the data.  if this happens then I want
remove  all rows with Alex. Here is my data set

df<- read.table(header=TRUE, text='first  week last
Alex1  West
Bob 1  John
Cory1  Jack
Cory2  Jack
Bob 2  John
Bob 3  John
Alex2  Joseph
Alex3  West
Alex4  West ')

Desired output

   first  week last
1 Bob 1   John
2 Bob 2   John
3 Bob 3   John
4 Cory 1   Jack
5 Cory 2   Jack

Thank you in advance

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproduci

Re: [R] remove

2017-02-12 Thread P Tennant
3

which uses a small set of verbs in a pipeline of functions to go from

input

to result in one pass.

If your data set is really big (running out of memory big) then you

might

want to investigate the data.table or sqlite packages, either of

which can

be combined with dplyr to get a standardized syntax for managing

larger

amounts of data. However, most people actually aren't running out of

memory

so in most cases the extra horsepower isn't actually needed.


On Sun, 12 Feb 2017, P Tennant wrote:


Hi Val,

The by() function could be used here. With the dataframe dfr:

# split the data by first name and check for more than one last name

for

each first name
res<- by(dfr, dfr['first'], function(x) length(unique(x$last))>  1)
# make the result more easily manipulated
res<- as.table(res)
res
# first
# Alex   Bob  Cory
# TRUE FALSE FALSE

# then use this result to subset the data
nw.dfr<- dfr[!dfr$first %in% names(res[res]) , ]
# sort if needed
nw.dfr[order(nw.dfr$first) , ]

  first week last
2   Bob1 John
5   Bob2 John
6   Bob3 John
3  Cory1 Jack
4  Cory2 Jack


Philip

On 12/02/2017 4:02 PM, Val wrote:

Hi all,
I have a big data set and want to  remove rows conditionally.
In my data file  each person were recorded  for several weeks.

Somehow

during the recording periods, their last name was misreported.

For

each person,   the last name should be the same. Otherwise remove

from

the data. Example, in the following data set, Alex was found to

have

two last names .

Alex   West
Alex   Joseph

Alex should be removed  from the data.  if this happens then I want
remove  all rows with Alex. Here is my data set

df<- read.table(header=TRUE, text='first  week last
Alex1  West
Bob 1  John
Cory1  Jack
Cory2  Jack
Bob 2  John
Bob 3  John
Alex2  Joseph
Alex3  West
Alex4  West ')

Desired output

first  week last
1 Bob 1   John
2 Bob 2   John
3 Bob 3   John
4 Cory 1   Jack
5 Cory 2   Jack

Thank you in advance

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


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




---

Jeff NewmillerThe .   .  Go

Live...

DCN: Basics: ##.#.   ##.#.  Live

Go...

   Live:   OO#.. Dead: OO#..

Playing

Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.

rocks...1k
---


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


Re: [R] Confused about using data.table package,

2017-02-21 Thread P Tennant
aggregate(), tapply(), do.call(), rbind() (etc.) are extremely useful 
functions that have been available in R for a long time. They remain 
useful regardless what plotting approach you use - base graphics, 
lattice or the more recent ggplot.


Philip


On 22/02/2017 8:40 AM, C W wrote:

Hi Carl,

I have not fully learned dplyr, but it seems harder than tapply() and the
?apply() family in general.

Almost every ggplot2 data I have seen is manipulated using dplyr. Something
must be good about dplyr.

aggregate(), tapply(), do.call(), rbind() will be sorely missed! :(

Thanks!

On Tue, Feb 21, 2017 at 4:21 PM, Carl Sutton  wrote:


Hi

I have found that:
A)  Hadley's new book to be wonderful on how to use dplyr, ggplot2 and his
other packages.  Read this and using as a reference saves major frustration.
b)  Data Camps courses on ggplot2 are also wonderful.  GGPLOT2 has more
capability than I have mastered or needed.  To be an expert with ggplot2
will take some effort.  To just get run of the mill helpful, beautiful
plots, no major time needed for that.

I use both of these sources regularly, especially when what is in my grey
matter memory banks is not working.  Refreshers are sometimes needed.

If your data sets are large and available memory limited, then data.table
is the package I use.   I am amazed at the difference of memory usage with
data.table versus other packages.  My laptop has 16gb ram, and tidyr maxed
it but data.table melt used less than 6gb(if I remember correctly) on my
current work.  Since discovering fread and fwrite, read.table, read.csv,
and write have been benched.   Every script I have includes
library(data.table)

Carl Sutton


[[alternative HTML version deleted]]

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


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


Re: [R] single strip for the same group in dotplot lattice

2017-02-22 Thread P Tennant

Hi Luigi,

I'm afraid I don't understand your toy data as you've described it, but 
if you really don't have run 2 for target A, and don't have run 1 for 
target B, why not just create another factor that reflects this, and 
plot that?


 my.data$clus2 <- with(my.data, interaction(cluster, target))

 and call: dotplot(value ~ type| clus2, ... )


Philip

On 22/02/2017 8:03 PM, Luigi Marongiu wrote:

dear all,
I have a set of data that is subdivided in cluster (run 1/run 2) and in
target (A/B). When plotting, I obtain a panel strip with "run 1" and "run
2" for each "A" and "B" panel, so "run 1" appears twice and so does "run
2". It is possible to merge the strip together so that I will have "run 1"
or "run 2" only once? this will reduce the complexity of the data and allow
more space for more detailed information in the strip.
the data follows,
thank you
L

cluster<- c(rep("run_1", 6), rep("run_2", 6))
type<- rep(c("blank", "positive", "negative"),2)
target<- c(rep("A", 6), rep("B", 6))
value<- c(0.01, 1.1, 0.5,
0.02, 1.6, 0.8,
0.07, 1.4, 0.7,
0.03, 1.4, 0.4)
my.data<- data.frame(cluster, type, target, value)

library(lattice)
dotplot(
   value ~ type|target + cluster,
   my.data,
   groups = type,
   pch=21,
   main = "Luminex analysis MTb humans",
   xlab = "Target", ylab = "Reading",
   col = c("grey", "green", "red"),
   par.settings = list(strip.background = list(col="paleturquoise")),
   scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
   key = list(
 space = "top",
 columns = 3,
 text = list(c("Blank", "Negative", "Positive"), col="black"),
 rectangles = list(col=c("grey", "green", "red"))
   )
)

[[alternative HTML version deleted]]

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


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


[R] Multiplication of data frame with vector

2009-07-07 Thread cir p

Dear group:
sorry for my beginners question, but I'm rather new to R and was searching high 
and low without success:

I have a data frame (df) with variables in the rows and observations in the 
columns like (the actual data frame has 15 columns and 1789 rows):

  early1 early2 early3 early4 early5
M386T1000  57056  55372  58012  55546  57309
M336T9011063  10312  10674  10840  11208
M427T9112064  11956  12692  12340  11924
M429T91 4594   3890   4096   4019   4204
M447T9026553  27647  26889  26751  26929

Now I'm trying to transform each value column-wise to make columns to all have 
the same mean with:

df * mean(mean(df)) / mean(df).

I just can't get my head around this: mean(df) gives me the correct column 
means vector, and mean(mean(df)) gives me the correct total mean. The above 
operation works correctly for individual rows, i.e. if I do
 df[1,]*mean(mean(df))/mean(df)

Can someone tell me what I am doing wrong??
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.


[R] dynamic network analysis

2009-07-30 Thread cir p

Dear group,
I am browsing the web to find suitable software for dynamic network analysis. I 
came across the sna-package under R, but this seems to do static analysis only. 
Is this right? Or is there a separate package for dynamic network analysis?
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] how do i retain decimal values

2009-08-02 Thread P Ehlers

You've already been pointed to options(digits=);
here's another way: since your data appear to be limited to 2 decimals,
why not select your noise from UNIF(0, 0.001)?

More importantly, are you really trying to do correlation between the
values you're showing us? What do you hope to learn from such correlations?

Peter

Manisha Brahmachary wrote:

Hello,

 


I am trying to do a spearman correlation. My data has tied values. To
overcome this issue, I am adding some random noise (values) to my original
data. However when I add the random noise to the data, the final matrix does
not show the new values. I guess the reason being that the noise I add is
very small and the full value including the decimals gets truncated to show
only the value upto two decimal points. Is there a way to keep the full value
as it is without truncation. Thanks for your suggestions in advance.

 


My script:

 


rand.val: stores the random numbers

data: stores the actual values 

 


rand.val<-data.frame(a=runif(11,0.1,0.0001),b=runif(11,0.
1,0.0001),
c=runif(11,0.1,0.0001),d=runif(11,0.1,0.0001),e=runif
(11,0.1,0.0001),f=runif(11,0.1,0.0001),g=runif(11,0.0
0001,0.0001),h=runif(11,0.1,0.0001))  


rand.val<- as.matrix(rand.val)

 

  

data



  X1015 X1238 X1433 X1520 X1847 X1870 X1928 X2422

1-Mar 2 2 2  2.00  2.00  2.00 2  2.00

2-Mar 2 2 2  2.00  2.00  2.00 2  2.00

5-Mar 2 2 2  2.00  4.28  2.00 2  2.00

6-Mar 2 2 2  2.00  2.00  2.00 2  2.72

8-Mar 2 2 2  2.00  2.00  2.00 2  2.00

9-Mar 2 2 2  2.00  2.00  2.00 2  2.00

1-Sep 2 2 2  2.00  2.00  2.00 2  2.00

2-Sep 2 2 2  2.00  2.00  1.39 2  2.00

6-Sep 2 2 2  2.00  2.00  2.00 2  2.00

8-Sep 2 2 2  1.05  2.00  2.00 2  2.00

9-Sep 2 2 2  2.00  2.00  2.00 2  2.00

 

  

rand.val



 abcde
fgh

 [1,] 6.066415e-09 7.243185e-09 2.579000e-09 6.140522e-09 6.630778e-09
7.035269e-09 4.122901e-09 1.449599e-09

 [2,] 3.623560e-09 9.038553e-09 2.269913e-09 7.762269e-09 5.540944e-09
1.478679e-09 6.159272e-09 7.082123e-09

 [3,] 2.085766e-09 3.737900e-09 2.457034e-09 4.939643e-09 3.868569e-09
5.015730e-09 3.320189e-09 3.858882e-09

 [4,] 5.037955e-09 8.234747e-09 5.407211e-09 4.136906e-09 9.078506e-09
8.743044e-09 8.026434e-09 7.089469e-09

 [5,] 6.254242e-09 7.805144e-09 5.264731e-09 3.993522e-09 4.668103e-09
9.429713e-09 2.144503e-09 4.739684e-09

 [6,] 2.051520e-09 3.173583e-09 7.463606e-09 2.799975e-09 6.192137e-09
4.345219e-09 1.301613e-09 2.913670e-09

 [7,] 7.278996e-09 4.329527e-09 2.407270e-09 8.421633e-09 4.196166e-09
9.890987e-09 3.783615e-09 4.093923e-09

 [8,] 9.046755e-09 5.665165e-09 7.740206e-09 3.482159e-09 6.048917e-09
3.170118e-09 6.764364e-09 5.860817e-09

 [9,] 7.766820e-09 5.901440e-09 2.198517e-09 7.349194e-09 6.563453e-09
9.981425e-09 7.768106e-09 4.213753e-09

[10,] 4.493040e-09 5.796008e-09 1.623817e-09 8.136924e-09 1.029656e-09
3.725094e-09 8.767293e-09 7.532047e-09

[11,] 5.974140e-09 4.173989e-09 8.704932e-09 1.929161e-09 5.718819e-09
4.995755e-09 4.723989e-09 9.198158e-09

 

  

data+rand.val



 


X1015 X1238 X1433 X1520 X1847 X1870 X1928 X2422

1-Mar 2 2 2  2.00  2.00  2.00 2  2.00

2-Mar 2 2 2  2.00  2.00  2.00 2  2.00

5-Mar 2 2 2  2.00  4.28  2.00 2  2.00

6-Mar 2 2 2  2.00  2.00  2.00 2  2.72

8-Mar 2 2 2  2.00  2.00  2.00 2  2.00

9-Mar 2 2 2  2.00  2.00  2.00 2  2.00

1-Sep 2 2 2  2.00  2.00  2.00 2  2.00

2-Sep 2 2 2  2.00  2.00  1.39 2  2.00

6-Sep 2 2 2  2.00  2.00  2.00 2  2.00

8-Sep 2 2 2  1.05  2.00  2.00 2  2.00

9-Sep 2 2 2  2.00  2.00  2.00 2  2.00

 


Manisha

 

 

 



[[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] How to deal with this :" object ' obs' not found.

2009-10-02 Thread P Ehlers

Try

 sortedx1=ttx1[order(-ttx1$obs),]

(and ask yourself where obs lives)

-Peter Ehlers

Hyo Lee wrote:

Hi guys,
I need your help.
I'm trying to sort the data by the variable "obs".
This is how I tried to sort the data below.

The problem is, I have a variable name "obs"; this is.. a counter variable.
something like _n_ in SAS.
I do not know why it is not working.
I even tried a similar example in UCLA webpage:
http://www.ats.ucla.edu/stat/R/faq/sort.htm  :it also does not seem to work.
"*sort1.hsb2 <- hsb2[order(read) , ]"*
Do you have any idea how to deal with this problem??  Thank you so much.
-Hyo

  

colnames(ttx1)


 [1] "longitude 1"  "longitude 2"  "longitude 3"  "longitude 4"  "longitude
5"
 [6] "longitude 6"  "longitude 7"  "longitude 8"  "longitude 9"  "longitude
10"
[11] "longitude 11" "longitude 12" "longitude 13" "longitude 14" "longitude
15"
[16] "longitude 16" "longitude 17" "longitude 18" "longitude 19" "longitude
20"
[21] "longitude 21" "longitude 22" "longitude 23" "longitude 24" "longitude
25"
[26] "longitude 26" "longitude 27" "longitude 28" "longitude 29" "longitude
30"
[31] "longitude 31" "longitude 32" "longitude 33" "longitude 34" "longitude
35"
[36] "longitude 36" "longitude 37" "longitude 38" "longitude 39" "longitude
40"
[41] "longitude 41" "longitude 42" "longitude 43" "longitude 44" "longitude
45"
[46] "longitude 46" "longitude 47" "longitude 48" "longitude 49" "longitude
50"
[51] "longitude 51" "longitude 52" "longitude 53" "longitude 54" "longitude
55"
[56] "longitude 56" "longitude 57" "longitude 58" "longitude 59" "longitude
60"
[61] "longitude 61" "longitude 62" "longitude 63" "longitude 64" "longitude
65"
[66] "longitude 66" "longitude 67" "longitude 68" "longitude 69" "longitude
70"
[71] "longitude 71" "longitude 72" "obs"
  

sortedx1=ttx1[order(-obs),]


Error in order(-obs) : object 'obs' not found

[[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] How to deal with this :" object ' obs' not found.

2009-10-02 Thread P Ehlers

You don't need to attach. But you do need to mention what kind of
object ttx1 is. I had (foolishly) assumed that it was dataframe,
but I see that it's a matrix. So try this:

 ttx1[order(-ttx1[,"obs"),]

-Peter Ehlers

Hyo Lee wrote:

Ok. I just figured out what the problem was.
I had to attach() the data.
**
x1=data1[,,2]
tx1=t(x1)
*ttx1 *= cbind(tx1 , obs=1:nrow(tx1))
--> this is how ttx1 was made; and of course, in ttx1, there is a variable
called 'obs'.

I had to attach(ttx1) first before I use this: *sortedx1=ttx1[order(-obs),]*

But it seems that, I cannot attach ttx1.
*> attach(ttx1)
Error in attach(ttx1) :
  'attach' only works for lists, data frames and environments*

Of course, this is one of the ways I can do. But I just don't think I can do
it for 1916 times.
  

write.csv(ttx1,"c:/i.csv")
m=read.table("c:/i.csv", header=T, sep=",")
attach(m)
sortedx1=m[order(-obs),]


Do you know what I should do?
Thanks.

-Hyo
On Fri, Oct 2, 2009 at 8:50 PM, jim holtman  wrote:

  

It is clear that 'obs' does not exist.

On Fri, Oct 2, 2009 at 8:48 PM, Hyo Lee  wrote:


It says...

  

str(obs)


Error in str(obs) : object 'obs' not found
  

ls(obs)


Error in try(name) : object 'obs' not found
Error in as.environment(pos) : no item called "obs" on the search list

On Fri, Oct 2, 2009 at 8:26 PM, jim holtman  wrote:
  

Are you really sure you have 'obs'?  What does 'str(obs)' show?  What
about 'ls()'?

On Fri, Oct 2, 2009 at 8:19 PM, Hyo Lee  wrote:


Hi guys,
I need your help.
I'm trying to sort the data by the variable "obs".
This is how I tried to sort the data below.

The problem is, I have a variable name "obs"; this is.. a counter
variable.
something like _n_ in SAS.
I do not know why it is not working.
I even tried a similar example in UCLA webpage:
http://www.ats.ucla.edu/stat/R/faq/sort.htm  :it also does not seem
  

to


work.
"*sort1.hsb2 <- hsb2[order(read) , ]"*
Do you have any idea how to deal with this problem??  Thank you so
  

much.


-Hyo

  

colnames(ttx1)


 [1] "longitude 1"  "longitude 2"  "longitude 3"  "longitude 4"
 "longitude
5"
 [6] "longitude 6"  "longitude 7"  "longitude 8"  "longitude 9"
 "longitude
10"
[11] "longitude 11" "longitude 12" "longitude 13" "longitude 14"
"longitude
15"
[16] "longitude 16" "longitude 17" "longitude 18" "longitude 19"
"longitude
20"
[21] "longitude 21" "longitude 22" "longitude 23" "longitude 24"
"longitude
25"
[26] "longitude 26" "longitude 27" "longitude 28" "longitude 29"
"longitude
30"
[31] "longitude 31" "longitude 32" "longitude 33" "longitude 34"
"longitude
35"
[36] "longitude 36" "longitude 37" "longitude 38" "longitude 39"
"longitude
40"
[41] "longitude 41" "longitude 42" "longitude 43" "longitude 44"
"longitude
45"
[46] "longitude 46" "longitude 47" "longitude 48" "longitude 49"
"longitude
50"
[51] "longitude 51" "longitude 52" "longitude 53" "longitude 54"
"longitude
55"
[56] "longitude 56" "longitude 57" "longitude 58" "longitude 59"
"longitude
60"
[61] "longitude 61" "longitude 62" "longitude 63" "longitude 64"
"longitude
65"
[66] "longitude 66" "longitude 67" "longitude 68" "longitude 69"
"longitude
70"
[71] "longitude 71" "longitude 72" "obs"
  

sortedx1=ttx1[order(-obs),]


Error in order(-obs) : object 'obs' not found

   [[alternative HTML version deleted]]

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

  


--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

  


--
 Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




[[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] How to deal with this :" object ' obs' not found.

2009-10-02 Thread P Ehlers

Oops, missed a square bracket:

ttx1[order(-ttx1[,"obs"]),]

-Peter Ehlers

P Ehlers wrote:

You don't need to attach. But you do need to mention what kind of
object ttx1 is. I had (foolishly) assumed that it was dataframe,
but I see that it's a matrix. So try this:

 ttx1[order(-ttx1[,"obs"),]

-Peter Ehlers

Hyo Lee wrote:

Ok. I just figured out what the problem was.
I had to attach() the data.
**
x1=data1[,,2]
tx1=t(x1)
*ttx1 *= cbind(tx1 , obs=1:nrow(tx1))
--> this is how ttx1 was made; and of course, in ttx1, there is a 
variable

called 'obs'.

I had to attach(ttx1) first before I use this: 
*sortedx1=ttx1[order(-obs),]*


But it seems that, I cannot attach ttx1.
*> attach(ttx1)
Error in attach(ttx1) :
  'attach' only works for lists, data frames and environments*

Of course, this is one of the ways I can do. But I just don't think I 
can do

it for 1916 times.
 

write.csv(ttx1,"c:/i.csv")
m=read.table("c:/i.csv", header=T, sep=",")
attach(m)
sortedx1=m[order(-obs),]


Do you know what I should do?
Thanks.

-Hyo
On Fri, Oct 2, 2009 at 8:50 PM, jim holtman  wrote:

 

It is clear that 'obs' does not exist.

On Fri, Oct 2, 2009 at 8:48 PM, Hyo Lee  wrote:
   

It says...

 

str(obs)


Error in str(obs) : object 'obs' not found
 

ls(obs)


Error in try(name) : object 'obs' not found
Error in as.environment(pos) : no item called "obs" on the search list

On Fri, Oct 2, 2009 at 8:26 PM, jim holtman  
wrote:
 

Are you really sure you have 'obs'?  What does 'str(obs)' show?  What
about 'ls()'?

On Fri, Oct 2, 2009 at 8:19 PM, Hyo Lee  wrote:
   

Hi guys,
I need your help.
I'm trying to sort the data by the variable "obs".
This is how I tried to sort the data below.

The problem is, I have a variable name "obs"; this is.. a counter
variable.
something like _n_ in SAS.
I do not know why it is not working.
I even tried a similar example in UCLA webpage:
http://www.ats.ucla.edu/stat/R/faq/sort.htm  :it also does not seem
  

to
   

work.
"*sort1.hsb2 <- hsb2[order(read) , ]"*
Do you have any idea how to deal with this problem??  Thank you so
  

much.
   

-Hyo

 

colnames(ttx1)


 [1] "longitude 1"  "longitude 2"  "longitude 3"  "longitude 4"
 "longitude
5"
 [6] "longitude 6"  "longitude 7"  "longitude 8"  "longitude 9"
 "longitude
10"
[11] "longitude 11" "longitude 12" "longitude 13" "longitude 14"
"longitude
15"
[16] "longitude 16" "longitude 17" "longitude 18" "longitude 19"
"longitude
20"
[21] "longitude 21" "longitude 22" "longitude 23" "longitude 24"
"longitude
25"
[26] "longitude 26" "longitude 27" "longitude 28" "longitude 29"
"longitude
30"
[31] "longitude 31" "longitude 32" "longitude 33" "longitude 34"
"longitude
35"
[36] "longitude 36" "longitude 37" "longitude 38" "longitude 39"
"longitude
40"
[41] "longitude 41" "longitude 42" "longitude 43" "longitude 44"
"longitude
45"
[46] "longitude 46" "longitude 47" "longitude 48" "longitude 49"
"longitude
50"
[51] "longitude 51" "longitude 52" "longitude 53" "longitude 54"
"longitude
55"
[56] "longitude 56" "longitude 57" "longitude 58" "longitude 59"
"longitude
60"
[61] "longitude 61" "longitude 62" "longitude 63" "longitude 64"
"longitude
65"
[66] "longitude 66" "longitude 67" "longitude 68" "longitude 69"
"longitude
70"
[71] "longitude 71" "longitude 72" "obs"
 

sortedx1=ttx1[order(-obs),]


Error in order(-obs) : object 'obs' not found

   [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> 


and provide commented, minimal, self-contained, reproducible code.

  


--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

  


--
 Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Creating a sparse matrix from a file

2009-10-27 Thread Pallavi P
Hi Martin,

Thanks for the help. Just to make sure I understand correctly.

The below steps are for creating an example table similar to the one that I
read from file.

n <- 22638
m <- 80914
nnz <- 30 # no idea if this is realistic for you

set.seed(101)
ex <- cbind(i = sample(n,nnz, replace=TRUE),
   j = sample(m,nnz, replace=TRUE),
   x = round(100 * rnorm(nnz)))


and I can understand the way sparseMatrix is initialized right now as
M <- sparseMatrix(i = ex[,"i"],
 j = ex[,"j"],
 x = ex[,"x"])

How ever, I couldn't understand the use of below commands.
MM. <- tcrossprod(M) # == MM' := M %*% t(M)

M.1 <- M %*% rep(1, ncol(M))
stopifnot(identical(drop(M.1), rowSums(M)))

Kindly let me know if I missed something.

Thanks
Pallavi

On Tue, Oct 27, 2009 at 4:12 PM, Martin Maechler  wrote:

>
>PP> Hi all,
>
>PP> I used sparseM package for creating sparse Matrix and
>PP> followed below commands.
>
> I'd strongly recommend to use package 'Matrix'  which is part of
> every R distribution (since R 2.9.0).
>
>PP> The sequence of commands are:
>
>>> ex <- read.table('fileName',sep=',')
>>> M <- as.matrix.csr(0,22638,80914)
> >> for (i in 1:nrow(ex)) { M[ex[i,1],ex[i,2]]<-ex[i,3]}
>
> This is very slow in either 'Matrix' or 'SparseM'
> as soon as  nrow(ex)  is non-small.
>
> However, there are very efficient ways to construct the sparse
> matrix directly from your 'ex' structure:
> In 'Matrix' you should use  the  sparseMatrix() function as you
> had proposed.
>
> Here I provide a reproducible example,
> using a random 'ex':
>
>
> n <- 22638
> m <- 80914
> nnz <- 30 # no idea if this is realistic for you
>
> set.seed(101)
> ex <- cbind(i = sample(n,nnz, replace=TRUE),
>j = sample(m,nnz, replace=TRUE),
>x = round(100 * rnorm(nnz)))
>
> library(Matrix)
>
> M <- sparseMatrix(i = ex[,"i"],
>  j = ex[,"j"],
>  x = ex[,"x"])
> MM. <- tcrossprod(M) # == MM' := M %*% t(M)
>
> M.1 <- M %*% rep(1, ncol(M))
> stopifnot(identical(drop(M.1), rowSums(M)))
>
> ##   and now do other stuff with your sparse matrix M
>
>
>PP> Even after 4 hours, I can still see the above command running. But,
> I am not
>PP> sure whether it got stuck some where.
>
>PP> Also, when I initialize matrix M and try to display the values, I
> can see
>PP> something like this
>PP> [1] 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
> 2 2 2 2
>PP> 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
> 2 2 2 2
>PP> 2 2 2 2 2 2 2 2 2 2
>PP> [85] 2 2
>
>PP> And, after I stopped executing above initialize command from
> table(after 4
>PP> hours). I could see a different values.
>
>PP> Could some one kindly explain what these number are about and how
> can I test
>PP> that my command is running and not just stuck some where.
>
>PP> Also, it would be great if some one point me to a tutorial if any on
> sparse
>PP> matricies on R as I couldn't get one from internet.
>
>PP> Thanks
>PP> Pallavi
>
>
>
>PP> Pallavi Palleti wrote:
>>>
>>> Hi David,
>>>
>>> Thanks for your help. This is exactly what I want.
>>> But, I have number of rows of my matrix = 25k and columns size as
> 80k. So,
>>> when I define a matrix object, it is throwing an error saying can not
>>> allocate a vector of length (25K * 80k). I heard that, this data can
> still
>>> be loaded into R using sparseMatrix. However, I couldn't get a syntax
> for
>>> creating the same.  Could someone kindly help me in this regard.
>>>
>>> Thanks
>>> Pallavi
> >>
>>>
>>> David Winsemius wrote:
>>>>
>>>>
>>>> On Oct 26, 2009, at 5:06 AM, Pallavi Palleti wrote:
>>>>
>
> Hi all,
>
> I am new to R and learning the same. I would like to create a
> sparse
> matrix
> from an existing file whose contents are in the format
> "rowIndex,columnIndex,value"
>
> for ex:
> 1,2,14
> 2,4,15
>
> I would like to create a sparse matrix by taking the above as
> input.
> However, I couldn't find an example where the data was being read
> from a
> file. I tried searching in R tutorial and also searched for the
> same
> in web
> but in vain. Could some one kindly help me how to give the above
> format as
> input in R to create a sparse matrix.
>>>>
>>>> ex <- read.table(textConnection("1,2,14
>>>> 2,4,15") , sep=",")
>>>> ex
>>>> #  V1 V2 V3
>>>> #1  1  2 14
>>>> #2  2  4 15
>>>>
>>>> M <- Matrix(0, 20, 20)
>>>>
>>>> > M
>>>> #20 x 20 sparse Matrix of class "dsCMatrix"
>>>>
>>>> [1,] . . . . . . . . . . . . . . . . . . . .
>>>> [2,] . . . . . . . . . . . . . . . . . . . .
>>>> [3,] . . . . . . . . . . . . . . . 

Re: [R] Creating a sparse matrix from a file

2009-10-28 Thread Pallavi P
Hi Martin,

I followed your example on my set  of data. Which has non zero values in
300k positions in 22638 X 80914 sparse matrix. I am able to load data into a
field and was able to do some operations (essentially  t(m) %*% m). However,
when I tried to display the value in the resulted matrix. I am getting below
error
*
Error in asMethod(object) :
  Cholmod error 'out of memory' at file:../Core/cholmod_memory.c, line 148*

The sequence of commands I used are:

>uac=read.table('C:\\personal\\code\\data\\user_album_count.csv',sep=',' ,
header=T)
>library(Matrix)
>m<-sparseMatrix(i=uac[,"user"],j=uac[,"item"],x=uac[,"count"])
>cm<-t(m) %*% m
upto this point, I was able to run, however when I tried to display cm[1,1],
I got above error. Kindly let me know if there is anything wrong going on
here.

Thanks
Pallavi

On Tue, Oct 27, 2009 at 8:34 PM, Martin Maechler  wrote:

> >>>>> "PP" == Pallavi P 
> >>>>> on Tue, 27 Oct 2009 18:13:22 +0530 writes:
>
>PP> Hi Martin,
>PP> Thanks for the help. Just to make sure I understand correctly.
>
>PP> The below steps are for creating an example table similar to the one
> that I
>PP> read from file.
>
> yes, exactly
>
> n <- 22638
> m <- 80914
> nnz <- 30 # no idea if this is realistic for you
>
> set.seed(101)
> ex <- cbind(i = sample(n,nnz, replace=TRUE),
> j = sample(m,nnz, replace=TRUE),
> x = round(100 * rnorm(nnz)))
>
>
> PP> and I can understand the way sparseMatrix is initialized right now
> as
> M <- sparseMatrix(i = ex[,"i"],
>  j = ex[,"j"],
>  x = ex[,"x"])
>
> PP> How ever, I couldn't understand the use of below commands.
>
>   MM. <- tcrossprod(M) # == MM' := M %*% t(M)
>   M.1 <- M %*% rep(1, ncol(M))
>   stopifnot(identical(drop(M.1), rowSums(M)))
>
> They were just for illustrative purposes,
> to show how and that you can work with the created sparse matrix
> 'M'.
>
> Regards,
> Martin Maechler, ETH Zurich
>
>PP> Kindly let me know if I missed something.
>
>PP> Thanks
>PP> Pallavi
>
>

[[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] Creating a sparse matrix from a file

2009-10-28 Thread Pallavi P
Hi Martin,

Unfortunately, the error is coming on the data set that I have right now. I
was successfully able to display any field in the matrix and even the whole
matrix when I tried the example code provided by you. However, it is failing
on the dataset I am working on.I can share the file with you if that helps.
Kindly let me know.

Also, please find the sessioninfo() output below:
> sessionInfo()
R version 2.9.2 (2009-08-24)
i386-pc-mingw32

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

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

other attached packages:
[1] Matrix_0.999375-30 lattice_0.17-25

loaded via a namespace (and not attached):
[1] grid_2.9.2
>


Thanks
Pallavi


On Wed, Oct 28, 2009 at 7:22 PM, Martin Maechler  wrote:

> >>>>> "PP" == Pallavi P 
> >>>>> on Wed, 28 Oct 2009 16:30:25 +0530 writes:
>
>PP> Hi Martin,
> PP> I followed your example on my set  of data. Which has non zero
> values in
>PP> 300k positions in 22638 X 80914 sparse matrix. I am able to load
> data into a
>PP> field and was able to do some operations (essentially  t(m) %*% m).
> However,
>PP> when I tried to display the value in the resulted matrix. I am
> getting below
>PP> error
>PP> *
>PP> Error in asMethod(object) :
>PP> Cholmod error 'out of memory' at file:../Core/cholmod_memory.c, line
> 148*
>
>PP> The sequence of commands I used are:
>
>>>
> uac=read.table('C:\\personal\\code\\data\\user_album_count.csv',sep=',' ,
> PP> header=T)
> >> library(Matrix)
>>> m<-sparseMatrix(i=uac[,"user"],j=uac[,"item"],x=uac[,"count"])
>>> cm<-t(m) %*% m
>
> The above is less efficient than
>
>cm <- crossprod(m)
>
> please use the latter {not just for sparse matrices; for all
> matrices in R !}
>
>PP> upto this point, I was able to run, however when I tried to display
> cm[1,1],
>PP> I got above error. Kindly let me know if there is anything wrong
> going on
>PP> here.
>
> Interestingly, we had a recent thread on R-devel,
> which also made a point about excessive memory usage when
> accessing elements of a sparse matrix.
>
> I'd really like to investigate further;
> but can you ***PLEASE*** use reproducible code, i.e.,
> similar to the one I used, rather than reading data from one of
> your files.
>
> Note that your matrix is still fine and should be able to work
> with it, even thoug it seems the operation
>
>  a <- cm[1,1]
>
> is currently implemented very sub-optimally.
>
> I'm busy for the rest of today with other duties,
> but am looking forward to receive **reproducible** code from
> you, by tonight.
> Also, please do not forget to also show the result of
> sessionInfo() !
>
> Martin Maechler,
>
>PP> Thanks
>PP> Pallavi
>
>PP> On Tue, Oct 27, 2009 at 8:34 PM, Martin Maechler <
> maech...@stat.math.ethz.ch
> >> wrote:
>
>>> >>>>> "PP" == Pallavi P 
>>> >>>>> on Tue, 27 Oct 2009 18:13:22 +0530 writes:
>>>
>PP> Hi Martin,
>PP> Thanks for the help. Just to make sure I understand correctly.
>>>
>PP> The below steps are for creating an example table similar to the one
>>> that I
>PP> read from file.
>>>
>>> yes, exactly
>>>
>>> n <- 22638
>>> m <- 80914
>>> nnz <- 30 # no idea if this is realistic for you
>>>
>>> set.seed(101)
>>> ex <- cbind(i = sample(n,nnz, replace=TRUE),
>>> j = sample(m,nnz, replace=TRUE),
>>> x = round(100 * rnorm(nnz)))
>>>
>>>
>PP> and I can understand the way sparseMatrix is initialized right now
>>> as
>>> M <- sparseMatrix(i = ex[,"i"],
>>> j = ex[,"j"],
>>> x = ex[,"x"])
>>>
>PP> How ever, I couldn't understand the use of below commands.
>>>
>>> MM. <- tcrossprod(M) # == MM' := M %*% t(M)
>>> M.1 <- M %*% rep(1, ncol(M))
>>> stopifnot(identical(drop(M.1), rowSums(M)))
>>>
>>> They were just for illustrative purposes,
>>> to show how and that you can work with the created

Re: [R] barchart() {Lattice} help.

2009-11-26 Thread P Ehlers

As I wrote earlier:

"I had to add the rectangles= and points= arguments to

auto.key to get the same key as you had earlier."

and the relevant line in the code was:

 auto.key = list(space = 'right', rectangles=TRUE, points=FALSE)

-Peter Ehlers

Peng Cai wrote:

Hello Peter and David,

Thanks for your help. I have added what you suggested and its working
perfectly fine except:

When I add the panel function, the legend changes. In the sense without the
panel function the column names are shown with small colored rectangles (on
right), but after adding it the rectangles change to tiny un-filled
diamonds. Any suggestions?

My current code and data is below,

Thanks a lot,
Peng


Data:
  

Sample Col1 Col2 Col3
Row1 -2 4 -1
Row2 3 -2 4
Row3 3 5 -2
Row4 4 1 -1

Code:





  

dta<-read.table("data.txt", header=TRUE, row.names="Sample")
coltemp=c(619,376,497)
myYscale <- seq(-10, 10, 1)
barchart(data.matrix(dta),
   horizontal=FALSE,
   stack=TRUE,
 par.settings = simpleTheme(col = colors()[coltemp]),
   auto.key=list(space="right"),
 border=NA,
 panel=function(x,y,...){
  panel.abline(h=c(myYscale), col.line="gray")
  panel.barchart(x,y,...)
   },
 scales = list(y = list(at = myYscale))
)












Thanks,
  

Peng


On Thu, Nov 26, 2009 at 7:23 PM, Peng Cai wrote:



Hi Again,

Before I start getting into what you just suggested, let me confirm if I
made my point clear previously. I'm looking for horizontal lines similar to
one on the following link (It has parallel lines for each y=200, y=400,...):

http://pfiles.5min.com/images/176735/176734313.jpg

What you just suggested can solve this purpose? Thanks,

Peng


On Thu, Nov 26, 2009 at 7:09 PM, Peter Ehlers  wrote:

  

Peng Cai wrote:



Thanks David, I tried panel.abline(h=somevalue) -- both inside and
outside
of barchart() function but its not working. Any suggestions?

Peng

  

Here's some code related to the data you posted earlier.


barchart(data.matrix(dta), horizontal = FALSE, stack = TRUE,
par.settings = simpleTheme(col = 2:4),
panel=function(x,y,...){
  panel.abline(h=c(-2,0,3,4), col.line="gray")
  panel.barchart(x,y,...)

},
scales = list(y = list(at = -2:8)),
auto.key = list(space = 'right', rectangles=TRUE,
points=FALSE)
)

If you want the gray lines in front of the bars, switch the
order of the panel functions. With lattice, it's all about
what goes into each panel (you have only one panel here).
If you want more than one thing in a panel, you have to set
up a function to do those things.

I had to add the rectangles= and points= arguments to
auto.key to get the same key as you had earlier.

 -Peter Ehlers





On Thu, Nov 26, 2009 at 6:42 PM, David Winsemius <
dwinsem...@comcast.net>wrote:

 On Nov 26, 2009, at 6:12 PM, Peng Cai wrote:
  

 Thanks a lot Peter! One more help, is there a similar function
abline()



for
barchart().

 ?panel.abline
  


 I'm trying to add a (light gray colored) horizontal lines, one for


each
y-value.

Peng

On Thu, Nov 26, 2009 at 5:59 PM, Peter Ehlers 
wrote:

 Peng Cai wrote:

  

 Hi Peter,



I'm not sure but it seems "scales" command works only with integer
values.

If the y-axis values are very small (such as -0.03, -0.02, -0.01, 0,
0.01,..., 0.08). My current plot has values 0, 0.05, and 0.10 only.
But
I
need it to extend it to negative numbers and reduce the scale width
(like
-0.04, -0.02, 0, 0.02,...).

Can I change these too? Thanks!


 Use, e.g.
  

myYscale <- seq(-0.04, 0.08, 0.02)
barchart(...,
 ...,
 scales = list(y = list(at = myYscale)),
 ...
)

-Peter Ehlers



 Peng



On Thu, Nov 26, 2009 at 3:18 PM, Peter Ehlers 
wrote:


 Peng Cai wrote:

  

Hi R Users,

 I'm trying to plot a stacked barplot. Here is data:


Sample Col1 Col2 Col3
Row1 -2 4 -1
Row2 3 -2 4
Row3 3 5 -2
Row4 4 1 -1

I'm using following R code:

library(lattice)
dta<-read.table("data.txt", header=TRUE, row.names="Sample")
barchart(data.matrix(dta),
   horizontal=FALSE,
   stack=TRUE,
col=2:4,
   auto.key=list(space="right",
title=names(dimnames(dta))[2])
)

Above code is working fine, but I need help with:

1) Legend boxes have default colors, whereas I'm looking them to
match
with
barplot colors (col=2:4).

replace the line

 col = 2:4,
  

with

par.settings = simpleTheme(col = 2:4),


2) Can I increase scale for y axis, like currently it plotting

 -2,0,2,4,...



I would like it as -2,-1,0,1,...

add the line

 scales = list(y = list(at = -2:8)),
  

or whatever tick locations you prefer.

-Peter Ehlers


Any help would be greatly appreciated,

 Thanks,


Peng

   [[alternative HTML version deleted]]

___

Re: [R] categorical vs numerical

2009-12-04 Thread P Ehlers

If your group sizes are not too large, I would use jittered stripcharts.
They're more informative than boxplots and much less subject to
misinterpretation. One warning, I'm not fond of the default pch=0.

-Peter Ehlers

DispersionMap wrote:

What ways are there to plot categorical vs numerical data in R.


I have two columns: one with categorical data in 5 categories a,b,c,d,e, and
a numerical column with integers between 1 and 100.

I have used a boxplot with a,b,c,d,e on the x-axis and an increasing
numerical scale on the y-axis. This look fine but im looking for other ways
to present the data.


What other ways can i do this???



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


[R] Finding root using Newton's method

2009-05-13 Thread Harry P

I want generate R code to determine the real root of the polynomial
x^3-2*x^2+3*x-5. Using an initial guess of 1 with Newton's method.
Help please...
-- 
View this message in context: 
http://www.nabble.com/Finding-root-using-Newton%27s-method-tp23534519p23534519.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] plotting a chisquare

2009-05-17 Thread Harry P

Dear R-users,
I have a problem in making a chi-square density function curve.
I have sth like curve(dchisq(x, df))
from help, x is vector of quantiles, df is the degree of freedom.
I do not understand what vector of quantiles is, what do I need to put in?
Thanks!
-- 
View this message in context: 
http://www.nabble.com/plotting-a-chisquare-tp23585369p23585369.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] Convert factor to "double"?

2009-04-03 Thread p . silva
Hi!

I'm reading a tab-seperated CVS file with:
test1 <- read.table("data.txt", header=TRUE)

It's in the following format:

Date_Time qK qL vL vP  ...
0 30 22 110 88 ...
...

(BTW: It seems to me R shifts the column descriptions by one.)

Anyway, I would like to Fourier-transform one column. So I say:
> fft(test1$vP)
Error in levels(x)[x] : invalid subscript type 'complex'

I guess this is some typing error but I don't know which function I have to use 
for conversion.

Some more Info about the data:

> test1$vP[1:10]
 [1] 110 108 116 118 114 120 117 111 95  118
166 Levels: - 0 1 10 100 101 102 103 104 105 106 107 108 109 11 110 111 ... 99

> class( test1$vPkw)
[1] "factor"


I would appreciate any hints! Thanks in advance!

Best, Philip
--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Convert factor to "double"?

2009-04-04 Thread p . silva
> 
> > Anyway, I would like to Fourier-transform one column. So I say:
> >> fft(test1$vP)
> > Error in levels(x)[x] : invalid subscript type 'complex'

> >> test1$vP[1:10]
> >  [1] 110 108 116 118 114 120 117 111 95  118
> > 166 Levels: - 0 1 10 100 101 102 103 104 105 106 107 108 109 11 110 111
> ... 99
> 
> 
> Obviously there is some "-" sign in your data file. You might want to 
> fix that prior to importing the data. You cannot convert easily to 
> numeric with artifacts like the string "-" in your data.
> 
> Uwe Ligges

Thanks a lot! This works now!

Philip Silva
--

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


Re: [R] Log analysis with R

2013-01-04 Thread P Ehlers

In Canada we use sawmills to process logs. Or we carve
them into totem poles. Or we carve dugout canoes.
Of course, sometimes we burn them in order to keep warm.

Peter Ehlers

On 2013-01-04 10:50, peter dalgaard wrote:


On Jan 4, 2013, at 18:41 , jim holtman wrote:


what type of logs are you trying to process?


Oregon pine?


what is their format?


Cylindrical?


what information do you want from them?


Tensile strength?


;-)

(Or: Base-10, 5-digit mantissa, geometric mean)


On Fri, Jan 4, 2013 at 6:33 AM, Ramprakash Ramamoorthy
 wrote:

Hello all,

  Need some suggestions on interesting use cases with R in the
field of log processing. Any help would be greatly appreciated.

--
With Thanks and Regards,
Ramprakash Ramamoorthy,
India,
+91 9626975420

[[alternative HTML version deleted]]

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




--
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] an apply question

2013-01-18 Thread m p
Hello,
It should be easu but I cannot figure out how to use apply function. I am
trying to replace negative values in an array with these values + 24.
Would appreciate help. Thanks,
Mark

shours <- apply(fhours, function(x){if (x < 0) x <- x+24})
Error in match.fun(FUN) : argument "FUN" is missing, with no default

[[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] Mistake in German Error message for friedman.test

2013-04-09 Thread P Ehlers



On 2013-04-09 7:35, kais...@med.uni-duesseldorf.de wrote:



There are two misspellings in the german Error message for friedman test:

Fehler in friedman.test.default(cont$score, group = cont$goup, blocks = 
cont$cont) :
   y, Gruppen und blöcke müssen die sekbe Länge haben

The correct spelling would be:

Fehler in friedman.test.default(cont$score, group = cont$goup, blocks = 
cont$cont) :
   y, Gruppen und *Blöcke* müssen die *selbe* Länge haben


Instead of "die selbe", it could be "dieselbe" or "die gleiche".


I believe that "die gleiche" would be most precise.

Peter Ehlers



Thanks
W. Kaisers



[[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] Raster comparrison

2013-05-09 Thread p m
Dear all,

I'm looking for a test to identify significant differences
(p-value) between 2 raster maps.

Can you suggest me a way to solve this problem?


Thank you in advance.

Paul

[[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] LASSO covTest doesn't work when used inside a function

2014-04-22 Thread Brad P
Hello,
I have stumbled across a peculiar problem.  I am writing code for a
simulation, and would like to package it into a function that completes one
iteration.  I'm using covTest sig. tests for LASSO (link is below to info
and the source code).  When this function is used within a function (F.1
below) it only works when n=15, and the results do not make sense (Part 1
below).  When used outside of the function, it works fine with any n and
the results makes sense (Part 2 below).  Can someone please look at this
and see if you can make sense of what is going on.  I am dumbfounded as to
why this is acting weird inside the function.

Please note, the package "covTest" link found here should be in your WD:
http://andrewgelman.com/2013/03/18/tibshirani-announces-new-research-result-a-significance-test-for-the-lasso/

Thank you.
BS


rm(list=ls()) # note: remove all
# Part 1:
F.1 <- function(n){

require("lars")
require("mvtnorm")
source("covTest/R/funcs.R")

# Simulated Data
##
X <- mvrnorm(n, mu=c(0, 0, 0), Sigma=diag(3))
b1 =2; b2 = 0.0; b3 = - 2
Y <- as.vector(X[,1]*b1 +X[,2]*b2 +X[,3]*b3  + rnorm(n, 0, 0.05) )

fit2 <- lars(as.matrix(X), Y, type="lasso", max.steps=100)
res <- covTest(fitobj=fit2, x=as.matrix(X), y=as.vector(Y)) # package
folder must be in WD
res <- res$results[order(res$results[,1]),3]
lasso <- c(fit2$beta[names(fit2$Cp[which.min(fit2$Cp)]),], res)
names(lasso)[4:6] <- c("X1.pval", "X2.pval", "X3.pval")
return(lasso)
# for output
#
}
# function end

# now use F.1 in a loop...
it = 3
out <- vector("list")
for(i in 1:it){
out[[i]] <- F.1(15) # this will only work for n=15, and p-values cannot be
close to correct
}
##
out



rm(list=ls()) # note: remove all
# Part 2:
##
require("lars")
require("mvtnorm")
source("covTest/R/funcs.R")

it = 3
n= 30 # here n can be anything, and the results make sense

out <- vector("list")
for(i in 1:it){

X <- mvrnorm(n, mu=c(0, 0, 0), Sigma=diag(3))
b1 =2; b2 = 0.0; b3 = - 2
Y <- as.vector(X[,1]*b1 +X[,2]*b2 +X[,3]*b3  + rnorm(n, 0, 0.05) )

fit2 <- lars(as.matrix(X), Y, type="lasso", max.steps=100)
res <- covTest(fitobj=fit2, x=as.matrix(X), y=as.vector(Y)) # package
folder must be in WD
res <- res$results[order(res$results[,1]),3]
lasso <- c(fit2$beta[names(fit2$Cp[which.min(fit2$Cp)]),], res)
names(lasso)[4:6] <- c("X1.pval", "X2.pval", "X3.pval")
# for output
#
out[[i]] <- lasso
}
##
out

[[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] subsetting time series

2012-12-13 Thread m p
Hello,
my series of dates look like

  [1] "2012-05-30 18:30:00 UTC" "2012-05-30 19:30:00 UTC"
  [3] "2012-05-30 20:30:00 UTC" "2012-05-30 21:30:00 UTC"
  [5] "2012-05-30 22:30:00 UTC" "2012-05-30 23:30:00 UTC"
  [7] "2012-05-31 00:30:00 UTC" "2012-05-31 01:30:00 UTC"
  [9] "2012-05-31 02:30:00 UTC" "2012-05-31 00:30:00 UTC"
 [11] "2012-05-31 01:30:00 UTC" "2012-05-31 02:30:00 UTC"
 [13] "2012-05-31 03:30:00 UTC" "2012-05-31 04:30:00 UTC"
 [15] "2012-05-31 05:30:00 UTC" "2012-05-31 06:30:00 UTC"
 [17] "2012-05-31 07:30:00 UTC" "2012-05-31 08:30:00 UTC"
 [19] "2012-05-31 06:30:00 UTC" "2012-05-31 07:30:00 UTC"
...

I'd like to subset this to four series

1)
  [1] "2012-05-30 18:30:00 UTC" "2012-05-30 19:30:00 UTC"
  [3] "2012-05-30 20:30:00 UTC" "2012-05-30 21:30:00 UTC"
  [5] "2012-05-30 22:30:00 UTC" "2012-05-30 23:30:00 UTC"
  [7] "2012-05-31 00:30:00 UTC" "2012-05-31 01:30:00 UTC"
  [9] "2012-05-31 02:30:00 UTC"

 [10] "2012-05-31 18:30:00 UTC" "2012-05-31 19:30:00 UTC"
...

2)
"2012-05-31 00:30:00 UTC"
-> [1]
 [11] "2012-05-31 01:30:00 UTC" "2012-05-31 02:30:00 UTC" -> [2,3]
 [13] "2012-05-31 03:30:00 UTC" "2012-05-31 04:30:00 UTC"
 [15] "2012-05-31 05:30:00 UTC" "2012-05-31 06:30:00 UTC"
 [17] "2012-05-31 07:30:00 UTC" "2012-05-31 08:30:00 UTC"

 [10] "2012-06-01 00:30:00 UTC"


3)
 [19] "2012-05-31 06:30:00 UTC" "2012-05-31 07:30:00 UTC"
...

so that I can plot data for each of the series separately without e.g. data
at hour  "2012-05-31 02:30:00 UTC"  connecting in the figure to "2012-05-31
00:30:00 UTC"

Basically, cycling through the series with period 9

Thanks for any suggestions/help,
thanks,

Mark

[[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] subsetting time series

2012-12-13 Thread m p
Thats works perfectly, thanks a lot,
Mark

On Thu, Dec 13, 2012 at 11:34 AM, arun  wrote:

> Hi,
> Try this:
> seq1<-seq(from=as.POSIXct("2012-05-30
> 18:30:00",tz="UTC"),to=as.POSIXct("2012-05-31 02:30:00",tz="UTC"),by="1
> hour")
> seq2<-seq(from=as.POSIXct("2012-05-31
> 00:30:00",tz="UTC"),to=as.POSIXct("2012-05-31 08:30:00",tz="UTC"),by="1
> hour")
> seq3<-seq(from=as.POSIXct("2012-05-31
> 06:30:00",tz="UTC"),to=as.POSIXct("2012-05-31 07:30:00",tz="UTC"),by="1
> hour")
> Sys.setenv(TZ="UTC")
>  Series1<-c(seq1,seq2,seq3)
>  split(Series1,rep(1:3,each=9))
> #or individually if it is a small dataset
> Series1[1:9]
> Series1[10:18]
> etc.
>

[[alternative HTML version deleted]]

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


[R] How to convert .dot file to gml file in R

2014-01-12 Thread vasanthi P
I have very basic knowledge in R. Kindly help me to convert dot file to gml
file. Can u suggest me some datasets of social networks consists of edge
weight and edge timestamp.

Thanks and regards,
Vasanthi P.

[[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] PLS1 NIPALS question: error with chemometrics package?

2013-09-22 Thread Brad P
I am doing a self study, trying to understand PLS.
I have run across the following and hope that someone here can clarify as
to what is going on.

These are the data from Wold et al. (1984)

dat <- structure(list(t = 1:15, y = c(4.39, 4.42, 5, 5.85, 4.35, 4.51,
6.33, 6.37, 4.68, 5.04, 7.1, 5.04, 6, 5.48, 7.1), x1 = c(4.55,
4.74, 5.07, 5.77, 4.62, 4.41, 6.17, 6.17, 4.33, 4.62, 7.22, 4.64,
5.62, 6.19, 7.85), x2 = c(8.93, 8.93, 9.29, 9.9, 9.9, 9.93, 9.19,
9.19, 10.03, 10.29, 9.29, 10.22, 9.94, 9.77, 9.29), x3 = c(1.14,
1.14, 1.14, 1.14, 1.14, 1.14, 1.14, 1.14, 1.14, 1.14, 1.14, 1.14,
-0.07, -0.07, -0.07), x4 = c(0.7, 1.23, 0.19, 0.19, 1.23, 1.23,
0.19, 0.19, 0.19, 0.19, 0.19, 0.19, 0.19, 0.19, 0.19), x5 = c(0.19,
0.19, 0.7, 1.64, 1.64, 2.35, 2.83, 2.56, 2.42, 3.36, 2.43, 2.95,
1.64, 1.64, 3.8), x6 = c(0.49, 0.49, 0, -0.1, -0.1, -0.2, -0.13,
-0.13, -0.08, -0.13, -0.3, -0.08, -0.19, -0.19, -0.3), x7 = c(1.24,
1.24, 0, -0.47, -0.47, -0.51, -0.93, -0.93, -0.38, -0.93, -1.6,
-0.38, -0.47, -0.47, -1.6), x8 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 0L, 0L, 1L, 0L, 1L, 1L, 1L)), .Names = c("t", "y", "x1",
"x2", "x3", "x4", "x5", "x6", "x7", "x8"), class = "data.frame", row.names
= c(NA,
-15L))
In Wold et al. (1984) (pg 741, Table 2) beta coefficients are given for PLS
(1) and PLS (2) where (1) and (2) correspond to the number of PLS
components retained. The coefficients are not the same as those when I run
the following:

library("chemometrics")

# retaining 1 component:
pls1_nipals(X=dat[,c(3:10)], y=dat[2], a=1, scale=TRUE)$b

# retaining 2 components:
pls1_nipals(X=dat[,c(3:10)], y=dat[2], a=2, scale=TRUE)$b


However, if I modify the source code like this:

 pls1_nipals_mod <- function(X, y, a, it = 50, tol = 1e-08, scale = FALSE)
{
    Xh <- scale(X, center = TRUE, scale = scale)
yh <- scale(y, center = TRUE, scale = scale)
T <- NULL
P <- NULL
C <- NULL
W <- NULL
for (h in 1:a) {
wh <- t(Xh) %*% yh/sum(yh^2)  # modified: / SS
wh <- wh/as.vector(sqrt(t(wh) %*% wh))
th <- Xh %*% wh
ch <- as.numeric(t(yh) %*% th)/sum(th^2)  # modified: / SS
# ch <- ch/as.vector(sqrt(t(th) %*% th))   # modified: removed
normalization of ch
    ph <- t(Xh) %*% th/as.vector(t(th) %*% th)
Xh <- Xh - th %*% t(ph)
yh <- yh - th * ch
T <- cbind(T, th)
P <- cbind(P, ph)
C <- c(C, ch)
W <- cbind(W, wh)
}
b <- W %*% solve(t(P) %*% W) %*% C
list(P = P, T = T, W = W, C = C, b = b)
}

pls1_nipals_mod(X=dat[,c(3:10)], y=dat[2], a=1, scale=TRUE)$b
pls1_nipals_mod(X=dat[,c(3:10)], y=dat[2], a=2, scale=TRUE)$b

These beta coefficients are exactly the same as in Wold et al. (1984)


Furthermore, if I do a leave-one-out CV, my modified version has a PRESS =
1.27, whereas the original pls1_nipals() function has a PRESS = 18.11!

That's not good, right? Here is my LOOCV code, 1:1 lines added in plots:

### LOOCV for original function
out.j <- vector("list", length=nrow(dat))
for(j in c(2:nrow(dat), 1)){
b <- pls1_nipals(X=dat[-j,c(3:10)], y=dat[-j,2], a=2, scale=TRUE)$b
dats <- scale(dat)
y.est <- dats[j,c(3:10)] %*% b
y.obs <- dats[j,2]
out.j[[j]] <- data.frame(y.obs, y.est)
}
out <- do.call(rbind, out.j)
sqrt(sum((out[,1]-out[,2])^2) )
plot(out[,2]~ out[,1], ylab="pred", xlab="obs")
abline(0,1, col="grey")

### LOOCV for modified function
out.j <- vector("list", length=nrow(dat))
for(j in c(2:nrow(dat), 1)){
b <- pls1_nipals_mod(X=dat[-j,c(3:10)], y=dat[-j,2], a=2, scale=TRUE)$b
dats <- scale(dat)
y.est <- dats[j,c(3:10)] %*% b
y.obs <- dats[j,2]
out.j[[j]] <- data.frame(y.obs, y.est)
}
out <- do.call(rbind, out.j)
sqrt(sum((out[,1]-out[,2])^2) )
plot(out[,2]~ out[,1], ylab="pred", xlab="obs")
abline(0,1, col="grey")


Is this an error with the chemometrics function; or am I simply
understanding something incorrectly?
Thank you.


Citation: Wold, S., A. Ruhe, H. Wold, W. Dunn. (1984) The collinearity
problem in linear regression. The partial least squares (PLS) approach to
generalized inverses*" SIAM J. Sci. Stat. Comput.

[[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] Merging nested lists

2010-10-27 Thread Alex P.
Hello All,

I have multiple "list of lists" in the form of 

Mylist1[[N]][[K]]$Name_i, 

with N=1..6, K=1..3, and i=1..7. Each Name_i is a matrix. I have 30 of these 
objects Mylist1, Mylist2, ... 

I would like to merge these lists by each Name_i using rbind, but I couldn't 
figure out how to do it. What I want at the end is a single "list of lists", 
again in the form of Mylist[[N]][[K]]$Name_i. Manually doing it is not feasible 
given the large number of Mylist objects. 

Thanks in advance,

Alex

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] is this matrix symmetric

2010-11-07 Thread P Ehlers

Jun Shen wrote:

Hi,

I have this symmetric matrix, at least I think so.

 col1  col2  col3
[1,] 0.20 0.05 0.06
[2,] 0.05 0.10 0.03
[3,] 0.06 0.03 0.08

or

structure(c(0.2, 0.05, 0.06, 0.05, 0.1, 0.03, 0.06, 0.03, 0.08
), .Dim = c(3L, 3L), .Dimnames = list(NULL, c("var1", "var2",
"var3")))

But isSymmetric() doesn't agree. Any comment? I am on R 2.10.1 Thanks.

Jun



Did you check the help page? See under Details about
rownames and colnames.

  -Peter Ehlers

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Integrate and mapply

2010-11-07 Thread Vaiva P
Hi,

I need some help on integrating a function that is a vector.
I have a function - vector which each element is different. And,
naturally, function integrate() does not work
I checked the article of U. Ligges and J. Fox (2008) about code
optimization "How Can I Avoid This Loop or Make It Faster?" on
http://promberger.info/files/rnews-vectorvsloops2008.pdf.
Their advice did not help me, because they advised a solution, when
function was the same, but limits of the integral were  vectors. I
have got everything other way around. I could not get any result.
I would be very grateful for an advice on this matter.
The code is below. The function needed to be integrated (undint with
respect to u from 0 to Inf).

Sincerely,
V.

Code

rm=list(ls())

#index matrix
t1<-c(1:15)
t2<-c(1:5)%x%matrix(1,3,1)
t3<-matrix(1,3,1)%x%c(1:5)
t4<-c(1:3)%x%matrix(1,5,1)
comb<-cbind(t1,t2,t3,t4)

nu<-rchisq(15,4)

gam<-matrix(rchisq(75,df=5),15,5)

undint<-function(u){
prob<-function(i) {
i1<-comb[i,1]
i2<-comb[i,2]
i3<-comb[i,3]
i4<-comb[i,4]

val1<-gam[((i3-1)*2+1):(i3*2),i4]
vc1<-matrix(12,length(val1),1)-matrix(u,length(val1),1)-val1
distr1<-prod(pchisq(vc1,df=2))

p10<-distr1*1/(exp(-nu[i1])*(1+gam[i2,i4]))*(1-plogis((u+log(gam[i3,i4])-log(1+gam[i2,i4])),0,1))
p10
}
val<-c(1:15)
q<-sapply(val,prob)
}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] unknown dimensions for loglm

2010-11-08 Thread P Ehlers

Jason Hwa wrote:

Dear R-help community,

I am working with multidimensional contingency tables and I am having 
trouble getting loglm to run on all dimensions without typing out each 
dimension.


I have generated random data and provided output for the results I want 
below:


d1.c1 <- rnorm(20, .10, .02)
d1.c2 <- rnorm(20, .10, .02)
d2.c1 <- rnorm(20, .09, .02)
d2.c2 <- rnorm(20, .09, .02)
d3.c1 <- rnorm(20, .11, .02)
d3.c2 <- rnorm(20, .11, .02)

group1 <- cbind(1, d1.c1, d2.c1, d3.c1)
group2 <- cbind(2, d1.c2, d2.c2, d3.c2)

colnames(group1) <- colnames(group2) <- c("group", "dim1", "dim2", "dim3")
combined <- rbind(group1, group2)
combined[,2:4] <- combined[,2:4] > .1

ctables <- xtabs(~., data = combined)
loglm(~group+dim1+dim2+dim3, data=ctables)

Call:
loglm(formula = ~group + dim1 + dim2 + dim3, data = ctables)

Statistics:
   X^2 df  P(> X^2)
Likelihood Ratio 12.29856 11 0.3416253
Pearson  10.28058 11 0.5053391

However, the number and the names of the dimensions change for each 
dataset. What I want is to be able to run the following line at the end 
of the code: "loglm(~., data=ctables)", but it always prints the 
following error:


Error in terms.formula(formula <- denumerate(formula)) :
   '.' in formula and no 'data' argument

Can anyone help me out?

Thank you,
Jason


Presumably you're using loglm from package MASS (which you
should indicate).

To use the dot notation, you need to put your data in
dataframe form. This works:

 d <- data.frame(ftable(ctables))
 loglm(Freq ~ ., data = d)

Or you could use the integer notation for the formula:

 loglm( ~ 1 + 2 + 3 + 4, data = ctables)

You could generate the formula in your code:

 form <- as.formula(paste("~", paste(1:4, collapse="+")))

and then use

 loglm(form, data = ctables)


   -Peter Ehlers

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Create Matrix of 2 Dim from two vectors

2010-11-08 Thread Vaiva P
Try
 x1<-matrix(1,3,1)%x%x
 y1<-y%x%matrix(1,3,1)

Z<-cbind(x1,y1)
And later you need to move towards list and matrix


On Mon, Nov 8, 2010 at 11:15 AM, abotaha  wrote:
>
> Hello,
>
> I have two data.
>
> x<-c(1, 2, 3)
> y<-c(4,5,6)
>
> How do i create matrix of 3 by 3 from this two, such that
>
>  (1,4)  (1,5)  (1,6)
>  (2,4)  (2,5)  (2,6)
>  (3,4)  (3,5)  (3,6)
>
> I tried some thing like this:
>
> xy <- as.data.frame(c(0,0,0), dim=c(3,3))
> for(i in 1:3)
> for(j in 1:3)
> xy[i][j]<-c(x[i],y[j])
>
> but i got errors..
> any help would appreciate
>
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Create-Matrix-of-2-Dim-from-two-vectors-tp3031718p3031718.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] plot options including formatting axes

2010-11-12 Thread P Ehlers

Jannis wrote:

Hi Sachin,

please read the posting guide and include a reproducible example of what 
you want to do.


For your first question you should have a look at ?axis. Supplying the 
'at' argument with the positions of the desired marks and the 'labels' 
with text strings like '10.000$' should do what you want. There may be 
easier ways though...


The second problem should be solved with adding your xlab and ylab 
arguments to the call of plot() and not to title().



HTH
Jannis



A couple more ideas:
1. use ann = FALSE in your plot call to omit labels
   and then add them with title(); see ?plot.default

2. use options(scipen = 3) to avoid the exponential
   format; then use format(y, big.mark = ",") to
   format your y-axis values.

  -Peter Ehlers


sachinthaka.abeyward...@allianz.com.au schrieb:

Hi All,

Currently my plot shows the y-axis in scientific notation (1e07 and so on).
I want to be able to display this in dollars such that it shows $10,000,000
(including the commas). How do I do this.

Also with the xlabel and ylabel. I've specified: 'title('Cash vs
Time',xlab='Period',ylab=''); Im hoping that this will also not display
anything on the y-axis. Instead it is actually overwriting the default
x-label and the default y-label remains the same.

Is there something I was supposed to do. I thought by specifying the 'xlab'
option in title it gets rid of the default one.

Thanks,
Sachin

--- Please consider the environment before printing this email --- 


Allianz - Best General Insurance Company of the Year 2010*
Allianz - General Insurance Company of the Year 2009+ 


* Australian Banking and Finance Insurance Awards
+ Australia and New Zealand Insurance Industry Awards 


This email and any attachments has been sent by Allianz Australia Insurance 
Limited (ABN 15 000 122 850) and is intended solely for the addressee. It is 
confidential, may contain personal information and may be subject to legal 
professional privilege. Unauthorised use is strictly prohibited and may be 
unlawful. If you have received this by mistake, confidentiality and any legal 
privilege are not waived or lost and we ask that you contact the sender and 
delete and destroy this and any other copies. In relation to any legal use you 
may make of the contents of this email, you must ensure that you comply with 
the Privacy Act (Cth) 1988 and you should note that the contents may be subject 
to copyright and therefore may not be reproduced, communicated or adapted 
without the express consent of the owner of the copyright.
Allianz will not be liable in connection with any data corruption, 
interruption, delay, computer virus or unauthorised access or amendment to the 
contents of this email. If this email is a commercial electronic message and 
you would prefer not to receive further commercial electronic messages from 
Allianz, please forward a copy of this email to unsubscr...@allianz.com.au with 
the word unsubscribe in the subject header.

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




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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 package 'np' problems

2010-11-15 Thread P Ehlers

Chris Carleton wrote:

Hi List,

I'm trying to get a density estimate for a point of interest from an npudens
object created for a sample of points. I'm working with 4 variables in total
(3 continuous and 1 unordered discrete - the discrete variable is the
character column in training.csv). When I try to evaluate the density for a
point that was not used in the training dataset, and when I extract the
fitted values from the npudens object itself, I'm getting values that are
much greater than 1 in some cases, which, if I understand correctly,
shouldn't be possible considering a pdf estimate can only be between 0 and
1. I think I must be doing something wrong, but I can't see it. Attached
I've included the training data (training.csv) and the point of interest
(origin.csv); below I've included the code I'm using and the results I'm
getting. I also don't understand why, when trying to evaluate the npudens
object at one point, I'm receiving the same set of fitted values from the
npudens object with the predict() function. It should be noted that I'm
indexing the dataframe of training data in order to get samples of the df
for density estimation (the samples are from different geographic locations
measured on the same set of variables; hence my use of sub-setting by [i]
and removing columns from the df before running the density estimation).
Moreover, in the example I'm providing here, the point of interest does
happen to come from the training dataset, but I'm receiving the same results
when I compare the point of interest to samples of which it is not a part
(density estimates that are either extremely small, which is acceptable, or
much greater than one, which doesn't seem right to me). Any thoughts would
be greatly appreciated,

Chris



I haven't looked at this in any detail, but why do say that pdf values
cannot exceed 1? That's certainly not true in general.

  -Peter Ehlers


fitted(npudens(tdat=training_df[training_cols_select][training_df$cat ==

i,]))

[1] 7.762187e+18 9.385532e+18 6.514318e+18 7.583486e+18 6.283017e+18
 [6] 6.167344e+18 9.820551e+18 7.952821e+18 7.882741e+18 1.744266e+19
[11] 6.653258e+18 8.704722e+18 8.631365e+18 1.876052e+19 1.995445e+19
[16] 2.323802e+19 1.203780e+19 8.493055e+18 8.485279e+18 1.722033e+19
[21] 2.227207e+19 2.177740e+19 2.168679e+19 9.329572e+18 9.380505e+18
[26] 1.023311e+19 2.109676e+19 7.903112e+18 7.935457e+18 8.91e+18
[31] 8.899827e+18 6.265440e+18 6.204720e+18 6.276559e+18 6.218002e+18


npu_dens <- npudens(tdat=training_df[training_cols_select][training_df$cat

== i,])

summary(npu_dens)


Density Data: 35 training points, in 4 variable(s)
  aster_srtm_aspect aster_srtm_dem_filled aster_srtm_slope
Bandwidth(s):  29.22422  2.500559e-24 3.111467
  class_unsup_pc_iso
Bandwidth(s):  0.2304616

Bandwidth Type: Fixed
Log Likelihood: 1531.598

Continuous Kernel Type: Second-Order Gaussian
No. Continuous Vars.: 3

Unordered Categorical Kernel Type: Aitchison and Aitken
No. Unordered Categorical Vars.: 1


predict(npu_dens,newdata=origin[training_cols_select]))


[1] 7.762187e+18 9.385532e+18 6.514318e+18 7.583486e+18 6.283017e+18
 [6] 6.167344e+18 9.820551e+18 7.952821e+18 7.882741e+18 1.744266e+19
[11] 6.653258e+18 8.704722e+18 8.631365e+18 1.876052e+19 1.995445e+19
[16] 2.323802e+19 1.203780e+19 8.493055e+18 8.485279e+18 1.722033e+19
[21] 2.227207e+19 2.177740e+19 2.168679e+19 9.329572e+18 9.380505e+18
[26] 1.023311e+19 2.109676e+19 7.903112e+18 7.935457e+18 8.91e+18
[31] 8.899827e+18 6.265440e+18 6.204720e+18 6.276559e+18 6.218002e+18


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] cannot see the y-labels (getting cut-off)

2010-11-15 Thread P Ehlers

jim holtman wrote:

increase the margins on the plot:


par(mar=c(4,7,2,1))
plot(1:5,y,ylab='',yaxt='n' );
axis(2, at=y, labels=formatC(y,big.mark=",",format="fg"),las=2,cex=0.1);



That's what I would do, but if you want to see how cex works,
use cex.axis=0.5. Check out ?par.

  -Peter Ehlers



On Sun, Nov 14, 2010 at 6:03 PM,
 wrote:

Hi All,

When I run the following code, I cannot see the entire number. As opposed
to seeing 1,000,000,000. I only see 000,000 because the rest is cut off.

The cex option doesn't seem to be doing anything at all.

y<-seq(1e09,5e09,1e09);
plot(1:5,y,ylab='',yaxt='n' );
axis(2, at=y, labels=formatC(y,big.mark=",",format="fg"),las=2,cex=0.1);

Any thoughts?

Thanks,
Sachin
p.s. sorry about corporate notice.

--- Please consider the environment before printing this email ---

Allianz - Best General Insurance Company of the Year 2010*
Allianz - General Insurance Company of the Year 2009+

* Australian Banking and Finance Insurance Awards
+ Australia and New Zealand Insurance Industry Awards

This email and any attachments has been sent by Allianz ...{{dropped:3}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Version 2.12.0 exe file

2010-11-15 Thread P Ehlers

Morris Anglin wrote:
I have R version 2.9.1 on my computer and the anlaysis is not working 
because I need to update to R version 2.12.0 the latest release. 

The person incharge of IT tried to download R version 2.12.0  but .exe file referenced in install isn't 
there -What might we be doing wrong?  We have downloaded as tar.gz, 
uncompress then look for .exe file but not present.


(It's a good idea to state your OS.)
Anyway, assuming that you got your download from your favourite
CRAN repository, you may have missed these two sentences:

 "The sources have to be compiled before you can use them. If you do 
not know what this means, you probably do not want to do it!"


Pre-compiled versions are available at CRAN.

  -Peter Ehlers



Many thanks,

Morris

Morris A. Anglin
Doctoral candidate
Institute of Health and Society
Newcastle University
Baddiley-Clark Building 
Richardson Road

NE2 4AX
UK

Direct line at Newcastle University:
+44 (0)191 222 8899
Direct line at Freeman Hospital: 
Tel: +44 (0) 191 233 6161 ext 26727

Mobile: +44 (0)07976206103
Email:morris.ang...@ncl.ac.uk
Email:morris.ang...@nuth.nhs.uk
http://www.ncl.ac.uk/ihs/postgrad/research/studentprofile.htm









To me, diversity is more complicated than rituals, food, clothing, etc. ...or race, 
language, and class, etc. To me, diversity needs to include divergent viewpoints, 
divergent interpretations, and divergent perspectives. Thus, diversity needs to 
include giving power and sanctioned space for divergent voices, even if this means 
disagreeing".

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Surprising behavior using seq()

2010-11-15 Thread P Ehlers

Vadim Patsalo wrote:

Patrick and Bert,

Thank you both for you replies to my question. I see how my naïve expectations 
fail to floating point arithmetic. However, I still believe there is an 
underlying problem.

It seems to me that when asked,


c(7.7, 7.8, 7.9) %in% seq(4, 8, by=0.1)
[1]  TRUE FALSE  TRUE


R should return TRUE in all instances. %in% is testing set membership... in 
that way, shouldn't it be using all.equal() (instead of the implicit '=='), as 
Patrick suggests the R inferno?

Is there a convenient way to test set membership using all.equal()? In 
particular, can you do it (conveniently) when the lengths of the numeric lists 
are different?


This looks like a job for zapsmall; check ?zapsmall.

  -Peter Ehlers


Thanks again for your reply!
Vadim

On Nov 13, 2010, at 5:46 AM, Patrick Burns wrote:


See Circle 1 of 'The R Inferno'.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] on NMDS graphics

2010-12-08 Thread Sinu P
Hi,

I have used Vegan to construct an NMDS ordination plot. I plotted sites of
three forest types with the site number in it. My reviewer has asked me to
use different symbols for each of the forest types.
Can anyone send me how I can do this in R in simple steps. I have used the
options like ordiplot, sel and pl syntaxes that are not working for the
question that I asked for.

Best,
Sinu

-- 
Palatty Allesh Sinu PhD FRES
Fellow (Adjunct)
Ashoka Trust for Research in Ecology and the Environment (ATREE)
Royal Enclave
Sri Rampura, Jakkur Post
Bangalore 65

[[alternative HTML version deleted]]

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


[R] loop variable names as function arguments

2011-01-05 Thread P Wilson
Dear all, is there a way to loop the rp.doublebutton function in the rpanel
package? The difficulty I'm having lies with the variable name argument.

library(rpanel)
if (interactive()) {
   draw <- function(panel) {
 plot(unlist(panel$V),ylim=0:1)
 panel
 }
   panel <- rp.control(V=as.list(rep(.5,3)))
   rp.doublebutton(panel, var = V[[1]], step = 0.05, action = draw, range = c(0,
1))
   rp.doublebutton(panel, var = V[[2]], step = 0.05, action = draw, range = c(0,
1))
   rp.doublebutton(panel, var = V[[3]], step = 0.05, action = draw, range = c(0,
1))
   }

Regards,
Philip

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] meaning of formula in aggregate function

2011-01-22 Thread P Ehlers

Den wrote:

Dear R community
Recently, dear Henrique Dallazuanna literally saved me solving one
problem on data transformation which follows:

(n_, _n, j_, k_ signify numbers)

SOURCE DATA:   
id  cycle1  cycle2  cycle3  …   cycle_n

1   c   c   c   c
1   m   m   m   m
1   f   f   f   f
2   m   m   m   NA
2   f   f   f   NA
2   c   c   c   NA
3   a   a   NA  NA
3   c   c   c   NA
3   f   f   f   NA
3   NA  NA  m   NA
...


Q: How to transform source data to:
RESULT DATA:
id  cyc1cyc2cyc3…   cyc_n
1   cfm cfm cfm cfm
2   cfm cfm cfm 
3   acf acf cfm 
...


 


The Henrique's solution is:

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


Could somebody EXPLAIN HOW IT WORKS?
I mean Henrique saved my investigation indeed.
However, considering the fact, that I am about to perform investigation
of cancer chemotherapy in 500 patients, it would be nice to know what 
I am actually doing.


1. All help says about LHS in formulas like '.~id' is that it's
name is "dot notation". And not a single word more. Thus, I have no
clue, what dot in that formula really means.


Well, ?aggregate does (rather gently) point you to the
help page for _formula_ where you will find quite a few
word about the use of '.' in the Details section.


2. help says:
 Note that ‘paste()’ coerces ‘NA_character_’, the character missing
value, to ‘"NA"'
And at the same time:
 ‘na.pass’ returns the object unchanged.
I am happy, that I don't have NAs in mydata.  I just don't understand
how it happened.


I don't understand what you're asking.


3. Can't see the real difference between 'FUN = function(x) paste(x)'
and 'FUN = paste'. However, former works perfectly while latter simply
do not.


That's not quite true. You're using paste(sort(x)) and not
just x in Henrique's solution. And that's precisely
the point: when a function is not 'simple', you need to
define it. Henrique is defining it 'on the fly'; you
could also define it separately before the aggregate()
call and then use it like this:

myfun <- function(x) paste(sort(x), collapse='')
aggregate(, FUN = myfun, )

Peter Ehlers




All I can follow from code above is that R breaks data on groups with
same id, then it tear each little 'cycle' piece in separate characters,
then sorts them and put together these characters within same id on each
'cycle'. I miss how R put together all this mess back into nice data
frame of long format. NAs is also a question, as I said before. 


Could you please put some light on it if you don't mind to answer those
naive  questions.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] meaning of formula in aggregate function

2011-01-23 Thread P Ehlers

Den wrote:

Dear Dennis
Thank you very much for your comprehensive reply and for time you've
spent dealing with my e-mail.
Your kindly explanation made things clearer for me. 
After your explanation it looks simple.

lapply with chosen options takes small part of cycle with same id
(eg. df[df$id==3,"cycle2"] and makes from it just a bunch of
characters. 
The only thing I still don't get is why how this code get rid out of

NAs, but this is rather minor technical issue. Main question for me was
in formula. You helped me indeed.


Okay, now I see what you're asking regarding the NAs.
I should have realized it before. Anyway, the answer
is in the function sort(). Have a look at its help
page and note what sort does when 'na.last=NA', the
default. You'll see where the NAs went.

Peter Ehlers


Thank you again
Have a nice day
Denis

From bending but not broken Belarus

У Суб, 22/01/2011 у 17:55 -0800, Dennis Murphy піша:

Hi:

I wouldn't pretend to speak for Henrique, but I'll give it a shot.

On Sat, Jan 22, 2011 at 4:44 AM, Den  wrote:
Dear R community
Recently, dear Henrique Dallazuanna literally saved me solving
one
problem on data transformation which follows:

(n_, _n, j_, k_ signify numbers)

SOURCE DATA:

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


Q: How to transform source data to:

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



The Henrique's solution is:

aggregate(.~ id, lapply(df, as.character), FUN =

function(x)paste(sort(x), collapse = ''), na.action = na.pass)

The first part, . ~ id, is the formula. It's using every available
variable in the input data on the left hand side of the formula except
for id, which is the grouping variable.

The data object is lapply(df, as.character), which is a list object
that translates every element to character. I'm guessing that each
element of the list is a character string or list of character
strings, but I'm not sure. It looks like the individual characters of
each cycle comprise a list component within id. (??)  [My guess: the
result of lapply() is a list of lists. The top-level list components
correspond to the id's, while the second-level components are the
cycle variables, whose elements are the characters in each cycle
variable for each row with the same id.]

The function to be applied to each id is described in FUN. As Peter
mentioned, it's an 'anonymous' function, which means it is defined
in-line. In this case, a generic input object x has its elements
sorted in increasing order and then combines the elements into a
single string (the purpose of collapse = ); NA values are skipped
over. Thus, if my hypothesis about the structure of the list is
correct, the three characters in each cycle/id combination are first
sorted and then combined into a single string, which is then output as
the result. By the way that Henrique used the formula, the aggregate()
function will march through each cycle variable within id and execute
the function, and then iterate the process over all id's. 



Could somebody EXPLAIN HOW IT WORKS?

I mean Henrique saved my investigation indeed.
However, considering the fact, that I am about to perform
investigation
of cancer chemotherapy in 500 patients, it would be nice to
know what
I am actually doing.

Henrique's R knowledge is on a different level from most of us, so I
understand your question :) 


1. All help says about LHS in formulas like '.~id' is that

it's
name is "dot notation". And not a single word more. Thus, I
have no
clue, what dot in that formula really means.

. is shorthand for 'everything not otherwise specified in the model
formula'. In this case, it represents the entire set of cycle
variables.
 


2. help says:
 Note that ‘paste()’ coerces ‘NA_character_’, the character
missing
value, to ‘"NA"'
And at the same time:
 ‘na.pass’ returns the object unchanged.
I am happy, that I don't have NAs in mydata.  I just don't
u

Re: [R] ls.diag and lsfit very basic question

2011-01-23 Thread P Ehlers

MM wrote:

Hello,

Is the "std.dev" component of ls.diag( lsfit(x,y) ) the sample standard
deviation of the residuals of the fit?

I have
  ls.diag(lsfit(xx,yy))$std.dev
different from
  sd(lsfit(xx,yy)$residuals)

where xx and yy are vectors of 5 elements.


Compare

ls.diag(lsfit(xx,yy))$std.dev

with

sd(resid(lsfit(xx,yy)))*sqrt(4/3)

and think about degrees of freedom.

Peter Ehlers



Regards,

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Axes=F and plotting dual y axes

2010-07-28 Thread P Ehlers

Johnson, Cedrick W. wrote:
That worked. Stupid me forgot that I had the stock ticker 'F' assigned 
in my workspace.


Well.. guess I'll hit myself with a 2x4 now.. Thanks for your help guys..



No, don't do that. Instead, calculate how much time you saved by typing 
'F' instead
of 'FALSE' and how much time it took to diagnose the problem. Then start 
using

TRUE/FALSE instead of T/F.

 -Peter Ehlers


-c

On 07/28/2010 12:37 PM, Ben Bolker wrote:

Johnson, Cedrick W.  cedrickjohnson.com>  writes:



Howdy. Been running into a bit of trouble with plotting. Seems that
axes=F is not "working". Whenever I plot (either a dataframe or xts/zoo
series) and I set axes=F along with xlab/ylab="" I still get the 
default

axes printed in my chart.


   A quick guess: what happens if you try axes=FALSE instead? (i.e., 
have

you assigned 'F' a value in your workspace?)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] UNIX-like "cut" command in R

2011-05-02 Thread P Ehlers

Mike Miller wrote:

On Mon, 2 May 2011, Gabor Grothendieck wrote:


On Mon, May 2, 2011 at 10:32 PM, Mike Miller  wrote:

On Tue, 3 May 2011, Andrew Robinson wrote:


try substr()

OK.  Apparently, it allows things like this...


substr("abcdef",2,4)

[1] "bcd"

...which is like this:

echo "abcdef" | cut -c2-4

But that doesn't use a delimiter, it only does character-based cutting, and
it is very limited.  With "cut -c" I can do stuff this:

echo "abcdefghijklmnopqrstuvwxyz" | cut -c-3,12-15,17-

abclmnoqrstuvwxyz

It extracts characters 1 to 3, 12 to 15 and 17 to the end.

That was a great tip, though, because it led me to strsplit, which can do
what I want, however somewhat awkwardly:


y <- "a b c d e f g h i j k l m n o p q r s t u v w x y z"
paste(unlist(strsplit(y, delim))[c(1:3,12:15,17:26)], collapse=delim)

[1] "a b c l m n o q r s t u v w x y z"

That gives me what I want, but it is still a little awkward.  I guess I
don't quite get what I'm doing with lists.  I'm not clear on how this would
work with a vector of strings.


Try this:


read.fwf(textConnection("abcdefghijklmnopqrstuvwxyz"), widths = c(3, 8, 4, 1, 10), 
colClasses = c(NA, "NULL"))

  V1   V3 V5
1 abc lmno qrstuvwxyz



That gives me a few more functions to study.  Of course the new code 
(using read.fwf() and textConnection()) is not doing what was requested 
and it requires some work to compute the widths from the given numbers 
(c(1:3, 12:15, 17:26) has to be converted to c(3, 8, 4, 1, 10)).


Mike


Use str_sub() in the stringr package:

require(stringr)  # install first if necessary
s <- "abcdefghijklmnopqrstuvwxyz"

str_sub(s, c(1,12,17), c(3,15,-1))
#[1] "abc""lmno"   "qrstuvwxyz"


Peter Ehlers

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] na.omit - Is it working properly?

2011-05-03 Thread P Ehlers

Kalicin, Sarah wrote:
\begin{quote}
I have a work around for this, but can someone explain
why the first example does not work properly?
I believed it worked in the previous version of R,
by selecting just the rows=200525 and omitting the na's.
\end{quote}

You can prove this statement by providing reproducible
code that we can test.

Peter Ehlers

I just upgraded to 2.13. I am also concern with the row numbers being 
different in the selections, should I be worried? FYI, I just selected 
the first few rows for demonstration, please do not worry that the 
number of rows shown are not equal. - Sarah


With na.omit around the column, but it is showing other values in the F.WW 
column other than 200525, along with NA.  I was hoping that this would omit all 
the NA's, and show all the rows that P$F.WW=200525. I believe it did with the 
previous version of R.
P[na.omit(P$F.WW)==200525, c(51, 52)]
  F.WWR.WW
45  200525  NA
53  NA  NA
61  200534  200534
63  200608  200608
66  200522  200541
80  NA  NA
150 200521  200516
231 200530  200530

No na.omit, the F.WW=200525 seems to work, but lots of NA included. This is 
what is expected!! The row numbers are not the same as the above example, 
except the first row.

P[P$F.WW==200525, c(51, 52)]

F.WW R.WW
45200525  NA
NANA  NA
NA.1  NA  NA
NA.2  NA  NA
NA.3  NA  NA
57200525  200526
65200525  NA
67200525  NA
70200525  200525
NA.4  NA  NA
NA.5  NA  NA
86200525  NA

Na.omit excludes the na's. This is what I want. The concern I have is why the 
row numbers do not match any of those shown in the examples above.

na.omit(P[P$F.WW==200525, c(51, 52)])

F.WWR.WW
57200525  200526
70200525  200525
161   200525  200525
245   200525  200525
246   200525  200525
247   200525  200526
256   200525  200525
266   200525  200525
269   200525  200525
271   200525  200526
276   200525  200526
278   200525  200526

[[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] quantmod's addTA plotting functions

2011-05-05 Thread P Ehlers

On 2011-05-05 0:47, Russ Abbott wrote:

Hi,

I'm having trouble with quantmod's addTA plotting functions.  They seem to
work fine when run from the command line. But when run inside a function,
only the last one run is visible.  Here's an example.


test.addTA<- function(from = "2010-06-01") {
 getSymbols("^GSPC", from = from)
 GSPC.close<- GSPC[,"GSPC.Close"]
 GSPC.EMA.3<- EMA(GSPC.close, n=3, ratio=NULL)
 GSPC.EMA.10<- EMA(GSPC.close, n=10, ratio=NULL)
 chartSeries(GSPC.close, theme=chartTheme('white'), up.col="black",
dn.col="black")
 addTA(GSPC.EMA.3,   on = 1, col = "#ff")
 addTA(GSPC.EMA.10,  on = 1, col = "#ff")
 # browser()
}


When I run this, GSPC.close always appears.  But only GSPC.EMA10 appears on
the plot along with it. If I switch the order of the addTA calls,
only GSPC.EMA3 appears. If I uncomment the call to browser() neither appears
when the browser() interrupt occurs. I can then draw both GSPC.EMA.3 and
GSPC.EMA10 manually, and let the function terminate. All intended plots are
visible after the function terminates. So it isn't as if one wipes out the
other. This shows that it's possible to get all three lines on the plot, but
I can't figure out how to do it without manual intervention. Any suggestions
are appreciated.


Perhaps you didn't see this NOTE on the ?TA help page:

"Calling any of the above methods from within a function
or script will generally require them to be wrapped in a
plot call as they rely on the context of the call to
initiate the actual charting addition."

Peter Ehlers



Thanks.

*-- Russ *

[[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] quantmod's addTA plotting functions

2011-05-05 Thread P Ehlers

Russ,

All you have to do is replace

  addTA(GSPC.EMA.3,   on = 1, col = "#ff")

with

  plot(addTA(GSPC.EMA.3,   on = 1, col = "#ff"))

etc.

I can sympathize with the documentation frustration, but I think
that much of the documentation in R and in many R packages is
actually very good. I get much more frustrated with the attempts
at 'non-technical' explanations I find in other software. It
does take a bit of getting used to always looking at the Value
section and, if in doubt, checking some of the See Alsos, but
it's worth it. I don't know quantmod very well, but even a
cursory look at the pdf file shows that the docs are quite
good.

As Jeff points out, good documentation is not easy. More good
examples are always better, but that's mighty time-consuming.

Peter Ehlers

On 2011-05-05 10:42, Russ Abbott wrote:

Thanks. You're right. I didn't see that.  I read the ?addTA help page,
which (annoyingly) didn't mention that feature, but I didn't read the
?TA page. (That page was mentioned as a see also, but not as a must see.)

I don't know what it means to wrap these calls in a plot call. I tried
to put the addTA calls into a function and call that function from the
higher level function, but that didn't work either. Would you tell me
what it means to wrap these calls in a plot call.

Thanks
/-- Russ /

P.S. Pardon my irritation, but I continually find that many of the help
files assume one already knows the information one is looking for. If
you don't know it, the help files are not very helpful.  This is a good
example.  In fact, it's two good examples.  I didn't know that I had to
look at another page, and I (still) don't know what it means to wrap
plot calls in another plot call.


On Thu, May 5, 2011 at 3:39 AM, P Ehlers mailto:ehl...@ucalgary.ca>> wrote:

On 2011-05-05 0:47, Russ Abbott wrote:

Hi,

I'm having trouble with quantmod's addTA plotting functions.
  They seem to
work fine when run from the command line. But when run inside a
function,
only the last one run is visible.  Here's an example.


test.addTA<- function(from = "2010-06-01") {
 getSymbols("^GSPC", from = from)
 GSPC.close<- GSPC[,"GSPC.Close"]
 GSPC.EMA.3<- EMA(GSPC.close, n=3, ratio=NULL)
 GSPC.EMA.10<- EMA(GSPC.close, n=10, ratio=NULL)
 chartSeries(GSPC.close, theme=chartTheme('white'),
up.col="black",
dn.col="black")
 addTA(GSPC.EMA.3,   on = 1, col = "#ff")
 addTA(GSPC.EMA.10,  on = 1, col = "#ff")
 # browser()
}


When I run this, GSPC.close always appears.  But only GSPC.EMA10
appears on
the plot along with it. If I switch the order of the addTA calls,
only GSPC.EMA3 appears. If I uncomment the call to browser()
neither appears
when the browser() interrupt occurs. I can then draw both
GSPC.EMA.3 and
GSPC.EMA10 manually, and let the function terminate. All
intended plots are
visible after the function terminates. So it isn't as if one
wipes out the
other. This shows that it's possible to get all three lines on
the plot, but
I can't figure out how to do it without manual intervention. Any
suggestions
are appreciated.


Perhaps you didn't see this NOTE on the ?TA help page:

"Calling any of the above methods from within a function
or script will generally require them to be wrapped in a
plot call as they rely on the context of the call to
initiate the actual charting addition."

Peter Ehlers


Thanks.

*-- Russ *

[[alternative HTML version deleted]]

__
R-help@r-project.org <mailto:R-help@r-project.org> mailing list
https://stat.ethz.ch/mailman/listinfo/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] Using $ accessor in GAM formula

2011-05-05 Thread P Ehlers

Gene,

David has given you the preferred code. I just want to
point out that the $-accessor is often not the best
thing to use. Both dat[["y"]] and dat[, "y"] will work
just fine.

Peter Ehlers

On 2011-05-05 12:06, David Winsemius wrote:


On May 5, 2011, at 1:08 PM, Gene Leynes wrote:


This is not mission critical, but it's bothering me.  I'm getting
inconsistent results when I use the $ accessor in the gam formula

*In window #1:*

library(mgcv)
dat=data.frame(x=1:100,y=sin(1:100/50)+rnorm(100,0,.05))
str(dat)
gam(dat$y~s(dat$x))

Error in eval(expr, envir, enclos) : object 'x' not found


I get the same error, but using the standard R approach to passing
data and formulae to regression functions I have not difficulty:

  >  gam(y~s(x), data=dat)

Family: gaussian
Link function: identity

Formula:
y ~ s(x)

Estimated degrees of freedom:
4.1552  total = 5.155229

GCV score: 0.002242771





*In window #2:*

gm = gam(dat$cf~s(dat$s))
gm


Family: gaussian
Link function: identity

Formula:
dat$cf ~ s(dat$s)

Estimated degrees of freedom:
8.7757  total = 9.77568980091

GCV score: 302.551417213




Has anyone else seen the same thing?

In both cases I'm using Windows 7 and R 2.13.0

[[alternative HTML version deleted]]

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


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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Averaging uneven measurements by time with uneven numbers of measurements

2011-05-05 Thread P Ehlers

On 2011-05-05 14:20, Schatzi wrote:

I do not want smoothing as the data should have jumps (it is weight left in
feeding bunker). I was thinking of maybe using a histogram-like function and
then averaging that. Not sure if this is possible.


(It would be useful to include your original request - not everyone
uses Nabble.)

Actually, averaging *is* smoothing, but I suppose your intent is, for
some reason, not to smooth across 30-minute boundaries.

Perhaps you could use findInterval() to identify which measurements to
average.

Peter Ehlers



-
In theory, practice and theory are the same. In practice, they are not - Albert 
Einstein
--
View this message in context: 
http://r.789695.n4.nabble.com/Averaging-uneven-measurements-by-time-with-uneven-numbers-of-measurements-tp3499337p3499386.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] lattice - change background strip color in one panel

2011-05-27 Thread P Ehlers

On 2011-05-27 0:48, Coen van Hasselt wrote:

Hello,

I would like to change the background color in only -one- of the strips in a
multipanel lattice xyplot, from the default yellow-brown color.
Until now, I only managed to change the background strip color in all of the
strips using the par.settings, but I do not get it to work for only 1 strip.

Below is the current code I am using.
The resulting plot is here:
http://dl.dropbox.com/u/9788680/01_DoseIntensity_MonitoringInterval_BW.pdf
(i.e. I'd like to color the "3 months" strip in red)

xyplot(value~ant|paste(intv, "Months"), groups=perc, data=di,
type="b", layout=c(4,1),xlab="Prior anthracyclines",
lty=c(1,2),lwd=2,col="black",main="Dose intensity ~ Monitorings Interval",
ylab="Dose intensity",
scales=list(x=list(at=c(0,0.5,1)),y=list(at=seq(0,1,.1))),
par.settings = list(superpose.line=list(lwd=2,lty=1:2, col="black")),

auto.key = list(space = "right", points = FALSE, ncol=3,nrow=1, lines
= TRUE, title="Percentiles", cex=.7, cex.title=.7, siz=6))

I would greatly appreciate it if someone could guide me in the right
direction!


See if this helps:

 xyplot(Sepal.Length ~ Sepal.Width | Species, data=iris,
  par.settings=list(strip.background=list(col=c('green','red','blue'))),
  strip = function(..., bg) {
strip.default(...,
   bg = trellis.par.get("strip.background")$col[which.packet()])
  })

See ?strip.default.

Peter Ehlers



Thanks

Coen

[[alternative HTML version deleted]]

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


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


[R] subsetting with condition

2011-06-01 Thread kristina p
Dear R Team, 

I am a new R user and I am currently trying to subset my data under a
special condition. I have went through several pages of the subsetting
section here on the forum, but I was not able to find an answer.

My data is as follows:

 ID  NAME   MS Pol. Party 
1   John   x   F 
2   Mary   s   S
3   Katie  x   O
4   Sarah  p   L
5   Martin  x  O
6   Angelika   x  F
7Smith  x  O


I am intested in only those observations, where there are at least three
members of 1 political party. That is, I need to throw out all cases in the
example above, except for members of party "O". 

Would really appreciate your help.
K

--
View this message in context: 
http://r.789695.n4.nabble.com/subsetting-with-condition-tp3567193p3567193.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] subsetting with condition

2011-06-02 Thread kristina p
Thank you all, 

tried all options and it gives me exactly what I needed! Many many thanks
again)

to Bert, 
oh, I see, yes, next time I will do that.


Kristina

--
View this message in context: 
http://r.789695.n4.nabble.com/subsetting-with-condition-tp3567193p3567645.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] transform table to matrix

2011-03-02 Thread P Ehlers

Scott Chamberlain wrote:

This thread seems freakishly similar to what you are askingScott


Even to the point of including the same typo as well as proof
that neither poster bothered to read the posting guide.

Great spot, Scott!

Peter Ehlers



http://tolstoy.newcastle.edu.au/R/help/06/07/30127.html
On Wednesday, March 2, 2011 at 7:43 AM, SK MAIDUL HAQUE wrote: 

 I have a text file that I have imported into R. It contains 3 columns and
316940 rows. The first column is vegetation plot ID, the second species
names and the third is a cover value (numeric). I imported using the
read.table function.

My problem is this. I need to reformat the information as a matrix, with the
first column becoming the row labels and the second the column labels and
the cover values as the matrix cell data. However, since the
read.tablefunction imported the data as an indexed data frame, I can't use
the columns
as vectors. Is there a way around this, to convert the data frame as 3
separate vectors? I have been looking all over for a function, and my
programming skills are not great.


--
Sk Maidul Haque
Scientific Officer-C
Applied Spectroscopy Division
Bhabha Atomic Research Centre, Vizag

Mo: 09666429050/09093458503

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


Re: [R] how to delete empty levels from lattice xyplot

2011-03-02 Thread P Ehlers

Dennis Murphy wrote:

Hi:

On Wed, Mar 2, 2011 at 1:52 PM, John Smith  wrote:


Hello All,

I try to use the attached code to produce a cross over plot. There are 13
subjects, 7 of them in for/sal group, and 6 of them in sal/for group. But
in
xyplot, all the subjects are listed in both subgraphs. Could anyone help me
figure out how to get rid of the empty levels?



Let's start with the data frame construction. Using the vectors from your
original post,

studyLong <- data.frame(id = factor(rep(id, 2)),
 sequence = rep(sequence, 2),
 treat = c(treat1, treat2),
 pef = c(pef1, pef2))

Notice how I read the data frame from your original vectors. You made the
mistake of mixing character with numeric vectors in forming a matrix - by
doing that,
the matrix type is coerced to character. You then coerced the matrix to a
data frame,
but because you didn't set stringsAsFactors = FALSE, all four of the
variables
in your data frame were factors. Something looked weird to me in your first
graph, so I checked it with str():

str(studyLong)

'data.frame':   26 obs. of  4 variables:
 $ id  : Factor w/ 13 levels "1","10","11",..: 1 9 11 12 2 3 6 7 8 10
...
 $ sequence: Factor w/ 2 levels "for/sal","sal/for": 1 1 1 1 1 1 1 2 2 2 ...
 $ treat   : Factor w/ 2 levels "for","sal": 1 1 1 1 1 1 1 2 2 2 ...
 $ pef : Factor w/ 20 levels " 90","210","220",..: 9 9 15 20 4 16 11 15
9 16 ...

After I re-read it per above, it looked like this:

str(studyLong)

'data.frame':   26 obs. of  4 variables:
 $ id  : Factor w/ 13 levels  "1","2","3","4",..: 1 4 6 7 10 11 14 2 3 5
...
 $ sequence: Factor w/ 2 levels "for/sal","sal/for": 1 1 1 1 1 1 1 2 2 2 ...
 $ treat   : Factor w/ 2 levels "for","sal": 1 1 1 1 1 1 1 2 2 2 ...
 $ pef : num  310 310 370 410 250 380 330 370 310 380 ...

If I understand your question, you want the only the levels for each
treatment group plotted in each panel. This is one way, but I'm guessing
it's not quite what you were expecting ( I wasn't :):

xyplot(pef ~ id | sequence, groups=treat, data=studyLong,
   auto.key=list(columns=2), scales = list(x = list(relation = 'free')))

I tried a couple of things without much success in lattice (I'm not
terribly good at writing panel functions off the top of my head, I'm
afraid),
but it was pretty easy to get what I think you want from ggplot2:

library(ggplot2)
g <- ggplot(studyLong, aes(x = id, y = pef, colour = treat))
g + geom_point() + facet_wrap( ~ sequence, scales = 'free_x')

# or, using the simpler qplot() function,
qplot(x = id, y = pef, colour = treat, data = studyLong, geom = 'point') +
   facet_wrap( ~ sequence, scales = 'free_x')

If that's what you're after, one of the Lattice mavens can probably show
you how to do it easily in Lattice as well. I'll probably learn something,
too...


I'm no lattice expert, but it seems to me that here one
simple answer is to set the levels of 'id' appropriately:
just replace the line

 studyLong <- data.frame(id = factor(rep(id, 2)),

with

 studyLong <- data.frame(id = factor(rep(id, 2), levels=id),

and run the lattice code.

Peter Ehlers



For more on ggplot2: http://had.co.nz/ggplot2
Scroll to the bottom to find the on-line help pages with examples.

HTH,
Dennis

Thanks




library(lattice)

pef1 <- c(310,310,370,410,250,380,330,370,310,380,290,260,90)
pef2 <- c(270,260,300,390,210,350,365,385,400,410,320,340,220)
id <- c("1","4","6","7","10","11","14","2","3","5","9","12","13")
sequence <- c(rep('for/sal', 7), rep('sal/for', 6))
treat1 <- c(rep('for', 7), rep('sal', 6))
treat2 <- c(rep('sal', 7), rep('for', 6))
study <- data.frame(id, sequence, treat1, pef1, treat2, pef2)

studyLong <- as.data.frame(rbind(as.matrix(study[,c('id', 'sequence',
'treat1', 'pef1')]),
as.matrix(study[,c('id', 'sequence',
'treat2', 'pef2')])))
colnames(studyLong) <- c('id', 'sequence', 'treat', 'pef')

xyplot(pef ~ id | sequence, groups=treat, data=studyLong,
auto.key=list(columns=2))



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Creating a weighted sample - Help

2011-03-02 Thread P Ehlers

LouiseS wrote:

Hi

I'm new to R and most things I want to do I can do but I'm stuck on how to
weight a sample.  I have had a look through the post but I can't find
anything that addresses my specific problem.  I am wanting to scale up a
sample which has been taken based on a single variable (perf) which has 4
attributes H,I, J and K.  The make up of the sample is shown below:-

Perf Factored Count (A) Raw Count (B)   Factor (A/B)
H  5,945   2,9242.033174
I  1,305   2,4360.535714
J  2,000   2,0920.956023
K   7501,2250.612245


I then want to produce all further analysis based on this factored sample. 
I can produce a weighted sample in SAS using the weight function which I

have shown below

wt=0;
if perf='H' then wt=2.033174;
if perf='I ' then wt=0.535714;
if perf='J ' then wt=0.956023;
if perf='K ' then wt=0.612245;

proc freq data=DD.new;
tables resdstat;
weight wt;
run;

Does anyone know how to reproduce this in R?


I don't know what you mean by "all further analysis",
but if you want weighted mean, variance, quantile, have
a look at ?wtd.mean in the Hmisc package. Just use your
A/B values in a weights vector.

Peter Ehlers



Thanks very much

--
View this message in context: 
http://r.789695.n4.nabble.com/Creating-a-weighted-sample-Help-tp3331842p3331842.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] lattice: How to increase space between ticks and labels of z-axis?

2011-03-03 Thread P Ehlers

Marius Hofert wrote:

Dear expeRts,

How can I increase the space between the ticks and the labels in the wireframe 
plot
below? I tried some variations with par.settings=list(..) but it just didn't 
work.


Marius,

I tried setting the 'distance' parameter, but that was less
than satisfactory. One way is to modify the labels appropriately:

 z_at <- seq(2000,1,2000)
 z_labs <- paste(z_at, "", sep="")

which tacks on some spaces, and then plot:

 wireframe(z~grid[,1]*grid[,2],
  aspect=1,
  scales = list(arrows = FALSE,
z = list(at = z_at, lab = z_labs)
  ),
  zlab = list("z", hjust = 3),
  ylab = list(rot = -40),
  xlab = list(rot = 30)
)

Peter Ehlers



Many thanks,

Marius



library(lattice)

u <- seq(0, 1, length.out=20)
grid <- expand.grid(x=u, y=u)
z <- apply(grid, 1, function(x) 1/(x[1]*x[2]+0.0001))

wireframe(z~grid[,1]*grid[,2], aspect=1, scales=list(col=1, arrows=FALSE))
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] lattice custom axis function -- right side margins

2011-03-03 Thread P Ehlers

Timothy W. Hilton wrote:

To clarify the trouble I'm having with ylab.right, I am not getting an
error message; the right-side label just does not appear on the plot.


Maybe this is mac-specific. On Windows, the label shows up
just fine. You might be able to make it appear by adjusting
the 'vjust' argument to ylab.right:

print(my_plot(example_data,
  ylab.right = list(expression(e==mc^2), vjust = -2)),
  position = c(0,0,.95,1))

Try playing with 'vjust'.

Peter Ehlers



-Tim


On Thu, Mar 3, 2011 at 1:50 PM, Timothy W. Hilton wrote:


Many thanks, Richard -- the position argument does exactly what I
needed.  I'm not having any luck with the ylab.right argument.  My R and
lattice are up to date (below); is there something else I should check?

Thanks for the help,
Tim


sessionInfo()

R version 2.12.2 (2011-02-25)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] lattice_0.19-17

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

On Thu, Mar 2011, 03 at 01:05:49PM -0500, Richard M. Heiberger wrote:

print(my_plot(example_data, ylab.right=expression(e==mc^2)),
position=c(0,0,.95,1))

You will need a recent R version for the ylab.right argument.

On Thu, Mar 3, 2011 at 12:52 PM, Timothy W. Hilton 
Dear R help list,



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


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


Re: [R] How two compare two matrixes

2011-03-04 Thread P Ehlers

Alaios wrote:

That's the problem
Even a 10*10 matrix does not fit to the screen (10 columns do not fit in one 
screen's row) and thus I do not get a well aligned matrix printed.



I don't see why you would want to do this, but you
could always invoke two instances of R and create
one matrix in one and the other in the second.

Peter Ehlers


This is that makes comparisons not that easy to the eye.
From the other hand  with edit(mymatrix) I get scrolls so I can scroll to one 
row and see only the area  I want to focus in. Problem with edit is that it 
blocks cli and thus I can not have two edits running at the same time.

I would like to thank you in advacne for your help

Regards
Alex

--- On Fri, 3/4/11, Philipp Pagel  wrote:


From: Philipp Pagel 
Subject: Re: [R] How two compare two matrixes
To: r-help@r-project.org
Date: Friday, March 4, 2011, 8:04 AM

Dear all I have two 10*10

matrixes and I would like to compare

theirs contents. By the word content I mean to check

visually (not

with any mathematical formulation) how similar are the

contents.

If they are really only 10x10 you can simply print them
both to the
screen and look at them. I'm not sure what else you could
do if you
are not interested in a specific distance emasure etc.

cu
Philipp

--
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
Maximus-von-Imhof-Forum 3
85354 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/

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






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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 shell line width

2011-09-16 Thread Mike P
Hi,

I want to apologize in advance if this has already been asked. I
wasn't able to find any information, either on google or from local
list search.

I'm running an R shell from a linux command line, in an xterm window.
Whenever I print a data frame, only the first couple of columns are
printed side-by-side, the others are being repositioned below them. It
seems something is limiting the line width of the output, even though
there is enough horizontal space to fit each row on a single line.

For example, this command:

> data.frame(matrix(1:30,nrow=1))

prints columns 1-21 on the first line, and the rest 22-30 on the second.

Is there a way I can configure R to increase the width of my output?

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.


[R] memory usage upon web-query using try function

2011-06-26 Thread cir p
Dear Community,
my program below runs quite slow and I'm not sure whether the http-requests are 
to blame for this. Also, when running it gradually increases the memory usage 
enormously. After the program finishes, the memory is not freed. Can someone 
point out a problem in the code? Sorry my basic question, but I am totally new 
to R programming...

Many thans for your time,
Cyrus

require(XML)
row=0
URL="http://de.finance.yahoo.com/lookup?s=";
df <- matrix(ncol=6,nrow=10)
for (Ticker in 10:20)
{
URLTicker=paste(URL,Ticker,sep="")
query=try(readHTMLTable(
URLTicker,
which=2,
header=T,
colClasses = c("character","character","character",
   "character","character","character"),
stringsAsFactors=F,)[1,],silent=T)

if (class(query)=="data.frame")
{
row=row+1
df[row,]=as.character(query)
}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] ncdf - writing variable to a file

2012-08-21 Thread m p
Hello,
I have a problem writing a variable to an existing file.
Below is a part of my script and how it fails.
I can't find "create.var.ncdf" in help
Thanks for any help.
Mark

nc <- open.ncdf(ncname, readunlim=FALSE, write=TRUE )

missing <- 1.e+30

xdim <- nc$dim[["west_east"]]
ydim <- nc$dim[["south_north"]]
tdim <- nc$dim[["Time"]]


lscalevar <- var.def.ncdf(scalenames[ivar],
'gpoints', list(xdim,ydim,tdim), missing )

nc <- var.add.ncdf( nc, lscalevar )

for( i in 1:nt)
put.var.ncdf(nc,lscalevar,scale,verbose=TRUE )

#scale is an array dimensioned (nx,ny)

[1] "Hint: make SURE the variable was not only defined with a call to
def.var.ncdf, but also included in the list passed to create.var.ncdf"
Error in vobjtovarid(nc, varid, verbose = verbose) : stopping
In addition: Warning message:
In is.na(vals) : is.na() applied to non-(list or vector) of type 'closure'

[[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] R shell line width

2011-10-06 Thread Mike P
Thank you very much for your responses! This is exactly what I needed.

On Fri, Sep 16, 2011 at 8:13 PM, Joshua Wiley  wrote:
> Hi Mike,
>
> Look at ?options  particularly something like:
>
> options(width = 120)
>
> 80 is the default, I believe.  On 1920 pixels I can comfortably get
> around 220 (depending on the overhead of the program, full screen,
> etc.).  I imagine it would also be possible to run into limitations
> from the terminal R is running in, though I do not know that for a
> fact.
>
> Cheers,
>
> Josh
>
> On Fri, Sep 16, 2011 at 12:48 PM, Mike P  wrote:
>> Hi,
>>
>> I want to apologize in advance if this has already been asked. I
>> wasn't able to find any information, either on google or from local
>> list search.
>>
>> I'm running an R shell from a linux command line, in an xterm window.
>> Whenever I print a data frame, only the first couple of columns are
>> printed side-by-side, the others are being repositioned below them. It
>> seems something is limiting the line width of the output, even though
>> there is enough horizontal space to fit each row on a single line.
>>
>> For example, this command:
>>
>>> data.frame(matrix(1:30,nrow=1))
>>
>> prints columns 1-21 on the first line, and the rest 22-30 on the second.
>>
>> Is there a way I can configure R to increase the width of my output?
>>
>> 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.
>>
>
>
>
> --
> 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.


[R] bioconductor help

2012-04-01 Thread Eric P
Hello,

I have a question on how to get bioconductor running properly on
Ubuntu 11.10 as I have tried everything it seems like and I keep on
getting this message. But before I go farther can you please email and
say that you will help me with this because nobody seems to want to
help or know how to.

"Cannot find Tcl/Tk package "Tktable". affylmGUI cannot conitnue"

I have installed BWidget like it tells me to.

I have tried to install Tktable 2.9 but cannot.  When I try to do so I
cannot run the make file properly. Then I have ran ./configure >
output and gotten /Tktable2.9$ ./configure > output
> configure: WARNING: "Cannot find Tcl configuration definitions"

And at this point I have really no idea what to do...So please some
one help me

Below is what happening when I try to install Tktable 2.9

Cheers,
Eric

tar zxf Tktable2.9.tar.gz
>> cd Tktable2.9
>> ./configure
>> make
>> sudo make install
>>
>> But when I run the command it says there is no make file.
>>
>> The directory looks like this
>>
>> aclocal.m4  configure.in  library  README.blt  TODO.txt
>> ChangeLog   demos license.txt  README.txt  unix
>> config.log  doc   mac  tclconfig   UPGRADING.txt
>> configure   generic   Makefile.in  tests   win
>>
>>
>> and this is what happens when I run the make command
>>
>>
>> :~/Downloads/Tktable2.9$ make
>> make: *** No targets specified and no makefile found.  Stop.
>>
>>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] fixed TkTable problem but I need to unistall/reinstall R....How do I manage that??

2012-02-26 Thread Eric P
Hello,

So I need some help. I have been trying to get biocondutor to work on
my computer that has Ubuntu 11.10 running on it and I found out that I
needed to install something called TkTable before I install R. So I
did that but now I have no idea how to properly uninstall/reinstall R,
and I cannot find any sort of help with that on this site or any
other. Help...Thanks

Eric

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Plotmath bug or my misunderstanding?

2012-05-13 Thread P Ehlers

Bert: inline

On 2012-05-13 7:43, Bert Gunter wrote:

Peter/David:

1. For some reason, I didn't see Peter's reply on r-help.

2. To Peter: Aha!!
Let me play this back to you. In

  text(1,1,labels=expression(atop(atop(sigma,"some text"),"another
level")),cex = 2)

The (outer) whole atop() specification is allocated twice the amount
of space that would be required for the current font size, cex =1.
Then each of the top and bottom is allocated the amount of space
needed within this cex = 2 space. For the inner atop to fit within
that allocated amount of space, its top and bottom must get smaller,
of course. N'est-ce pas?


Yes, that's my understanding. With your text() call above, the
size of "another level" is what text(x,y,lab="another text",cex=2)
will print.



This makes sense to me!  My misunderstanding is thinking that cex
applied to the individual text components, not the entire expression.
Enlightenment much appreciated.

3. However, this now begs the question of how to keep all text and
symbols the same size, which is really what the OP really wanted (a
way to emulate multiple lines). I'll fool around with this to see what
I come up with now that I'm enlightened -- or see if you or David come
up with something clever.


I don't think it's possible to nest atop()s and have all members
of the same cex.

Anyway, atop() is really the wrong tool for this sort of thing.
It can be a useful quick fix, but I usually prefer the 'multiple
lines' approach for its greater flexibility.

Peter Ehlers




Cheers,
Bert



On Sat, May 12, 2012 at 9:27 PM, David Winsemius  wrote:


On May 12, 2012, at 6:27 PM, Peter Ehlers wrote:


Hi Bert,

I think the 'cex=' argument applies to the outermost 'atop()'.
It then applies that size specification to each of the two
components of the atop(a,b). If one of the components is itself
another atop(a,b), then the individual parts are sized downward
to produce the required cex for the unit.

As for the 'cex=1:2' specification, only the first value is used.



Isn't there also a 0.67 factor being applied to whatever was the "outside"
size prior to being used for the atop arguments? So the inner atop arguments
get that applied twice if I understand correctly.

text(1,1,labels=expression(atop(
   atop("top level one", "top level two"),
   "another level")
 ) )


I did notice that the cr-linefeed (perhaps unintentionally being inserted by
a mail client) seemed to be "working" at least on my Mac :

plot(1,1)
text(1,1,labels=expression("another
level")
 )

Whereas it is well known that "\n" will appear as two characters, \n, and
not be interpreted as a special.
--
David



Cheers,
Peter Ehlers

On 2012-05-12 14:05, Bert Gunter wrote:


This is a followup to a recent post on using atop() to obtain
multiline expressions.

My reading of the plotmath docs makes it clear that issuing (in base
graphics) the specification

par(cex = 2)

doubles symbols and regular text in subsequent plotmath expressions.
However, it is unclear to me what specifying cex _within_ the
annotation function using plotmath should do, and the following seems
to want to have it both ways: ignore/obey )or maybe recycle?)

plot(1,type="n", xaxt='n', yaxt='n', ann=FALSE)
  text(1,1,labels=expression(atop(sigma,"some text")),cex = 2)
## obeys the cex specification in symbols and text

HOWEVER

plot(1,type="n", xaxt='n', yaxt='n', ann=FALSE)
  text(1,1,labels=expression(atop(atop(sigma,"some text"),"another
level")),cex = 2)
## ???

For even more fun, try:

plot(1,type="n", xaxt='n', yaxt='n', ann=FALSE)
  text(1,1,labels=expression(atop(atop(sigma,"some text"),"another level")),cex 
= 1:2)
##

So I confess to being flummoxed. Enlightenment would be much appreciated.

Cheers,
Bert






__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] variable spatial correlation

2012-05-16 Thread m p
Hello,
I used "correlogram" from "spatial" package to determine correlation scale
for my data but just looking with bare eye it seems that the correlation
scale varies over the domain.
Can someone suggest what would the best way to handle that problem?
Thanks,
Mark

[[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] MAD

2007-09-18 Thread P Ehlers
If you read ?mad you will find this phrase:

"median of the absolute deviations from the median"

Note the first word. I think you're too focused on
the last word.

Peter Ehlers

Nair, Murlidharan T wrote:
> 
> -Original Message-
> From: Deepayan Sarkar [mailto:[EMAIL PROTECTED] 
> Sent: Monday, September 17, 2007 5:10 PM
> To: Nair, Murlidharan T
> Cc: [EMAIL PROTECTED]
> Subject: Re: [R] MAD
> 
> On 9/17/07, Nair, Murlidharan T <[EMAIL PROTECTED]> wrote:
>> I am calculating the median absolute deviation using mad function, and
>> it tends to ignore the parameter constant=1, when I am calculating it
>> for x=seq(1:5). Am I missing something here?
>>
>> x<-seq(1:5)
>> mad(x)# gives [1] 1.4826
>> mad(x, constant=1)# gives [1] 1
>> #Here is the long form
>> dev.from.median<-abs((x-median(x)))
>> dev.from.median # Gives [1] 2 1 0 1 2
>> sum(dev.from.median) # Gives [1] 6
>> sum(dev.from.median)/length(x) # Gives [1] 1.2
>> # The long form does not match the output from the function
>>
>> # When x<-seq(1:10) they match
>> x<-seq(1:10)
>> dev.from.median<-abs((x-median(x)))
>> sum(dev.from.median)/length(x) # Gives 2.5
>> mad(x, constant=1) # Gives 2.5
>> #The long form matches the output from the function
>>
>> Did I miss anything here?
> 
> yes; mad := Median (not mean) absolute deviation (from the median, by
> default).
> 
> -Deepayan
> 
> Indeed, its median and that what I am calculating in the long form.  So,
> what is that you found I was doing differently? May be I missed your
> point. 
> Thx../M
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Plotmath issue superscript "-"

2007-09-20 Thread P Ehlers
If you need a subscript as well, I like

  plot(0, main=quote({NO^'\x96'}[3]))

Peter Ehlers

Peter Dalgaard wrote:
> Gavin Simpson wrote:
>> Dear List,
>>
>> I'm trying to typeset some chemical ions in axis labels. These have both
>> super and subscript components, and for some, I need a superscript "-".
>> In LaTeX I might use $NO_3^-$ to do the typesetting, but I'm having a
>> problem getting the correct invocation for expression:
>>
>>   
>>> expression(NO^{-}[3])
>>> 
>> Error: syntax error, unexpected '}' in "expression(NO^{-}"
>>   
>>> expression(NO^-[3])
>>> 
>> Error: syntax error, unexpected '[' in "expression(NO^-["
>>   
>>> expression(NO^-)
>>> 
>> Error: syntax error, unexpected ')' in "expression(NO^-)"
>>   
>>> expression(NO^{-})
>>> 
>> Error: syntax error, unexpected '}' in "expression(NO^{-}"
>>
>> This is with R 2.5.1 (exact version info below).
>>
>> I suspect this is something to do with my use of the "-", which has some
>> special meaning.
>>
>> Is there a way to achieve a superscript "-" (or similar looking
>> character) using the plotmath routines in R?
>>
>>   
> It's an operator, it needs something to operate on.
> 
> Try
> 
>  plot(0,main=quote(NO^-{}))
> 
> 
> 
>> Thanks in advance,
>>
>> G
>>
>>   
>>> version
>>> 
>>_  
>> platform   i686-pc-linux-gnu  
>> arch   i686   
>> os linux-gnu  
>> system i686, linux-gnu
>> status Patched
>> major  2  
>> minor  5.1
>> year   2007   
>> month  07 
>> day05 
>> svn rev42131  
>> language   R  
>> version.string R version 2.5.1 Patched (2007-07-05 r42131)
>>
>>   
> 
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Plotmath issue superscript "-"

2007-09-20 Thread P Ehlers
Yes, sorry, I should have said that I was on Windows.
In a UTF-8 locale, you could try \u2013 in place of \x96.
The character is an endash.

Peter Ehlers

Scionforbai wrote:
> Hallo,
> 
>> If you need a subscript as well, I like
>>
>>   plot(0, main=quote({NO^'\x96'}[3]))
> 
> 
> I tried this but I get:
> 
>>  plot(0, main=quote({NO^'\x96'}[3]))
> Errore in title(...) : stringa multibyte non valida ('invalid multibyte 
> string')
> 
> My R version is:
> platform   i686-redhat-linux-gnu
> version.string R version 2.4.1 (2006-12-18)
> 
> locale is: LANG=it_IT.UTF-8
> 
> What is this multibyte string? Does it depend on LOCALE settings?
> Where can I find further docs on this way to pass character
> descriptors?
> Thanks,
> ScionForbai
> 
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 numbers at a specified decimal length on a plot()

2007-09-23 Thread P Ehlers
I find sprintf() useful for this.

Compare
lab <- rnorm(8)
plot(1:10)
text(2:9, 2:9, lab)

with
lab2 <- sprintf("%4.2f", lab)
plot(1:10)
text(2:9, 2:9, lab2)

  - Peter Ehlers

Matthew Dubins wrote:
> Hi there,
> 
> I want to figure out how to plot means, with 2 decimal places, of any Y 
> variable on a scatterplot according to any X variable (which obviously 
> should have limited scope).  I already figured out how to plot the 
> means, but without limiting their precision to 2 decimal places.  This 
> is the code I used once I had the scatterplot drawn:
> 
> text(c(1990, 1992, 1994, 1996, 1998, 1999, 2000, 2001, 2002, 2003), 25, 
> mean.yrly.closures$values, cex=.7)
> 
> 
> It's a plot of school closures by Year.  The closures variable is 
> labeled "values" in the "mean.yrly.closures" data set.  I managed to 
> *display* the mean.yrly.closures data set with a precision of 2 decimal 
> places (options(digits=2)), but then once I plotted the numbers, they 
> showed up with many decimal places. 
> 
> It would be nice to figure this out so that I don't have to rely on 
> Excel to make changes to the precision!
> 
> Thanks,
> Matthew Dubins
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Legend

2007-09-26 Thread P Ehlers
How about

a <- .33
b <- .55
legend("bottom", fill=c("red","blue"),
   legend=c(bquote(p == .(a)), bquote(p == .(b))), bty="n")

or look at ?substitute

  - Peter Ehlers

stat stat wrote:
> I have following syntax for putting a legend :
> 
> legend("bottom", fill=c("red","blue"), legend=expression(p==0.30, p==0.50), 
> bty="n")
> 
> However what I want is that : the value "0.30" should be a value of a 
> variable instead of a constant, so that I can put the name of this variable 
> and in legend it's value will be displayed. Can anyone tell me how to do that?
> 
> Regards,
> 
> 
> thanks in advance
>
> -
>  Why delete messages? Unlimited storage is just a click away.
>   [[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] Arrows Pointing to Curve

2007-09-27 Thread P Ehlers
You might also look at ?Arrows in package IDPmisc
and ?p.arrows in package sfsmisc.

  - Peter Ehlers


> --- Lorenzo Isella <[EMAIL PROTECTED]> wrote:
> 
>> Dear All,
>> I hope this is not a FAQ, but my online research was
>> not fruitful.
>> Consider a standard 2D plot generated with the
>> "plot" command.
>> I would like to introduce inside the graph some text
>> with an arrow 
>> pointing to a specific position of the plotted
>> function.
>> Is this doable in R? Can anyone provide me with an
>> example?
>> Many thanks
>>
>> Lorenzo
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Shapiro-Welch W value interpretation

2007-09-30 Thread P Ehlers

Omar Baqueiro wrote:
> Hello,
> 
> I have tested a distribution for normality using the Shapiro-Welch
> statistic. The result of this is the following:
> 
> 
> Shapiro-Wilk normality test
> 
> data: mydata
> W = 0.9989, p-value = 0.8791
> 
> 
> I know that the p-value > 0.05 (for my purposes) means that the data
> IS normally distributed but what I am not sure is with the W value,
> what values tell me that the data is normally distributed.   I know
> that my data is normally distributed, but what I want to know if how
> to interpret the W value, I have read that "if W is very small then
> the distribution is probably not normally distributed", but how
> "small"  is "very small", and also, what happens is, say W = 0.01
> but the p-value is > my significance level (0.05)? is the hypothesis
> rejected?
> 

There is some confusion in your query.
First, how do you know that your data are indeed normally distributed?
That's *not* what the p-value of the test says.
Consider the following result of the Shapiro-Wilk test applied to
a vector x:

data: x
W = 0.9856, p-value = 0.988

Here x was not sampled from a normal distribution (code at end).

Second, the point of a p-value is to formalize decision-making
so that critical regions of tests are converted to p-value intervals.
Thus, your emphasis on the value of W is misplaced. It's
not how small W is but how small it is for the given sample size,
and the p-value takes care of the significance. (This is not to
say, of course, that the distribution of W is not of interest.)

Finally, what exactly, in your view, is "the hypothesis"?

I hope this doesn't sound too critical. I'm trying to be helpful.

Peter Ehlers

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

set.seed(34); shapiro.test(rexp(10))

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


Re: [R] data structure with coefficients, and call from lm()

2007-10-01 Thread P Ehlers
John,

Jim has shown how to accomplish what you want.
Here's a slight variation (for a single model):

y <- rnorm(20)
x <- runif(20)
z <- runif(20)

fm <- lm(y ~ x + z)
m <- cbind(NA, coef(summary(fm)))
colnames(m)[1] <- deparse(formula(fm))
print(m, na.print = "")

  - Peter Ehlers

jim holtman wrote:
> This is close to what you want.  I created the list by hand, but you
> can create it in your processing loop.  Once you have the list
> created, you can create your own print routine.
> 
>> x <- runif(100)
>> z <- runif(100)
>> y <- runif(100)
>>
>>
>> # I am doing this by hand, but you could easily automate it in a loop or 
>> function call
>> whatIwant <- list()  # where results are stored
>>
>> lm.x <- lm(y~x)
>> whatIwant[[1]] <- list(summary(lm.x)$call, summary(lm.x)$coefficients)
>>
>> lm.z <- lm(y~z)
>> whatIwant[[2]] <- list(summary(lm.z)$call, summary(lm.z)$coefficients)
>>
>> lm.xz <- lm(y~x+z)
>> whatIwant[[3]] <- list(summary(lm.xz)$call, summary(lm.xz)$coefficients)
>>
>> # this is close
>> whatIwant
> [[1]]
> [[1]][[1]]
> lm(formula = y ~ x)
> 
> [[1]][[2]]
>   Estimate Std. Error   t value Pr(>|t|)
> (Intercept) 0.46211645 0.05442237 8.4912958 2.244835e-13
> x   0.02387787 0.09709648 0.2459190 8.062592e-01
> 
> 
> [[2]]
> [[2]][[1]]
> lm(formula = y ~ z)
> 
> [[2]][[2]]
>Estimate Std. Errort value Pr(>|t|)
> (Intercept)  0.49612568 0.05390759  9.2032627 6.488440e-15
> z   -0.04600174 0.09298692 -0.4947119 6.219108e-01
> 
> 
> [[3]]
> [[3]][[1]]
> lm(formula = y ~ x + z)
> 
> [[3]][[2]]
>Estimate Std. Errort value Pr(>|t|)
> (Intercept)  0.48617771 0.07502099  6.480 3.804443e-09
> x0.01880206 0.09808697  0.1916877 8.483876e-01
> z   -0.04400913 0.09402369 -0.4680643 6.407886e-01
> 
> 
>> #now create a function to print your list
>> printMyList <-
> + function(myList){
> + lapply(myList, function(.ele){
> + print(.ele[[1]])
> + print(.ele[[2]])
> + })
> + invisible(NULL)
> + }
>> printMyList(whatIwant)
> lm(formula = y ~ x)
>   Estimate Std. Error   t value Pr(>|t|)
> (Intercept) 0.46211645 0.05442237 8.4912958 2.244835e-13
> x   0.02387787 0.09709648 0.2459190 8.062592e-01
> lm(formula = y ~ z)
>Estimate Std. Errort value Pr(>|t|)
> (Intercept)  0.49612568 0.05390759  9.2032627 6.488440e-15
> z   -0.04600174 0.09298692 -0.4947119 6.219108e-01
> lm(formula = y ~ x + z)
>Estimate Std. Errort value Pr(>|t|)
> (Intercept)  0.48617771 0.07502099  6.480 3.804443e-09
> x0.01880206 0.09808697  0.1916877 8.483876e-01
> z   -0.04400913 0.09402369 -0.4680643 6.407886e-01
>>
> 
> 
> On 9/30/07, John Sorkin <[EMAIL PROTECTED]> wrote:
>> Jim,
>> You are indeed trying to help, again my thanks.
>> What I want to do is make a single structure - a table is an apt description 
>> that will summarize all the regressions, something like:
>>
>> Estimate Std. Error   t value Pr(>|t|)
>>  (Intercept) lm(formula = y ~ x) 4.927791 2.62115494  1.880007 6.307727e-02
>>  x   1.887634 0.04372724 43.168382 1.410167e-65
>>  (Intercept) lm(formula = z ~ x) 6.927791 2.62115494  1.880007 6.307727e-02
>>  x   1.887634 0.04372724 43.168382 1.410167e-65
>>  (Intercept) lm(formula = z~x+z) 6.927791 2.62115494  1.880007 6.307727e-02
>>  x   1.887634 0.04372724 43.168382 1.410167e-65
>>  z   1.887634 0.04372724 43.168382 1.410167e-65
>>
>> If you use a non-proportional spaced font (e.g. Courier on a windows system)
>> the material above is a single "table" that contains all the data from my 
>> numerous regressions, including the call and the coefficients.(If I can get
>> this to work I will add the R squared values) n.b. In the example above I 
>> have
>> copied the estimates and changed the label of the lines just to demonstrate 
>> the
>> kind of output I desire. Of course when used on real data each line will have
>> different values.
>> Again thanks,
>> John
>>
>>
>> John Sorkin M.D., Ph.D.
>> Chief, Biostatistics and Informatics
>> University of Maryland School of Medicine Division of Gerontology
>> Baltimore VA Medical Center
>> 10 North Greene Street
>> GRECC (BT/18/GR)
>> Baltimore, MD 21201-1524
>> (Phone) 410-605-7119
>> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>>
> "jim holtman" <[EMAIL PROTECTED]> 9/30/2007 11:24 PM >>>
>> The easiest thing is to same the result from 'lm' and then you can use
>> that to extract any of the information that you want.  If you are
>> going to do thousands of regressions, then you can make a list of 'lm'
>> results, or if that is too memory intensive (depends on the size of
>> the regressions), you could same them to a file with 'save'.  It all
>> depends on what you want to do with t

[R] 1-d function fitting

2007-10-25 Thread m p
Hello,
I'd like to check if my data can be well approximated  with a function 
(1+x/L) exp(-x/L)
and calculate the best value for L. Is there some package in R that would 
simplify that task?
Thanks,
Mark


 __



[[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] 1-d function fitting

2007-10-25 Thread m p
No, that's not my homework. Does that seem so easy?
Mark

Rolf Turner <[EMAIL PROTECTED]> wrote: 
On 26/10/2007, at 10:14 AM, m p wrote:

> Hello,
> I'd like to check if my data can be well approximated  with a function
> (1+x/L) exp(-x/L)
> and calculate the best value for L. Is there some package in R that  
> would simplify that task?
> Thanks,
> Mark

 Is this a homework question?

   cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:17}}

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


[R] How to switch off accepting the shortcut of column names

2007-10-30 Thread P. Olsson
Dear R-users,

currently I am working with the R version 2.4.1.
I realized it has a feature,  which might be wonderful (as so many things in
R), but in this case might be a bit dangerous as well. It seems that columns
of a data frame can be called just by indicating the first letter of the
name of the column.

For example:
first_item <- seq(1,10)
second_item <- seq(11,20)
dat <- data.frame(first_item, second_item)
names(dat)
# [1] "first_item"  "second_item"
dat$f
# [1]  1  2  3  4  5  6  7  8  9 10
dat$s
#  [1] 11 12 13 14 15 16 17 18 19 20

The good thing is, that if there is more than one column starting with the
same letter(s), more than one letter has to be given to call the column.
However, I would appreciate if I could choose an option in my workspace,
whether this type of shortcut is allowed or not.

Is there such an option?

Thanks for any potential hints.

Best wishes,

P. Olsson

[[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] Dataframe is character

2017-11-17 Thread P. Roberto Bakker
Hi everybody,

Question: why are my dataframe and numeric variables a character?

I read an excel file via readxl but my dataframe is a character, and
numeric variables, eg "yi", are also a character.
My excelfile is in English numeric
Sometimes the dataframe was indeed a dataframe, but I do not know why it
did sometimes.
Thank you in advance, Roberto
PS I used "guess". The problem is not solve by using "text", "numeric" etc

My syntax (I think I cannot send the excel file as binary?)

> library(readxl)
> library(readxl)
> library(metafor)
> setwd("C:/docs/Work2/Statistic_Analyses/MetaQTcAD")
> getwd()
[1] "C:/docs/Work2/Statistic_Analyses/MetaQTcAD"
>

> dat <- read_excel("Hedges-g_QTc MA_R05.xlsx", sheet = 2, col_names=TRUE,
col_types = c("guess"))
> class("dat")
[1] "character"
> class("yi")
[1] "character"
>

[[alternative HTML version deleted]]

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


[R] [R-pkgs] elo v1.0.0: Elo Ratings

2017-11-21 Thread Heinzen, Ethan P.
Dear useRs,

I'm pleased to announce the v1.0.0 major release of the "elo" package on CRAN 
(https://cran.r-project.org/package=elo).

This package implements a flexible framework for calculating Elo ratings of any 
two-team-per-matchup system (chess, sports leagues, 'Go', etc.).  It is capable 
of evaluating a variety of matchups, Elo rating updates, and win probabilities, 
all based on the basic Elo rating system.  For details, see the vignette 
included in the package.  Bug reports and other contributions are always 
welcome on the "elo" package GitHub page: https://github.com/eheinzen/elo.

Cheers,
Ethan Heinzen
heinzen.et...@mayo.edu
https://github.com/eheinzen

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

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


[R] Copy text from Script syntax into .txt

2018-04-24 Thread P. Roberto Bakker
Hi everybody,

How can I get text from RScript (e.g. syntax, reminder) into the result
text.
Sink() does not do that - I only read the results and therefore I have to
'guess' which syntax was used where - reminders I wrote are lost.

Bw and thank you in advance,

Roberto

[[alternative HTML version deleted]]

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


Re: [R] Copy text from Script syntax into .txt

2018-04-25 Thread P. Roberto Bakker
Hi Thierry,

Thank you for your information.

Bw Roberto

Op di 24 apr. 2018 12:01 schreef Thierry Onkelinx :

> Dear Roberto,
>
> The easiest way IMHO is to convert your script into an R markdown
> document. See https://rmarkdown.rstudio.com/
>
> Best regards,
>
> ir. Thierry Onkelinx
> Statisticus / Statistician
>
> Vlaamse Overheid / Government of Flanders
> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
> AND FOREST
> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
> thierry.onkel...@inbo.be
> Havenlaan 88 bus 73, 1000 Brussel
> www.inbo.be
>
>
> ///
> To call in the statistician after the experiment is done may be no
> more than asking him to perform a post-mortem examination: he may be
> able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does
> not ensure that a reasonable answer can be extracted from a given body
> of data. ~ John Tukey
>
> ///
>
>
>
>
> 2018-04-24 11:23 GMT+02:00 P. Roberto Bakker :
> > Hi everybody,
> >
> > How can I get text from RScript (e.g. syntax, reminder) into the result
> > text.
> > Sink() does not do that - I only read the results and therefore I have to
> > 'guess' which syntax was used where - reminders I wrote are lost.
> >
> > Bw and thank you in advance,
> >
> > Roberto
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


  1   2   3   4   5   >