[R] GMM twoStep vs Stata's ivreg2 gmm2s or ivregress coefficients

2020-03-29 Thread Peter Lomas
Hi R-Help, I'm replicating IV-GMM models from Stata in R, but get small differences in coefficients (eg 100.0 vs 100.3); I'm hoping somebody can share anything they've learned attempting the same thing. The linear models match exactly, so there isn't a data problem. With both help files I've matc

[R] Creating dataframe with subtotals by all fields and totals of subtotals

2016-09-14 Thread Peter Lomas
Hello R-Helpers, I'm trying to to create a subtotal category for each column in a dataset, and totals of subtotals, resulting in one data frame. I figure I could do this by a whack of aggregate() and rbind(), but I'm hoping there is a simpler way. Below is a sample dataset. Underneath I create a

Re: [R] Calculate average of many subsets based on columns in another dataframe

2016-02-11 Thread Peter Lomas
is still a loop (via apply), however, so it may not > satisfy your efficiency needs. > > Cheers, > Bert > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breat

Re: [R] Calculate average of many subsets based on columns in another dataframe

2016-02-10 Thread Peter Lomas
indInterval is a fast way to do this. > > ... I think. > > If you try this, let me know (perhaps privately) how/if it works. > > Cheers, > Bert > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it.&q

[R] Calculate average of many subsets based on columns in another dataframe

2016-02-10 Thread Peter Lomas
Hello, I have a dataframe with a date range, and another dataframe with observations by date. For each date range, I'd like to average the values within that range from the other dataframe. I've provided code below doing what I would like, but using a for loop is too inefficient for my actual cas

[R] Resizing a graph with a legend in the outer margin - wish for functionality like mtext()

2015-03-25 Thread Peter Lomas
Dear R-Helpers I am attempting to get a legend in the outer margins of a graph that has a similar flexibility to mtext(), within base graphics. This is used in a tool that will end up with graphs of many different coordinates, exported in many different sizes. I'm trying to come up with a genera

[R] Conditional formatting of POSIXct date axis labels to only print year at a change

2014-02-11 Thread Peter Lomas
Hello, I'm creating graphs like the following: x <- seq(as.POSIXct("2012-01-01"), as.POSIXct("2013-01-01"), by = "days") y <- (1:length(x)*10 + cumsum(rnorm(n=length(x), mean=0, sd= 100))) plot(x,y, type = 'l', xaxt='n') axis.POSIXct(side=1,at=seq(min(x), max(x), by="months"), format = "%b \'%y

Re: [R] Math notation in a title

2013-10-15 Thread Peter Lomas
check out: demo("plotmath") On Tue, Oct 15, 2013 at 4:30 PM, arun wrote: > Hi, > Try: > plot(1,main=bquote("Pareto Distribution: " ~ alpha == 2 * "," > ~italic(y[m]) == 3)) > > > A.K. > > > Hi, > > I'd like to put the following in a main title of a plot. > > > > Can someone show me how to do t

Re: [R] fitted

2013-08-26 Thread Peter Lomas
I don't fully understand what you are looking for, but you may want to check out ?predict, ?predict.lm On Sat, Aug 24, 2013 at 7:43 AM, alR wrote: > I have fitted a multiple regression model to the row of a matrix using lm: > > ft<-lm(datos[i, ]-r1 + r2+ r3 + r4,keep.data = TRUE,model=TRUE) > >

Re: [R] Subset a floating point vector using all.equal?

2013-05-30 Thread Peter Lomas
t; > x[are.equal(x, 0.15)] > > > Hope this helps, > > Rui Barradas > > Em 30-05-2013 02:27, Peter Lomas escreveu: > >> Hello, >> >> I have a whole bunch of data to two decimal places. I've done some >> arithmetic with them, so floating point be

Re: [R] How can I write logical function in R?

2013-05-30 Thread Peter Lomas
Not sure whether your data is just 0's and 1's, but something like this may also work for you: imm <- 1*(speciesTime2[ , 2:4] == 1 & speciesTime2[ , 2:4] != speciesTime1[ , 2:4]) imm <- cbind(imm, sum = rowSums(imm)) Exti <- 1*(speciesTime2[ , 2:4] == 0 & speciesTime2[ , 2:4] != speciesTime1[ , 2

[R] Subset a floating point vector using all.equal?

2013-05-29 Thread Peter Lomas
Hello, I have a whole bunch of data to two decimal places. I've done some arithmetic with them, so floating point becomes an issue. x <- c(1, 0.15,(0.1+.05),0.4) I want to do something like this: x[x==0.15] But you'll notice that is troublesome with the well known floating point issue. So re

[R] Reading Parts of Excel Files (within a sheet)

2011-09-14 Thread Peter Lomas
Dear R Users, I have to read data from many excel spreadsheets, all which have some frustrating formatting (lots of titles, headers, etc.). I am trying to work directly from source data and the number of the spreadsheets I would have to go through make reformatting one by one a pain. I have foun

Re: [R] Latex Table for means and standard deviations in brackets

2011-07-20 Thread Peter Lomas
Hi Jim, Perhaps somebody else knows a smoother way, but in the past I have just built my table in R as a matrix then used xtable. Here's what I would do with your example: library(xtable) dataset1 = matrix( c(1,2,3,4, 5, 6 ), 2 , 3) dataset2 = matrix( c(4,3,5,10, 1, 0), 2, 3) dataset <- rbind(d

Re: [R] Taking all "complete" diagonals of a matrix

2011-07-19 Thread Peter Lomas
On Tue, Jul 19, 2011 at 17:34, Nordlund, Dan (DSHS/RDA) wrote: >> -Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- >> project.org] On Behalf Of Peter Lomas >> Sent: Tuesday, July 19, 2011 2:16 PM >> To: r-help@r-project.org >>

[R] Taking all "complete" diagonals of a matrix

2011-07-19 Thread Peter Lomas
Hi R-Help! I am trying to find a nicer way of extracting all the "complete" diagonals of a matrix. I am working with very large matrices that have many more rows than columns. I want to be able to extract each of the diagonals that are as long as the number of columns in the matrix. I have writ

Re: [R] calculating the mean of a random matrix (by row) and some general questions

2011-07-19 Thread Peter Lomas
Hi Richard, As others have said, try to use the "apply" functions rather than loops. There is also an apply function for lists, see ?lapply. This is much more efficient. I also like writing my own functions. For example: f <- function(x) { x^2 } Which can then be used by: > f(2) [1] 4 Thi