Re: [R] Extract from a text file

2016-05-31 Thread Bert Gunter
On Tue, May 31, 2016 at 7:05 PM, Jeff Newmiller
 wrote:
> You need to go back and study how I made my solution reproducible and make 
> your problem reproducible.
>
> You probably also ought to spend some time comparing the regex pattern to 
> your actual data... the point of this list is to learn how to construct these 
> solutions yourself.


Ah, if only that were the case.

(or is that just the grumbling of an old curmudgeon?)

Cheers,
Bert


> --
> Sent from my phone. Please excuse my brevity.
>
> On May 31, 2016 6:26:31 PM PDT, Val  wrote:
>>Thank you so much Jeff. It worked for this example.
>>
>>When I read it from a file (c:\data\test.txt) it did not work
>>
>>KLEM="c:\data"
>>KR=paste(KLEM,"\test.txt",sep="")
>>indta <- readLines(KR, skip=46)  # not interested in the first 46
>>lines)
>>
>>pattern <- "^.*group (\\d+)[^:]*: *([-+0-9.eE]*).*$"
>>firstlines <- grep( pattern, indta )
>># Replace the matched portion (entire string) with the first capture #
>>string
>>v1 <- as.numeric( sub( pattern, "\\1", indta[ firstlines ] ) )
>># Replace the matched portion (entire string) with the second capture #
>>string
>>v2 <- as.numeric( sub( pattern, "\\2", indta[ firstlines ] ) )
>># Convert the lines just after the first lines to numeric
>>v3 <- as.numeric( indta[ firstlines + 1 ] )
>># put it all into a data frame
>>result <- data.frame( Group = v1, Mean = v2, SE = v3 )
>>
>>result
>>[1] Group Mean  SE
>><0 rows> (or 0-length row.names)
>>
>>Thank you in advance
>>
>>
>>On Tue, May 31, 2016 at 1:12 AM, Jeff Newmiller
>> wrote:
>>> Please learn to post in plain text (the setting is in your email
>>client...
>>> somewhere), as HTML is "What We See Is Not What You Saw" on this
>>mailing
>>> list.  In conjunction with that, try reading some of the fine
>>material
>>> mentioned in the Posting Guide about making reproducible examples
>>like this
>>> one:
>>>
>>> # You could read in a file
>>> # indta <- readLines( "out.txt" )
>>> # but there is no "current directory" in an email
>>> # so here I have used the dput() function to make source code
>>> # that creates a self-contained R object
>>>
>>> indta <- c(
>>> "Mean of weight  group 1, SE of mean  :  72.289037489555276",
>>> " 11.512956539215610",
>>> "Average weight of group 2, SE of Mean :  83.940053900595013",
>>> "  10.198495690144522",
>>> "group 3 mean , SE of Mean :78.310441258245469",
>>> " 13.015876679555",
>>> "Mean of weight of group 4, SE of Mean   :
>>76.967516495101669",
>>> " 12.1254882985", "")
>>>
>>> # Regular expression patterns are discussed all over the internet
>>> # in many places OTHER than R
>>> # You can start with ?regex, but there are many fine tutorials also
>>>
>>> pattern <- "^.*group (\\d+)[^:]*: *([-+0-9.eE]*).*$"
>>> # For this task the regex has to match the whole "first line" of each
>>set
>>> #  ^ =match starting at the beginning of the string
>>> #  .* =any character, zero or more times
>>> #  "group " =match these characters
>>> #  ( =first capture string starts here
>>> #  \\d = any digit (first backslash for R, second backslash for
>>regex)
>>> #  + =one or more of the preceding (any digit)
>>> #  ) =end of first capture string
>>> #  [^:] =any non-colon character
>>> #  * =zero or more of the preceding (non-colon character)
>>> #  : =match a colon exactly
>>> #  " *" =match zero or more spaces
>>> #  ( =second capture string starts here
>>> #  [ =start of a set of equally acceptable characters
>>> #  -+ =either of these characters are acceptable
>>> #  0-9 =any digit would be acceptable
>>> #  . =a period is acceptable (this is inside the [])
>>> #  eE =in case you get exponential notation input
>>> #  ] =end of the set of acceptable characters (number)
>>> #  * =number of acceptable characters can be zero or more
>>> #  ) =second capture string stops here
>>> #  .* =zero or more of any character (just in case)
>>> #  $ =at end of pattern, requires that the match reach the end
>>> # of the string
>>>
>>> # identify indexes of strings that match the pattern
>>> firstlines <- grep( pattern, indta )
>>> # Replace the matched portion (entire string) with the first capture
>>#
>>> string
>>> v1 <- as.numeric( sub( pattern, "\\1", indta[ firstlines ] ) )
>>> # Replace the matched portion (entire string) with the second capture
>>#
>>> string
>>> v2 <- as.numeric( sub( pattern, "\\2", indta[ firstlines ] ) )
>>> # Convert the lines just after the first lines to numeric
>>> v3 <- as.numeric( indta[ firstlines + 1 ] )
>>> # put it all into a data frame
>>> result <- data.frame( Group = v1, Mean = v2, SE = v3 )
>>>
>>> Figuring out how to deliver your result (output) is a separate
>>question that
>>> depends where you want it to go.
>>>
>>>
>>> On Mon, 30 May 2016, Val wrote:
>>>
 Hi all,

 I have a messy text file and from this text file I want extract some
 information
 here is the text file 

Re: [R] Extract from a text file

2016-05-31 Thread Jeff Newmiller
You need to go back and study how I made my solution reproducible and make your 
problem reproducible. 

You probably also ought to spend some time comparing the regex pattern to your 
actual data... the point of this list is to learn how to construct these 
solutions yourself.
-- 
Sent from my phone. Please excuse my brevity.

On May 31, 2016 6:26:31 PM PDT, Val  wrote:
>Thank you so much Jeff. It worked for this example.
>
>When I read it from a file (c:\data\test.txt) it did not work
>
>KLEM="c:\data"
>KR=paste(KLEM,"\test.txt",sep="")
>indta <- readLines(KR, skip=46)  # not interested in the first 46
>lines)
>
>pattern <- "^.*group (\\d+)[^:]*: *([-+0-9.eE]*).*$"
>firstlines <- grep( pattern, indta )
># Replace the matched portion (entire string) with the first capture #
>string
>v1 <- as.numeric( sub( pattern, "\\1", indta[ firstlines ] ) )
># Replace the matched portion (entire string) with the second capture #
>string
>v2 <- as.numeric( sub( pattern, "\\2", indta[ firstlines ] ) )
># Convert the lines just after the first lines to numeric
>v3 <- as.numeric( indta[ firstlines + 1 ] )
># put it all into a data frame
>result <- data.frame( Group = v1, Mean = v2, SE = v3 )
>
>result
>[1] Group Mean  SE
><0 rows> (or 0-length row.names)
>
>Thank you in advance
>
>
>On Tue, May 31, 2016 at 1:12 AM, Jeff Newmiller
> wrote:
>> Please learn to post in plain text (the setting is in your email
>client...
>> somewhere), as HTML is "What We See Is Not What You Saw" on this
>mailing
>> list.  In conjunction with that, try reading some of the fine
>material
>> mentioned in the Posting Guide about making reproducible examples
>like this
>> one:
>>
>> # You could read in a file
>> # indta <- readLines( "out.txt" )
>> # but there is no "current directory" in an email
>> # so here I have used the dput() function to make source code
>> # that creates a self-contained R object
>>
>> indta <- c(
>> "Mean of weight  group 1, SE of mean  :  72.289037489555276",
>> " 11.512956539215610",
>> "Average weight of group 2, SE of Mean :  83.940053900595013",
>> "  10.198495690144522",
>> "group 3 mean , SE of Mean :78.310441258245469",
>> " 13.015876679555",
>> "Mean of weight of group 4, SE of Mean   :
>76.967516495101669",
>> " 12.1254882985", "")
>>
>> # Regular expression patterns are discussed all over the internet
>> # in many places OTHER than R
>> # You can start with ?regex, but there are many fine tutorials also
>>
>> pattern <- "^.*group (\\d+)[^:]*: *([-+0-9.eE]*).*$"
>> # For this task the regex has to match the whole "first line" of each
>set
>> #  ^ =match starting at the beginning of the string
>> #  .* =any character, zero or more times
>> #  "group " =match these characters
>> #  ( =first capture string starts here
>> #  \\d = any digit (first backslash for R, second backslash for
>regex)
>> #  + =one or more of the preceding (any digit)
>> #  ) =end of first capture string
>> #  [^:] =any non-colon character
>> #  * =zero or more of the preceding (non-colon character)
>> #  : =match a colon exactly
>> #  " *" =match zero or more spaces
>> #  ( =second capture string starts here
>> #  [ =start of a set of equally acceptable characters
>> #  -+ =either of these characters are acceptable
>> #  0-9 =any digit would be acceptable
>> #  . =a period is acceptable (this is inside the [])
>> #  eE =in case you get exponential notation input
>> #  ] =end of the set of acceptable characters (number)
>> #  * =number of acceptable characters can be zero or more
>> #  ) =second capture string stops here
>> #  .* =zero or more of any character (just in case)
>> #  $ =at end of pattern, requires that the match reach the end
>> # of the string
>>
>> # identify indexes of strings that match the pattern
>> firstlines <- grep( pattern, indta )
>> # Replace the matched portion (entire string) with the first capture
>#
>> string
>> v1 <- as.numeric( sub( pattern, "\\1", indta[ firstlines ] ) )
>> # Replace the matched portion (entire string) with the second capture
>#
>> string
>> v2 <- as.numeric( sub( pattern, "\\2", indta[ firstlines ] ) )
>> # Convert the lines just after the first lines to numeric
>> v3 <- as.numeric( indta[ firstlines + 1 ] )
>> # put it all into a data frame
>> result <- data.frame( Group = v1, Mean = v2, SE = v3 )
>>
>> Figuring out how to deliver your result (output) is a separate
>question that
>> depends where you want it to go.
>>
>>
>> On Mon, 30 May 2016, Val wrote:
>>
>>> Hi all,
>>>
>>> I have a messy text file and from this text file I want extract some
>>> information
>>> here is the text file (out.txt).  One record has tow lines. The mean
>comes
>>> in the first line and the SE of the mean is on the second line. Here
>is
>>> the
>>> sample of the data.
>>>
>>> Mean of weight  group 1, SE of mean  :  72.289037489555276
>>> 11.512956539215610
>>> Average weight of group 2, SE of Mean :  83.940053900595013
>>>  

Re: [R] Extract from a text file

2016-05-31 Thread Val
Thank you so much Jeff. It worked for this example.

When I read it from a file (c:\data\test.txt) it did not work

KLEM="c:\data"
KR=paste(KLEM,"\test.txt",sep="")
indta <- readLines(KR, skip=46)  # not interested in the first 46 lines)

pattern <- "^.*group (\\d+)[^:]*: *([-+0-9.eE]*).*$"
firstlines <- grep( pattern, indta )
# Replace the matched portion (entire string) with the first capture # string
v1 <- as.numeric( sub( pattern, "\\1", indta[ firstlines ] ) )
# Replace the matched portion (entire string) with the second capture # string
v2 <- as.numeric( sub( pattern, "\\2", indta[ firstlines ] ) )
# Convert the lines just after the first lines to numeric
v3 <- as.numeric( indta[ firstlines + 1 ] )
# put it all into a data frame
result <- data.frame( Group = v1, Mean = v2, SE = v3 )

result
[1] Group Mean  SE
<0 rows> (or 0-length row.names)

Thank you in advance


On Tue, May 31, 2016 at 1:12 AM, Jeff Newmiller
 wrote:
> Please learn to post in plain text (the setting is in your email client...
> somewhere), as HTML is "What We See Is Not What You Saw" on this mailing
> list.  In conjunction with that, try reading some of the fine material
> mentioned in the Posting Guide about making reproducible examples like this
> one:
>
> # You could read in a file
> # indta <- readLines( "out.txt" )
> # but there is no "current directory" in an email
> # so here I have used the dput() function to make source code
> # that creates a self-contained R object
>
> indta <- c(
> "Mean of weight  group 1, SE of mean  :  72.289037489555276",
> " 11.512956539215610",
> "Average weight of group 2, SE of Mean :  83.940053900595013",
> "  10.198495690144522",
> "group 3 mean , SE of Mean :78.310441258245469",
> " 13.015876679555",
> "Mean of weight of group 4, SE of Mean   : 76.967516495101669",
> " 12.1254882985", "")
>
> # Regular expression patterns are discussed all over the internet
> # in many places OTHER than R
> # You can start with ?regex, but there are many fine tutorials also
>
> pattern <- "^.*group (\\d+)[^:]*: *([-+0-9.eE]*).*$"
> # For this task the regex has to match the whole "first line" of each set
> #  ^ =match starting at the beginning of the string
> #  .* =any character, zero or more times
> #  "group " =match these characters
> #  ( =first capture string starts here
> #  \\d = any digit (first backslash for R, second backslash for regex)
> #  + =one or more of the preceding (any digit)
> #  ) =end of first capture string
> #  [^:] =any non-colon character
> #  * =zero or more of the preceding (non-colon character)
> #  : =match a colon exactly
> #  " *" =match zero or more spaces
> #  ( =second capture string starts here
> #  [ =start of a set of equally acceptable characters
> #  -+ =either of these characters are acceptable
> #  0-9 =any digit would be acceptable
> #  . =a period is acceptable (this is inside the [])
> #  eE =in case you get exponential notation input
> #  ] =end of the set of acceptable characters (number)
> #  * =number of acceptable characters can be zero or more
> #  ) =second capture string stops here
> #  .* =zero or more of any character (just in case)
> #  $ =at end of pattern, requires that the match reach the end
> # of the string
>
> # identify indexes of strings that match the pattern
> firstlines <- grep( pattern, indta )
> # Replace the matched portion (entire string) with the first capture #
> string
> v1 <- as.numeric( sub( pattern, "\\1", indta[ firstlines ] ) )
> # Replace the matched portion (entire string) with the second capture #
> string
> v2 <- as.numeric( sub( pattern, "\\2", indta[ firstlines ] ) )
> # Convert the lines just after the first lines to numeric
> v3 <- as.numeric( indta[ firstlines + 1 ] )
> # put it all into a data frame
> result <- data.frame( Group = v1, Mean = v2, SE = v3 )
>
> Figuring out how to deliver your result (output) is a separate question that
> depends where you want it to go.
>
>
> On Mon, 30 May 2016, Val wrote:
>
>> Hi all,
>>
>> I have a messy text file and from this text file I want extract some
>> information
>> here is the text file (out.txt).  One record has tow lines. The mean comes
>> in the first line and the SE of the mean is on the second line. Here is
>> the
>> sample of the data.
>>
>> Mean of weight  group 1, SE of mean  :  72.289037489555276
>> 11.512956539215610
>> Average weight of group 2, SE of Mean :  83.940053900595013
>>  10.198495690144522
>> group 3 mean , SE of Mean :78.310441258245469
>> 13.015876679555
>> Mean of weight of group 4, SE of Mean   : 76.967516495101669
>> 12.1254882985
>>
>> I want produce the following  table. How do i read it first and then
>> produce a
>>
>>
>> Gr1  72.289037489555276   11.512956539215610
>> Gr2  83.940053900595013   10.198495690144522
>> Gr3  78.310441258245469   13.015876679555
>> Gr4  76.967516495101669   12.1254882985
>>
>>
>> Thank you in advance
>>
>> 

Re: [R] Variable labels and value labels

2016-05-31 Thread Jim Lemon
Hi Georg,
You may find the "add.value.labels" function in the prettyR package useful.

Jim

On Tue, May 31, 2016 at 10:00 PM,   wrote:
> Hi All,
>
> I am using R for social sciences. In this field I am used to use short
> variable names like "q1" for question 1, "q2" for question 2 and so on and
> label the variables like q1 : "Please tell us your age" or q2 : "Could you
> state us your household income?" or something similar indicating which
> question is stored in the variable.
>
> Similar I am used to label values like 1: "Less than 18 years", 2 : "18 to
> 30 years", 3 : "31 to 60 years" and 4 : "61 years and more".
>
> I know that the packages Hmisc and memisc have a functionality for this
> but these labeling functions are limited to the packages they were defined
> for. Using the question tests as variable names is possible but very
> inconvenient.
>
> I there another way for labeling variables and values in R?
>
> Kind regards
>
> Georg Maubach
>
> __
> 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-es] data.frame colname igraph

2016-05-31 Thread Javier Marcuzzi
Estimados

Tengo un problema, creo que sencillo, pero hay algo que hice mal, coloco el 
código, básicamente desde igraph se realiza un análisis, y se me ocurre tener 
un data.frame para ordenar los resultados, pero justo en ese punto aparece un 
problema.

¿Alguna sugerencia? 

> version
   _   
platform   x86_64-w64-mingw32  
arch   x86_64  
os mingw32 
system x86_64, mingw32 
status 
major  3   
minor  2.5 
year   2016
month  04  
day14  
svn rev70478   
language   R   
version.string R version 3.2.5 (2016-04-14)
nickname   Very, Very Secure Dishes
> number_edges_vertex <- as.data.frame(degree(datos.network))
> colnames(number_edges_vertex) <-c('var','grados')
Error in `colnames<-`(`*tmp*`, value = c("var", "grados")) : 
  'names' attribute [2] must be the same length as the vector [1]
> str(number_edges_vertex)
'data.frame':   216 obs. of  1 variable:
 $ degree(datos.network): num  9 10 7 9 7 10 10 12 8 9 ...


Javier Rubén Marcuzzi


[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Searching for antilog function

2016-05-31 Thread Richard M. Heiberger
Use power

> log(78,10)
[1] 1.892095
> 10^log(78,10)
[1] 78

On Tue, May 31, 2016 at 4:14 PM, Carlos  wrote:
> The following function can do the work as well
>
>  antilog<-function(lx,base)
>  {
>  lbx<-lx/log(exp(1),base=base)
>  result<-exp(lbx)
>  result
>  }
>
> This solution is based on the change of base formula which states that :
>
> log (x,base=b) = log(x,base=a)/log(b,base=a)
>
> The original logarithm is changed into natural logarithm and then the
> exponential function is employed
>
> The arguments are:
>
> 'lx', de logarithm we have.
> 'base', the base what was employed to obtain lx
>
> For example:
>
> log(78,10) = 1.892095
>
> Then the antllog is
>
> antilog(1.892095,10)
>
> 78
>
> As expected.
>
> __
> 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] Searching for antilog function

2016-05-31 Thread Carlos

The following function can do the work as well

 antilog<-function(lx,base)
 {
 lbx<-lx/log(exp(1),base=base)
 result<-exp(lbx)
 result
 }

This solution is based on the change of base formula which states that :

log (x,base=b) = log(x,base=a)/log(b,base=a)

The original logarithm is changed into natural logarithm and then the 
exponential function is employed


The arguments are:

'lx', de logarithm we have.
'base', the base what was employed to obtain lx

For example:

log(78,10) = 1.892095

Then the antllog is

antilog(1.892095,10)

78

As expected.

__
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] Regression and Sub-Groups Analysis in Metafor

2016-05-31 Thread Dan Kolubinski
Thank you, Bert.  That's perfect!  I will do.
On 31 May 2016 21:43, "Bert Gunter"  wrote:

> Briefly, as this is off-topic, and inline:
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Tue, May 31, 2016 at 11:32 AM, Dan Kolubinski 
> wrote:
> > That makes perfect sense.  Thank you, Michael.  I take your point about
> not
> > chasing the data and definitely see the risks involved in doing so.  Our
> > hypothesis was that the first, second and fourth variables would be
> > significant, but the third one (intervention) would not be.
>
> That is **not** a legitimate scientific hypothesis. Post to a
> statistical list like stats.stackexchange.com to learn why not.
>
> Cheers,
> Bert
>
>
>
>  I will
> > double-check the dataset to make sure that there are not any errors and
> > will report the results as we see them.  I much appreciate you taking the
> > time!
> >
> > Best wishes,
> > Dan
> >
> > On Tue, May 31, 2016 at 12:02 PM, Michael Dewey  >
> > wrote:
> >
> >> In-line
> >>
> >> On 30/05/2016 19:27, Dan Kolubinski wrote:
> >>
> >>> I am completing a meta-analysis on the effect of CBT on low self-esteem
> >>> and
> >>> I could use some help regarding the regression feature in metafor.
> Based
> >>> on the studies that I am using for the analysis, I identified 4
> potential
> >>> moderators that I want to explore:
> >>> - Some of the studies that I am using used RCTs to compare an
> intervention
> >>> with a waitlist and others used the pre-score as the control in a
> >>> single-group design.
> >>> - Some of the groups took place in one day and others took several
> weeks.
> >>> - There are three discernible interventions being represented
> >>> - The initial level of self-esteem varies
> >>>
> >>> Based on the above, I used this command to conduct a meta-analysis
> using
> >>> standarized mean differences:
> >>>
> >>>
> >>>
> >>> MetaMod<-rma(m1i=m1, m2i=m2, sd1i=sd1, sd2i=sd2, n1i=n1, n2i=n2,
> >>> mods=cbind(dur, rct, int, level),measure = "SMD")
> >>>
> >>>
> >> You could also say mods = ~ dur + rct + int + level
> >>
> >>
> >>>
> >>> Would this be the best command to use for what I described?  Also, what
> >>> could I add to the command so that the forest plot shows a sub-group
> >>> analysis using the 'dur' variable as a between-groups distinction?
> >>>
> >>>
> >> You have to adjust the forest plot by hand and then use add.polygon to
> >> add the summaries for each level of dur.
> >>
> >>
> >>> Also, with respect to the moderators, this is what was delivered:
> >>>
> >>>
> >>>
> >>> Test of Moderators (coefficient(s) 2,3,4,5):
> >>> QM(df = 4) = 8.7815, p-val = 0.0668
> >>>
> >>> Model Results:
> >>>
> >>>  estimate  se zvalpvalci.lb   ci.ub
> >>> intrcpt0.7005  0.6251   1.1207  0.2624  -0.5246  1.9256
> >>> dur0.5364  0.2411   2.2249  0.0261   0.0639  1.0090  *
> >>> rct   -0.3714  0.1951  -1.9035  0.0570  -0.7537  0.0110  .
> >>> int0.0730  0.1102   0.6628  0.5075  -0.1430  0.2890
> >>> level -0.2819  0.2139  -1.3180  0.1875  -0.7010  0.1373
> >>>
> >>> ---
> >>> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> >>>
> >>>
> >>>
> >> So the totality of moderators did not reach an arbitrary level of
> >> significance.
> >>
> >>
> >>> From this, can I interpret that the variable 'dur' (duration of
> 
> >>> intervention) has a significant effect and the variable 'rct' (whether
> a
> >>> study was an RCT or used pre-post scores) was just shy of being
> >>> statistically significant?  I mainly ask, because the QM-score has a
> >>> p-value of 0.0668, which I thought would mean that none of the
> moderators
> >>> would be significant.  Would I be better off just listing one or two
> >>> moderators instead of four?
> >>>
> >>>
> >> At the moment you get an overall test of the moderators which you had a
> >> scientific reason for using. If you start selecting based on the data
> >> you run the risk of ending up with confidence intervals and significance
> >> levels which do not have the meaning they are supposed to have.
> >>
> >>
> >> Much appreciated,
> >>> Dan
> >>>
> >>>   [[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.
> >>>
> >>>
> >> --
> >> Michael
> >> http://www.dewey.myzen.co.uk/home.html
> >>
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 

Re: [R] SEM GFI

2016-05-31 Thread Bert Gunter
Probably impossible to answer without your following the posting guide
and posting your code, etc.

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 Breathed in his "Bloom County" comic strip )


On Tue, May 31, 2016 at 11:28 AM, VINAY KULKARNI via R-help
 wrote:
> Hi,
> I am exactly replicating the SEM model which was done in SAS using Proc Calis 
> in R.
> Used sem package in R but not getting the GFI as same as in SAS 
> (approximately 15% difference)
> and also one link is insignificant but in SAS am getting significant.
> Searched through online in different blogs but not able to get the solution.
> Please let me know what might be the reason.
> Thanks,Vinay
>
>
>
> [[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] Regression and Sub-Groups Analysis in Metafor

2016-05-31 Thread Bert Gunter
Briefly, as this is off-topic, and inline:
Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, May 31, 2016 at 11:32 AM, Dan Kolubinski  wrote:
> That makes perfect sense.  Thank you, Michael.  I take your point about not
> chasing the data and definitely see the risks involved in doing so.  Our
> hypothesis was that the first, second and fourth variables would be
> significant, but the third one (intervention) would not be.

That is **not** a legitimate scientific hypothesis. Post to a
statistical list like stats.stackexchange.com to learn why not.

Cheers,
Bert



 I will
> double-check the dataset to make sure that there are not any errors and
> will report the results as we see them.  I much appreciate you taking the
> time!
>
> Best wishes,
> Dan
>
> On Tue, May 31, 2016 at 12:02 PM, Michael Dewey 
> wrote:
>
>> In-line
>>
>> On 30/05/2016 19:27, Dan Kolubinski wrote:
>>
>>> I am completing a meta-analysis on the effect of CBT on low self-esteem
>>> and
>>> I could use some help regarding the regression feature in metafor.  Based
>>> on the studies that I am using for the analysis, I identified 4 potential
>>> moderators that I want to explore:
>>> - Some of the studies that I am using used RCTs to compare an intervention
>>> with a waitlist and others used the pre-score as the control in a
>>> single-group design.
>>> - Some of the groups took place in one day and others took several weeks.
>>> - There are three discernible interventions being represented
>>> - The initial level of self-esteem varies
>>>
>>> Based on the above, I used this command to conduct a meta-analysis using
>>> standarized mean differences:
>>>
>>>
>>>
>>> MetaMod<-rma(m1i=m1, m2i=m2, sd1i=sd1, sd2i=sd2, n1i=n1, n2i=n2,
>>> mods=cbind(dur, rct, int, level),measure = "SMD")
>>>
>>>
>> You could also say mods = ~ dur + rct + int + level
>>
>>
>>>
>>> Would this be the best command to use for what I described?  Also, what
>>> could I add to the command so that the forest plot shows a sub-group
>>> analysis using the 'dur' variable as a between-groups distinction?
>>>
>>>
>> You have to adjust the forest plot by hand and then use add.polygon to
>> add the summaries for each level of dur.
>>
>>
>>> Also, with respect to the moderators, this is what was delivered:
>>>
>>>
>>>
>>> Test of Moderators (coefficient(s) 2,3,4,5):
>>> QM(df = 4) = 8.7815, p-val = 0.0668
>>>
>>> Model Results:
>>>
>>>  estimate  se zvalpvalci.lb   ci.ub
>>> intrcpt0.7005  0.6251   1.1207  0.2624  -0.5246  1.9256
>>> dur0.5364  0.2411   2.2249  0.0261   0.0639  1.0090  *
>>> rct   -0.3714  0.1951  -1.9035  0.0570  -0.7537  0.0110  .
>>> int0.0730  0.1102   0.6628  0.5075  -0.1430  0.2890
>>> level -0.2819  0.2139  -1.3180  0.1875  -0.7010  0.1373
>>>
>>> ---
>>> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>>>
>>>
>>>
>> So the totality of moderators did not reach an arbitrary level of
>> significance.
>>
>>
>>> From this, can I interpret that the variable 'dur' (duration of

>>> intervention) has a significant effect and the variable 'rct' (whether a
>>> study was an RCT or used pre-post scores) was just shy of being
>>> statistically significant?  I mainly ask, because the QM-score has a
>>> p-value of 0.0668, which I thought would mean that none of the moderators
>>> would be significant.  Would I be better off just listing one or two
>>> moderators instead of four?
>>>
>>>
>> At the moment you get an overall test of the moderators which you had a
>> scientific reason for using. If you start selecting based on the data
>> you run the risk of ending up with confidence intervals and significance
>> levels which do not have the meaning they are supposed to have.
>>
>>
>> Much appreciated,
>>> Dan
>>>
>>>   [[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.
>>>
>>>
>> --
>> Michael
>> http://www.dewey.myzen.co.uk/home.html
>>
>
> [[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 

Re: [R] R getting "Killed" while running VAR model

2016-05-31 Thread Bert Gunter
Standard reply (see posting guide):

Update to the current version of R (3.3.0 or so) and retry. Your
version is old -- this often leads to incompatibilities with newer
software versions.

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 Breathed in his "Bloom County" comic strip )


On Tue, May 31, 2016 at 11:29 AM, Vivek Singh  wrote:
> Hi,
>
> I am using VARS (vector autoregressive model). The process gets killed
> after running for sometime. Following is the output of R.
>
> vivek@isds-research:~/cloudAuction/padding/panel$ cat var.Rout
>
> R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
> Copyright (C) 2013 The R Foundation for Statistical Computing
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> You are welcome to redistribute it under certain conditions.
> Type 'license()' or 'licence()' for distribution details.
>
>   Natural language support but running in an English locale
>
> R is a collaborative project with many contributors.
> Type 'contributors()' for more information and
> 'citation()' on how to cite R or R packages in publications.
>
> Type 'demo()' for some demos, 'help()' for on-line help, or
> 'help.start()' for an HTML browser interface to help.
> Type 'q()' to quit R.
>
> [Previously saved workspace restored]
>
>> data=read.csv("output1.csv")
>> attach(data)
>> only_variables= subset(data, select=c(-date,-hour,-minute,-sec))
>>
>> library("vars")
> Loading required package: MASS
> Loading required package: strucchange
> Loading required package: zoo
>
> Attaching package: ‘zoo’
>
> The following objects are masked from ‘package:base’:
>
> as.Date, as.Date.numeric
>
> Loading required package: sandwich
> Loading required package: urca
> Loading required package: lmtest
>> summary(VAR(only_variables, p = 1, type ="both"))
> *Killed*
>
> [[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] R getting "Killed" while running VAR model

2016-05-31 Thread Uwe Ligges
Wild guess: You have huge and high dimensional VAR models, i.e. the 
matrices get huge and you use huge amounts of memory and you use more 
than what is available physically. The operating system protects itself 
by killing processes in such a case...


Best,
Uwe Ligges


On 31.05.2016 20:29, Vivek Singh wrote:

Hi,

I am using VARS (vector autoregressive model). The process gets killed
after running for sometime. Following is the output of R.

vivek@isds-research:~/cloudAuction/padding/panel$ cat var.Rout

R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]


data=read.csv("output1.csv")
attach(data)
only_variables= subset(data, select=c(-date,-hour,-minute,-sec))

library("vars")

Loading required package: MASS
Loading required package: strucchange
Loading required package: zoo

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

as.Date, as.Date.numeric

Loading required package: sandwich
Loading required package: urca
Loading required package: lmtest

summary(VAR(only_variables, p = 1, type ="both"))

*Killed*

[[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-es] sumar una variable con cast

2016-05-31 Thread Javier Marcuzzi
Perdón en la demora, literalmente me quedé dormido (estaba cansado). 

No quería colocar más librerías, pero yo se utilizar sqlite, aunque evito esta 
si hay fechas, me supo dar problemas, si usted maneja sql lo bueno de sqlite es 
el poder ayudarse con alguna herramienta de “wizard” para construir consultas 
complejas.

Javier Rubén Marcuzzi

De: Enrique RAMOS
Enviado: martes, 31 de mayo de 2016 15:57
Para: Enrique RAMOS; Carlos Ortega; Javier Marcuzzi
CC: Enrique RAMOS via R-help-es
Asunto: Re: [R-es] sumar una variable con cast


supongo que tendré que utilizar otra opción, porque con cast o dcast no lo logre
 
Saludos Enrique RAMOS

El Martes, 31 de mayo, 2016 13:33:24, Carlos Ortega  
escribió:

Hola,

Otra forma de hacerlo es así:

library(sqldf)
datIn <- read.table("EJEMPLO.csv", header =T, sep = ",")
sum_Evento <- sqldf("select sum(evento) as SumaAgregada from datIn group by
TIPO, grupo, col_que_quieras

De esta forma, al igual que en aggregate estás indicando explícitamente qué
variable suma y con qué variables agrupas.

Saludos,
Carlos Ortega
www.qualityexcellence.es



El 31 de mayo de 2016, 19:59, Javier Marcuzzi <
javier.ruben.marcu...@gmail.com> escribió:

> Estimado Enrique Ramos
>
> Yo podría decir ¿y data.table?. Hay muchas alternativas (no envié antes
> sin querer al correo).
>
> ¿Qué alternativa esta utilizando? Carlos Ortega y Carlos J. Gil Bellosta
> aportaron dos soluciones posibles, ¿Cuál le da problemas?
>
>
> Javier Rubén Marcuzzi
>
> De: Javier Marcuzzi
> Enviado: martes, 31 de mayo de 2016 14:57
> Para: Enrique RAMOS via R-help-es; R-help-es@r-project.org
> Asunto: RE: [R-es] sumar una variable con cast
>
> Estimado Enrique Ramos
>
> Yo podría decir ¿y data.table?. Hay muchas alternativas
>
> Javier Rubén Marcuzzi
>
> De: Enrique RAMOS via R-help-es
> Enviado: martes, 31 de mayo de 2016 14:03
> Para: R-help-es@r-project.org
> Asunto: Re: [R-es] sumar una variable con cast
>
> yo de nuevo, ahora se me presento otro problema en la base de datos del
> ejemplo solo tenia unas cuantas columnas mi base de datos tiene mas
> columnas ahora el detalle es como puedo elegir la columna que quiero que
> sume porque siempre me suma la que está en el extremo derechomil gracias
> Saludos
> Enrique RAMOS
>
>    El Lunes, 30 de mayo, 2016 14:06:11, Enrique RAMOS via R-help-es <
> r-help-es@r-project.org> escribió:
>
> agradezco la ayuda, el problema se resumía a que el Rstudio me ponía unos
> paréntesis de forma automática los quite y asunto solucionado Saludos
> Enrique RAMOS
>
>    El Lunes, 30 de mayo, 2016 12:26:33, Carlos J. Gil Bellosta <
> c...@datanalytics.com> escribió:
>
> Hola, ¿qué tal?
> Mira el argumento fun.aggregate en ?dcast.
> Un saludo,
> Carlos J. Gil Bellostahttp://www.datanalytics.com
> El 30 de mayo de 2016, 18:15, Enrique RAMOS via R-help-es <
> r-help-es@r-project.org> escribió:
>
> buenas tardes les envío este mensaje de ayuda porque ya le batalle mucho y
> no he podido hacerlo lo que necesito, tengo una tabla como la que pongo en
> el archivo anexo ejemplo he estado utilizando la instrucción cast de
> reshape2 para generar algo como lo que sigue
>
> | Suma de evento | Etiquetas de columna |  |  |  |  |
> | Etiquetas de fila | 2000 | 2001 | 2002 | 2003 | 2004 | Total general |
> | D | 2 | 3 | 1 | 4 | 1 | 11 |
> |    AU | 2 | 1 | 1 | 1 |  | 5 |
> |    CA |  | 1 |  |  |  | 1 |
> |    GV |  | 1 |  | 3 | 1 | 5 |
> | F | 3 | 4 | 1 | 3 | 3 | 14 |
> |    AU | 1 |  |  |  | 2 | 3 |
> |    CA | 1 | 3 |  |  |  | 4 |
> |    GV | 1 | 1 | 1 | 3 | 1 | 7 |
> | Total general | 5 | 7 | 2 | 7 | 4 | 25 |
>
>  donde se obtiene la suma de los eventos en función del tipo y grupo por
> cada año, lo que he logrado es obtener solo la cuenta de reglones
> de antemano mil gracias,
> Saludos Enrique RAMOSOficina de confiabilidadLAPEM-CFE
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>
>
>
>    [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>                [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>
>        [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es


    [[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es



[[alternative HTML version deleted]]

___
R-help-es mailing list

[R] SEM GFI

2016-05-31 Thread VINAY KULKARNI via R-help
Hi,
I am exactly replicating the SEM model which was done in SAS using Proc Calis 
in R.
Used sem package in R but not getting the GFI as same as in SAS (approximately 
15% difference)
and also one link is insignificant but in SAS am getting significant.
Searched through online in different blogs but not able to get the solution.
Please let me know what might be the reason.
Thanks,Vinay



[[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 getting "Killed" while running VAR model

2016-05-31 Thread Vivek Singh
Hi,

I am using VARS (vector autoregressive model). The process gets killed
after running for sometime. Following is the output of R.

vivek@isds-research:~/cloudAuction/padding/panel$ cat var.Rout

R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> data=read.csv("output1.csv")
> attach(data)
> only_variables= subset(data, select=c(-date,-hour,-minute,-sec))
>
> library("vars")
Loading required package: MASS
Loading required package: strucchange
Loading required package: zoo

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

as.Date, as.Date.numeric

Loading required package: sandwich
Loading required package: urca
Loading required package: lmtest
> summary(VAR(only_variables, p = 1, type ="both"))
*Killed*

[[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] Regression and Sub-Groups Analysis in Metafor

2016-05-31 Thread Dan Kolubinski
That makes perfect sense.  Thank you, Michael.  I take your point about not
chasing the data and definitely see the risks involved in doing so.  Our
hypothesis was that the first, second and fourth variables would be
significant, but the third one (intervention) would not be.  I will
double-check the dataset to make sure that there are not any errors and
will report the results as we see them.  I much appreciate you taking the
time!

Best wishes,
Dan

On Tue, May 31, 2016 at 12:02 PM, Michael Dewey 
wrote:

> In-line
>
> On 30/05/2016 19:27, Dan Kolubinski wrote:
>
>> I am completing a meta-analysis on the effect of CBT on low self-esteem
>> and
>> I could use some help regarding the regression feature in metafor.  Based
>> on the studies that I am using for the analysis, I identified 4 potential
>> moderators that I want to explore:
>> - Some of the studies that I am using used RCTs to compare an intervention
>> with a waitlist and others used the pre-score as the control in a
>> single-group design.
>> - Some of the groups took place in one day and others took several weeks.
>> - There are three discernible interventions being represented
>> - The initial level of self-esteem varies
>>
>> Based on the above, I used this command to conduct a meta-analysis using
>> standarized mean differences:
>>
>>
>>
>> MetaMod<-rma(m1i=m1, m2i=m2, sd1i=sd1, sd2i=sd2, n1i=n1, n2i=n2,
>> mods=cbind(dur, rct, int, level),measure = "SMD")
>>
>>
> You could also say mods = ~ dur + rct + int + level
>
>
>>
>> Would this be the best command to use for what I described?  Also, what
>> could I add to the command so that the forest plot shows a sub-group
>> analysis using the 'dur' variable as a between-groups distinction?
>>
>>
> You have to adjust the forest plot by hand and then use add.polygon to
> add the summaries for each level of dur.
>
>
>> Also, with respect to the moderators, this is what was delivered:
>>
>>
>>
>> Test of Moderators (coefficient(s) 2,3,4,5):
>> QM(df = 4) = 8.7815, p-val = 0.0668
>>
>> Model Results:
>>
>>  estimate  se zvalpvalci.lb   ci.ub
>> intrcpt0.7005  0.6251   1.1207  0.2624  -0.5246  1.9256
>> dur0.5364  0.2411   2.2249  0.0261   0.0639  1.0090  *
>> rct   -0.3714  0.1951  -1.9035  0.0570  -0.7537  0.0110  .
>> int0.0730  0.1102   0.6628  0.5075  -0.1430  0.2890
>> level -0.2819  0.2139  -1.3180  0.1875  -0.7010  0.1373
>>
>> ---
>> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>>
>>
>>
> So the totality of moderators did not reach an arbitrary level of
> significance.
>
>
>> From this, can I interpret that the variable 'dur' (duration of
>>>
>> intervention) has a significant effect and the variable 'rct' (whether a
>> study was an RCT or used pre-post scores) was just shy of being
>> statistically significant?  I mainly ask, because the QM-score has a
>> p-value of 0.0668, which I thought would mean that none of the moderators
>> would be significant.  Would I be better off just listing one or two
>> moderators instead of four?
>>
>>
> At the moment you get an overall test of the moderators which you had a
> scientific reason for using. If you start selecting based on the data
> you run the risk of ending up with confidence intervals and significance
> levels which do not have the meaning they are supposed to have.
>
>
> Much appreciated,
>> Dan
>>
>>   [[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.
>>
>>
> --
> Michael
> http://www.dewey.myzen.co.uk/home.html
>

[[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-es] sumar una variable con cast

2016-05-31 Thread Carlos Ortega
Hola,

con "reshape2" lo puedes hacer así:

> event_melt <- melt(datIn, id.vars = c("TIPO", "grupo"), measure.vars =
"evento")
> head(event_melt)
  TIPO grupo variable value
1DAU   evento 1
2DAU   evento 1
3FGV   evento 1
4FCA   evento 1
5FAU   evento 1
6DCA   evento 1
> event_sum  <- dcast(event_melt, TIPO ~ grupo, sum)
> event_sum
  TIPO AU CA GV
1D  5  1  5
2F  3  4  7

Saludos,
Carlos Ortega
www.qualityexcellence.es

El 31 de mayo de 2016, 20:57, Enrique RAMOS 
escribió:

>
> supongo que tendré que utilizar otra opción, porque con cast o dcast no lo
> logre
>
> Saludos Enrique RAMOS
>
>
> El Martes, 31 de mayo, 2016 13:33:24, Carlos Ortega <
> c...@qualityexcellence.es> escribió:
>
>
> Hola,
>
> Otra forma de hacerlo es así:
>
> library(sqldf)
> datIn <- read.table("EJEMPLO.csv", header =T, sep = ",")
> sum_Evento <- sqldf("select sum(evento) as SumaAgregada from datIn group by
> TIPO, grupo, col_que_quieras
>
> De esta forma, al igual que en aggregate estás indicando explícitamente qué
> variable suma y con qué variables agrupas.
>
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>
>
>
> El 31 de mayo de 2016, 19:59, Javier Marcuzzi <
> javier.ruben.marcu...@gmail.com> escribió:
>
> > Estimado Enrique Ramos
> >
> > Yo podría decir ¿y data.table?. Hay muchas alternativas (no envié antes
> > sin querer al correo).
> >
> > ¿Qué alternativa esta utilizando? Carlos Ortega y Carlos J. Gil Bellosta
> > aportaron dos soluciones posibles, ¿Cuál le da problemas?
> >
> >
> > Javier Rubén Marcuzzi
> >
> > De: Javier Marcuzzi
> > Enviado: martes, 31 de mayo de 2016 14:57
> > Para: Enrique RAMOS via R-help-es; R-help-es@r-project.org
> > Asunto: RE: [R-es] sumar una variable con cast
> >
> > Estimado Enrique Ramos
> >
> > Yo podría decir ¿y data.table?. Hay muchas alternativas
> >
> > Javier Rubén Marcuzzi
> >
> > De: Enrique RAMOS via R-help-es
> > Enviado: martes, 31 de mayo de 2016 14:03
> > Para: R-help-es@r-project.org
> > Asunto: Re: [R-es] sumar una variable con cast
> >
> > yo de nuevo, ahora se me presento otro problema en la base de datos del
> > ejemplo solo tenia unas cuantas columnas mi base de datos tiene mas
> > columnas ahora el detalle es como puedo elegir la columna que quiero que
> > sume porque siempre me suma la que está en el extremo derechomil gracias
> > Saludos
> > Enrique RAMOS
> >
> >El Lunes, 30 de mayo, 2016 14:06:11, Enrique RAMOS via R-help-es <
> > r-help-es@r-project.org> escribió:
> >
> > agradezco la ayuda, el problema se resumía a que el Rstudio me ponía unos
> > paréntesis de forma automática los quite y asunto solucionado Saludos
> > Enrique RAMOS
> >
> >El Lunes, 30 de mayo, 2016 12:26:33, Carlos J. Gil Bellosta <
> > c...@datanalytics.com> escribió:
> >
> > Hola, ¿qué tal?
> > Mira el argumento fun.aggregate en ?dcast.
> > Un saludo,
> > Carlos J. Gil Bellostahttp://www.datanalytics.com
> > El 30 de mayo de 2016, 18:15, Enrique RAMOS via R-help-es <
> > r-help-es@r-project.org> escribió:
> >
> > buenas tardes les envío este mensaje de ayuda porque ya le batalle mucho
> y
> > no he podido hacerlo lo que necesito, tengo una tabla como la que pongo
> en
> > el archivo anexo ejemplo he estado utilizando la instrucción cast de
> > reshape2 para generar algo como lo que sigue
> >
> > | Suma de evento | Etiquetas de columna |  |  |  |  |
> > | Etiquetas de fila | 2000 | 2001 | 2002 | 2003 | 2004 | Total general |
> > | D | 2 | 3 | 1 | 4 | 1 | 11 |
> > |AU | 2 | 1 | 1 | 1 |  | 5 |
> > |CA |  | 1 |  |  |  | 1 |
> > |GV |  | 1 |  | 3 | 1 | 5 |
> > | F | 3 | 4 | 1 | 3 | 3 | 14 |
> > |AU | 1 |  |  |  | 2 | 3 |
> > |CA | 1 | 3 |  |  |  | 4 |
> > |GV | 1 | 1 | 1 | 3 | 1 | 7 |
> > | Total general | 5 | 7 | 2 | 7 | 4 | 25 |
> >
> >  donde se obtiene la suma de los eventos en función del tipo y grupo por
> > cada año, lo que he logrado es obtener solo la cuenta de reglones
> > de antemano mil gracias,
> > Saludos Enrique RAMOSOficina de confiabilidadLAPEM-CFE
> > ___
> > R-help-es mailing list
> > R-help-es@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> >
> >
> >
> >
> >
> >[[alternative HTML version deleted]]
> >
> > ___
> > R-help-es mailing list
> > R-help-es@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> >
> >
> >[[alternative HTML version deleted]]
> >
> > ___
> > R-help-es mailing list
> > R-help-es@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> >
> >
> >
> >[[alternative HTML version deleted]]
> >
> > ___
> > R-help-es mailing list
> > R-help-es@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> >
>
>
>
> --
> Saludos,
> Carlos Ortega
> www.qualityexcellence.es
>
>
>   

Re: [R-es] sumar una variable con cast

2016-05-31 Thread Enrique RAMOS via R-help-es

supongo que tendré que utilizar otra opción, porque con cast o dcast no lo 
logre Saludos Enrique RAMOS 

El Martes, 31 de mayo, 2016 13:33:24, Carlos Ortega 
 escribió:
 

 Hola,

Otra forma de hacerlo es así:

library(sqldf)
datIn <- read.table("EJEMPLO.csv", header =T, sep = ",")
sum_Evento <- sqldf("select sum(evento) as SumaAgregada from datIn group by
TIPO, grupo, col_que_quieras

De esta forma, al igual que en aggregate estás indicando explícitamente qué
variable suma y con qué variables agrupas.

Saludos,
Carlos Ortega
www.qualityexcellence.es



El 31 de mayo de 2016, 19:59, Javier Marcuzzi <
javier.ruben.marcu...@gmail.com> escribió:

> Estimado Enrique Ramos
>
> Yo podría decir ¿y data.table?. Hay muchas alternativas (no envié antes
> sin querer al correo).
>
> ¿Qué alternativa esta utilizando? Carlos Ortega y Carlos J. Gil Bellosta
> aportaron dos soluciones posibles, ¿Cuál le da problemas?
>
>
> Javier Rubén Marcuzzi
>
> De: Javier Marcuzzi
> Enviado: martes, 31 de mayo de 2016 14:57
> Para: Enrique RAMOS via R-help-es; R-help-es@r-project.org
> Asunto: RE: [R-es] sumar una variable con cast
>
> Estimado Enrique Ramos
>
> Yo podría decir ¿y data.table?. Hay muchas alternativas
>
> Javier Rubén Marcuzzi
>
> De: Enrique RAMOS via R-help-es
> Enviado: martes, 31 de mayo de 2016 14:03
> Para: R-help-es@r-project.org
> Asunto: Re: [R-es] sumar una variable con cast
>
> yo de nuevo, ahora se me presento otro problema en la base de datos del
> ejemplo solo tenia unas cuantas columnas mi base de datos tiene mas
> columnas ahora el detalle es como puedo elegir la columna que quiero que
> sume porque siempre me suma la que está en el extremo derechomil gracias
> Saludos
> Enrique RAMOS
>
>    El Lunes, 30 de mayo, 2016 14:06:11, Enrique RAMOS via R-help-es <
> r-help-es@r-project.org> escribió:
>
> agradezco la ayuda, el problema se resumía a que el Rstudio me ponía unos
> paréntesis de forma automática los quite y asunto solucionado Saludos
> Enrique RAMOS
>
>    El Lunes, 30 de mayo, 2016 12:26:33, Carlos J. Gil Bellosta <
> c...@datanalytics.com> escribió:
>
> Hola, ¿qué tal?
> Mira el argumento fun.aggregate en ?dcast.
> Un saludo,
> Carlos J. Gil Bellostahttp://www.datanalytics.com
> El 30 de mayo de 2016, 18:15, Enrique RAMOS via R-help-es <
> r-help-es@r-project.org> escribió:
>
> buenas tardes les envío este mensaje de ayuda porque ya le batalle mucho y
> no he podido hacerlo lo que necesito, tengo una tabla como la que pongo en
> el archivo anexo ejemplo he estado utilizando la instrucción cast de
> reshape2 para generar algo como lo que sigue
>
> | Suma de evento | Etiquetas de columna |  |  |  |  |
> | Etiquetas de fila | 2000 | 2001 | 2002 | 2003 | 2004 | Total general |
> | D | 2 | 3 | 1 | 4 | 1 | 11 |
> |    AU | 2 | 1 | 1 | 1 |  | 5 |
> |    CA |  | 1 |  |  |  | 1 |
> |    GV |  | 1 |  | 3 | 1 | 5 |
> | F | 3 | 4 | 1 | 3 | 3 | 14 |
> |    AU | 1 |  |  |  | 2 | 3 |
> |    CA | 1 | 3 |  |  |  | 4 |
> |    GV | 1 | 1 | 1 | 3 | 1 | 7 |
> | Total general | 5 | 7 | 2 | 7 | 4 | 25 |
>
>  donde se obtiene la suma de los eventos en función del tipo y grupo por
> cada año, lo que he logrado es obtener solo la cuenta de reglones
> de antemano mil gracias,
> Saludos Enrique RAMOSOficina de confiabilidadLAPEM-CFE
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>
>
>
>    [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>                [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>
>        [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

    [[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

  
[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] sumar una variable con cast

2016-05-31 Thread Enrique RAMOS via R-help-es
si ya trabaje dos días en eso y siempre falla  Saludos Enrique RAMOS 

El Martes, 31 de mayo, 2016 13:55:06, Carlos J. Gil Bellosta 
 escribió:
 

 ?dcast. Mira los argumentos que admite la función. Uno de ellos se
llama value.var (o similar).

El día 31 de mayo de 2016, 20:52, Enrique RAMOS via R-help-es
 escribió:
> Estimado Javier Marcusi
> estoy intentando hacerlo con dcast ya logre que se realice la suma pero lo 
> hace con la ultima columna y yo requiero que se haga el mismo proceso con 
> varias columnas Saludos Enrique RAMOS
>
>    El Martes, 31 de mayo, 2016 13:00:28, Javier Marcuzzi 
> escribió:
>
>
>  Estimado Enrique Ramos
>
> Yo podría decir ¿y data.table?. Hay muchas alternativas (no envié antes sin 
> querer al correo).
>
> ¿Qué alternativa esta utilizando? Carlos Ortega y Carlos J. Gil Bellosta 
> aportaron dos soluciones posibles, ¿Cuál le da problemas?
>
>
> Javier Rubén Marcuzzi
>
> De: Javier Marcuzzi
> Enviado: martes, 31 de mayo de 2016 14:57
> Para: Enrique RAMOS via R-help-es; R-help-es@r-project.org
> Asunto: RE: [R-es] sumar una variable con cast
>
> Estimado Enrique Ramos
>
> Yo podría decir ¿y data.table?. Hay muchas alternativas
>
> Javier Rubén Marcuzzi
>
> De: Enrique RAMOS via R-help-es
> Enviado: martes, 31 de mayo de 2016 14:03
> Para: R-help-es@r-project.org
> Asunto: Re: [R-es] sumar una variable con cast
>
> yo de nuevo, ahora se me presento otro problema en la base de datos del 
> ejemplo solo tenia unas cuantas columnas mi base de datos tiene mas columnas 
> ahora el detalle es como puedo elegir la columna que quiero que sume porque 
> siempre me suma la que está en el extremo derechomil gracias
> Saludos
> Enrique RAMOS
>
>    El Lunes, 30 de mayo, 2016 14:06:11, Enrique RAMOS via R-help-es 
> escribió:
>
> agradezco la ayuda, el problema se resumía a que el Rstudio me ponía unos 
> paréntesis de forma automática los quite y asunto solucionado Saludos Enrique 
> RAMOS
>
>    El Lunes, 30 de mayo, 2016 12:26:33, Carlos J. Gil Bellosta 
> escribió:
>
> Hola, ¿qué tal?
> Mira el argumento fun.aggregate en ?dcast.
> Un saludo,
> Carlos J. Gil Bellostahttp://www.datanalytics.com
> El 30 de mayo de 2016, 18:15, Enrique RAMOS via R-help-es 
>  escribió:
>
> buenas tardes les envío este mensaje de ayuda porque ya le batalle mucho y no 
> he podido hacerlo lo que necesito, tengo una tabla como la que pongo en el 
> archivo anexo ejemplo he estado utilizando la instrucción cast de reshape2 
> para generar algo como lo que sigue
>
> | Suma de evento | Etiquetas de columna |  |  |  |  |
> | Etiquetas de fila | 2000 | 2001 | 2002 | 2003 | 2004 | Total general |
> | D | 2 | 3 | 1 | 4 | 1 | 11 |
> |    AU | 2 | 1 | 1 | 1 |  | 5 |
> |    CA |  | 1 |  |  |  | 1 |
> |    GV |  | 1 |  | 3 | 1 | 5 |
> | F | 3 | 4 | 1 | 3 | 3 | 14 |
> |    AU | 1 |  |  |  | 2 | 3 |
> |    CA | 1 | 3 |  |  |  | 4 |
> |    GV | 1 | 1 | 1 | 3 | 1 | 7 |
> | Total general | 5 | 7 | 2 | 7 | 4 | 25 |
>
>  donde se obtiene la suma de los eventos en función del tipo y grupo por cada 
>año, lo que he logrado es obtener solo la cuenta de reglones
> de antemano mil gracias,
> Saludos Enrique RAMOSOficina de confiabilidadLAPEM-CFE
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>
>
>
>    [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>                [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>
>    [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>        [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es

  
[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] sumar una variable con cast

2016-05-31 Thread Carlos J. Gil Bellosta
?dcast. Mira los argumentos que admite la función. Uno de ellos se
llama value.var (o similar).

El día 31 de mayo de 2016, 20:52, Enrique RAMOS via R-help-es
 escribió:
> Estimado Javier Marcusi
> estoy intentando hacerlo con dcast ya logre que se realice la suma pero lo 
> hace con la ultima columna y yo requiero que se haga el mismo proceso con 
> varias columnas Saludos Enrique RAMOS
>
> El Martes, 31 de mayo, 2016 13:00:28, Javier Marcuzzi 
>  escribió:
>
>
>  Estimado Enrique Ramos
>
> Yo podría decir ¿y data.table?. Hay muchas alternativas (no envié antes sin 
> querer al correo).
>
> ¿Qué alternativa esta utilizando? Carlos Ortega y Carlos J. Gil Bellosta 
> aportaron dos soluciones posibles, ¿Cuál le da problemas?
>
>
> Javier Rubén Marcuzzi
>
> De: Javier Marcuzzi
> Enviado: martes, 31 de mayo de 2016 14:57
> Para: Enrique RAMOS via R-help-es; R-help-es@r-project.org
> Asunto: RE: [R-es] sumar una variable con cast
>
> Estimado Enrique Ramos
>
> Yo podría decir ¿y data.table?. Hay muchas alternativas
>
> Javier Rubén Marcuzzi
>
> De: Enrique RAMOS via R-help-es
> Enviado: martes, 31 de mayo de 2016 14:03
> Para: R-help-es@r-project.org
> Asunto: Re: [R-es] sumar una variable con cast
>
> yo de nuevo, ahora se me presento otro problema en la base de datos del 
> ejemplo solo tenia unas cuantas columnas mi base de datos tiene mas columnas 
> ahora el detalle es como puedo elegir la columna que quiero que sume porque 
> siempre me suma la que está en el extremo derechomil gracias
> Saludos
> Enrique RAMOS
>
> El Lunes, 30 de mayo, 2016 14:06:11, Enrique RAMOS via R-help-es 
>  escribió:
>
> agradezco la ayuda, el problema se resumía a que el Rstudio me ponía unos 
> paréntesis de forma automática los quite y asunto solucionado Saludos Enrique 
> RAMOS
>
> El Lunes, 30 de mayo, 2016 12:26:33, Carlos J. Gil Bellosta 
>  escribió:
>
> Hola, ¿qué tal?
> Mira el argumento fun.aggregate en ?dcast.
> Un saludo,
> Carlos J. Gil Bellostahttp://www.datanalytics.com
> El 30 de mayo de 2016, 18:15, Enrique RAMOS via R-help-es 
>  escribió:
>
> buenas tardes les envío este mensaje de ayuda porque ya le batalle mucho y no 
> he podido hacerlo lo que necesito, tengo una tabla como la que pongo en el 
> archivo anexo ejemplo he estado utilizando la instrucción cast de reshape2 
> para generar algo como lo que sigue
>
> | Suma de evento | Etiquetas de columna |  |  |  |  |
> | Etiquetas de fila | 2000 | 2001 | 2002 | 2003 | 2004 | Total general |
> | D | 2 | 3 | 1 | 4 | 1 | 11 |
> | AU | 2 | 1 | 1 | 1 |  | 5 |
> | CA |  | 1 |  |  |  | 1 |
> | GV |  | 1 |  | 3 | 1 | 5 |
> | F | 3 | 4 | 1 | 3 | 3 | 14 |
> | AU | 1 |  |  |  | 2 | 3 |
> | CA | 1 | 3 |  |  |  | 4 |
> | GV | 1 | 1 | 1 | 3 | 1 | 7 |
> | Total general | 5 | 7 | 2 | 7 | 4 | 25 |
>
>  donde se obtiene la suma de los eventos en función del tipo y grupo por cada 
> año, lo que he logrado es obtener solo la cuenta de reglones
> de antemano mil gracias,
> Saludos Enrique RAMOSOficina de confiabilidadLAPEM-CFE
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Application of "merge" and "within"

2016-05-31 Thread Jeff Newmiller
Then perhaps your example should illustrate one of these "many situations" that 
trouble you but you are not being clear about. 
-- 
Sent from my phone. Please excuse my brevity.

On May 31, 2016 11:39:04 AM PDT, Santosh  wrote:
>I agree that performing merge outside the scope of "within" function,
>is
>pretty straight forward.. At times there are situations when many, if
>not
>all, of the operations are needed to be done within the scope the
>"within"
>environment..
>
>Thanks so much..
>Regards,
>Santosh
>
>On Tue, May 31, 2016 at 11:29 AM, Jeff Newmiller
>
>wrote:
>
>> What is complicated about merge( q, r )?
>>
>> Keep in mind that there is nothing simple about the rules for
>non-standard
>> evaluation of variables that within() uses, and it only gets more
>> complicated if you try to apply those rules to two data frames at
>once.
>> While I am not quite sure I understand what you really want, I
>suspect you
>> won't like the behavior you get when you pile too much context into
>> within().
>>
>> Note that dplyr::inner_join, which is designed to fit into a whole
>> ecosystem of NSE functions, uses strings to specify column names to
>join by
>> just like the merge "by" parameters do rather than using NSE, because
>it is
>> actually the least confusing approach when two data frames are being
>> referenced.
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> On May 31, 2016 10:50:24 AM PDT, Santosh 
>wrote:
>>>
>>> Thanks for response.. I want to merge two data frames using "within"
>>> function..the columns to used for merge could vary.. then the other
>>> commands become simpler..
>>>
>>> Thanks so much for your help!
>>> Santosh
>>>
>>> On Sat, May 28, 2016 at 1:53 PM, Duncan Murdoch
>
>>> wrote:
>>>
>>>  On 27/05/2016 7:00 PM, Santosh wrote:

  Dear Rxperts!
>
>  Is there a way to compute relative values.. using within()..
>function?
>
>  Any assistance/suggestions are highly welcome!!
>  Thanks again,
>  Santosh...
> --
>
>  A sample dataset and the computation "outside" within()  function
>is
>  shown..
>
>  q <- data.frame(GL =
> rep(paste("G",1:3,sep = ""),each = 50),
>  G  = rep(1:3,each = 50),
>  D = rep(paste("D",1:5,sep = ""),each = 30),
>  a = rep(1:15,each = 10),
>  t = rep(seq(10),15),
>  b = round(runif(150,10,20)))
>  r <- subset(q,!duplicated(paste(G,a)),sel=c(G,a,b))
>  names(r)[3] <- "bl"
>  s <- merge(q,r)
>   s$db <- s$b-s$bl
>
>  head(s,5)
>
>>
>>  G  a GL  D  t  b bl db
>  1   1  1 G1 D1  1 13 13  0
>  2   1  1 G1 D1  2 16 13  3
>  3   1  1 G1 D1  3 19 13  6
>  4   1  1 G1 D1  4 12 13 -1
>  5   1  1 G1 D1  5 19 13  6



  Just use

   s <- within(s, db <- b - bl)

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


[R-es] Hidrología con R

2016-05-31 Thread Javier Valdes Cantallopts (DGA)
Hola a todos
Quisiera saber cómo trabajar las funciones de distribución estadística (normal, 
log normal-Gamma y Gumbel), para datos de caudales. La idea es generar las 
curvas de variación estacional
Saludos a todos.




[R]




CONFIDENCIALIDAD: La información contenida en este mensaje y/o en los archivos 
adjuntos es de carácter confidencial o privilegiada y está destinada al uso 
exclusivo del emisor y/o de la persona o entidad a quien va dirigida. Si usted 
no es el destinatario, cualquier almacenamiento, divulgación, distribución o 
copia de esta información está estrictamente prohibido y sancionado por la ley. 
Si recibió este mensaje por error, por favor infórmenos inmediatamente 
respondiendo este mismo mensaje y borre todos los archivos adjuntos. Gracias.

CONFIDENTIAL NOTE: The information transmitted in this message and/or 
attachments is confidential and/or privileged and is intented only for use of 
the person or entity to whom it is addressed. If you are not the intended 
recipient, any retention, dissemination, distribution or copy of this 
information is strictly prohibited and sanctioned by law. If you received this 
message in error, please reply us this same message and delete this message and 
all attachments. Thank you.
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R] Application of "merge" and "within"

2016-05-31 Thread Santosh
I agree that performing merge outside the scope of "within" function, is
pretty straight forward.. At times there are situations when many, if not
all, of the operations are needed to be done within the scope the "within"
environment..

Thanks so much..
Regards,
Santosh

On Tue, May 31, 2016 at 11:29 AM, Jeff Newmiller 
wrote:

> What is complicated about merge( q, r )?
>
> Keep in mind that there is nothing simple about the rules for non-standard
> evaluation of variables that within() uses, and it only gets more
> complicated if you try to apply those rules to two data frames at once.
> While I am not quite sure I understand what you really want, I suspect you
> won't like the behavior you get when you pile too much context into
> within().
>
> Note that dplyr::inner_join, which is designed to fit into a whole
> ecosystem of NSE functions, uses strings to specify column names to join by
> just like the merge "by" parameters do rather than using NSE, because it is
> actually the least confusing approach when two data frames are being
> referenced.
> --
> Sent from my phone. Please excuse my brevity.
>
> On May 31, 2016 10:50:24 AM PDT, Santosh  wrote:
>>
>> Thanks for response.. I want to merge two data frames using "within"
>> function..the columns to used for merge could vary.. then the other
>> commands become simpler..
>>
>> Thanks so much for your help!
>> Santosh
>>
>> On Sat, May 28, 2016 at 1:53 PM, Duncan Murdoch 
>> wrote:
>>
>>  On 27/05/2016 7:00 PM, Santosh wrote:
>>>
>>>  Dear Rxperts!

  Is there a way to compute relative values.. using within().. function?

  Any assistance/suggestions are highly welcome!!
  Thanks again,
  Santosh...
 --

  A sample dataset and the computation "outside" within()  function is
  shown..

  q <- data.frame(GL =
 rep(paste("G",1:3,sep = ""),each = 50),
  G  = rep(1:3,each = 50),
  D = rep(paste("D",1:5,sep = ""),each = 30),
  a = rep(1:15,each = 10),
  t = rep(seq(10),15),
  b = round(runif(150,10,20)))
  r <- subset(q,!duplicated(paste(G,a)),sel=c(G,a,b))
  names(r)[3] <- "bl"
  s <- merge(q,r)
   s$db <- s$b-s$bl

  head(s,5)

>
>  G  a GL  D  t  b bl db
  1   1  1 G1 D1  1 13 13  0
  2   1  1 G1 D1  2 16 13  3
  3   1  1 G1 D1  3 19 13  6
  4   1  1 G1 D1  4 12 13 -1
  5   1  1 G1 D1  5 19 13  6
>>>
>>>
>>>
>>>  Just use
>>>
>>>   s <- within(s, db <- b - bl)
>>>
>>>  Duncan Murdoch
>>
>>
>>
>>
>>  [[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-es] sumar una variable con cast

2016-05-31 Thread Carlos Ortega
Hola,

Otra forma de hacerlo es así:

library(sqldf)
datIn <- read.table("EJEMPLO.csv", header =T, sep = ",")
sum_Evento <- sqldf("select sum(evento) as SumaAgregada from datIn group by
TIPO, grupo, col_que_quieras

De esta forma, al igual que en aggregate estás indicando explícitamente qué
variable suma y con qué variables agrupas.

Saludos,
Carlos Ortega
www.qualityexcellence.es



El 31 de mayo de 2016, 19:59, Javier Marcuzzi <
javier.ruben.marcu...@gmail.com> escribió:

> Estimado Enrique Ramos
>
> Yo podría decir ¿y data.table?. Hay muchas alternativas (no envié antes
> sin querer al correo).
>
> ¿Qué alternativa esta utilizando? Carlos Ortega y Carlos J. Gil Bellosta
> aportaron dos soluciones posibles, ¿Cuál le da problemas?
>
>
> Javier Rubén Marcuzzi
>
> De: Javier Marcuzzi
> Enviado: martes, 31 de mayo de 2016 14:57
> Para: Enrique RAMOS via R-help-es; R-help-es@r-project.org
> Asunto: RE: [R-es] sumar una variable con cast
>
> Estimado Enrique Ramos
>
> Yo podría decir ¿y data.table?. Hay muchas alternativas
>
> Javier Rubén Marcuzzi
>
> De: Enrique RAMOS via R-help-es
> Enviado: martes, 31 de mayo de 2016 14:03
> Para: R-help-es@r-project.org
> Asunto: Re: [R-es] sumar una variable con cast
>
> yo de nuevo, ahora se me presento otro problema en la base de datos del
> ejemplo solo tenia unas cuantas columnas mi base de datos tiene mas
> columnas ahora el detalle es como puedo elegir la columna que quiero que
> sume porque siempre me suma la que está en el extremo derechomil gracias
> Saludos
> Enrique RAMOS
>
> El Lunes, 30 de mayo, 2016 14:06:11, Enrique RAMOS via R-help-es <
> r-help-es@r-project.org> escribió:
>
> agradezco la ayuda, el problema se resumía a que el Rstudio me ponía unos
> paréntesis de forma automática los quite y asunto solucionado Saludos
> Enrique RAMOS
>
> El Lunes, 30 de mayo, 2016 12:26:33, Carlos J. Gil Bellosta <
> c...@datanalytics.com> escribió:
>
> Hola, ¿qué tal?
> Mira el argumento fun.aggregate en ?dcast.
> Un saludo,
> Carlos J. Gil Bellostahttp://www.datanalytics.com
> El 30 de mayo de 2016, 18:15, Enrique RAMOS via R-help-es <
> r-help-es@r-project.org> escribió:
>
> buenas tardes les envío este mensaje de ayuda porque ya le batalle mucho y
> no he podido hacerlo lo que necesito, tengo una tabla como la que pongo en
> el archivo anexo ejemplo he estado utilizando la instrucción cast de
> reshape2 para generar algo como lo que sigue
>
> | Suma de evento | Etiquetas de columna |  |  |  |  |
> | Etiquetas de fila | 2000 | 2001 | 2002 | 2003 | 2004 | Total general |
> | D | 2 | 3 | 1 | 4 | 1 | 11 |
> | AU | 2 | 1 | 1 | 1 |  | 5 |
> | CA |  | 1 |  |  |  | 1 |
> | GV |  | 1 |  | 3 | 1 | 5 |
> | F | 3 | 4 | 1 | 3 | 3 | 14 |
> | AU | 1 |  |  |  | 2 | 3 |
> | CA | 1 | 3 |  |  |  | 4 |
> | GV | 1 | 1 | 1 | 3 | 1 | 7 |
> | Total general | 5 | 7 | 2 | 7 | 4 | 25 |
>
>  donde se obtiene la suma de los eventos en función del tipo y grupo por
> cada año, lo que he logrado es obtener solo la cuenta de reglones
> de antemano mil gracias,
> Saludos Enrique RAMOSOficina de confiabilidadLAPEM-CFE
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Application of "merge" and "within"

2016-05-31 Thread Jeff Newmiller
What is complicated about merge( q, r )?

Keep in mind that there is nothing simple about the rules for non-standard 
evaluation of variables that within() uses, and it only gets more complicated 
if you try to apply those rules to two data frames at once. While I am not 
quite sure I understand what you really want, I suspect you won't like the 
behavior you get when you pile too much context into within(). 

Note that dplyr::inner_join, which is designed to fit into a whole ecosystem of 
NSE functions, uses strings to specify column names to join by just like the 
merge "by" parameters do rather than using NSE, because it is actually the 
least confusing approach when two data frames are being referenced. 
-- 
Sent from my phone. Please excuse my brevity.

On May 31, 2016 10:50:24 AM PDT, Santosh  wrote:
>Thanks for response.. I want to merge two data frames using "within"
>function..the columns to used for merge could vary.. then the other
>commands become simpler..
>
>Thanks so much for your help!
>Santosh
>
>On Sat, May 28, 2016 at 1:53 PM, Duncan Murdoch
>
>wrote:
>
>> On 27/05/2016 7:00 PM, Santosh wrote:
>>
>>> Dear Rxperts!
>>>
>>> Is there a way to compute relative values.. using within()..
>function?
>>>
>>> Any assistance/suggestions are highly welcome!!
>>> Thanks again,
>>> Santosh...
>>> ___
>>> A sample dataset and the computation "outside" within()  function is
>>> shown..
>>>
>>> q <- data.frame(GL = rep(paste("G",1:3,sep = ""),each = 50),
>>> G  = rep(1:3,each = 50),
>>> D = rep(paste("D",1:5,sep = ""),each = 30),
>>> a = rep(1:15,each = 10),
>>> t = rep(seq(10),15),
>>> b = round(runif(150,10,20)))
>>> r <- subset(q,!duplicated(paste(G,a)),sel=c(G,a,b))
>>> names(r)[3] <- "bl"
>>> s <- merge(q,r)
>>>  s$db <- s$b-s$bl
>>>
>>> head(s,5)

>>> G  a GL  D  t  b bl db
>>> 1   1  1 G1 D1  1 13 13  0
>>> 2   1  1 G1 D1  2 16 13  3
>>> 3   1  1 G1 D1  3 19 13  6
>>> 4   1  1 G1 D1  4 12 13 -1
>>> 5   1  1 G1 D1  5 19 13  6
>>>
>>
>> Just use
>>
>>  s <- within(s, db <- b - bl)
>>
>> Duncan Murdoch
>>
>>
>
>   [[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-es] sumar una variable con cast

2016-05-31 Thread Javier Marcuzzi
Estimado Enrique Ramos

Yo podría decir ¿y data.table?. Hay muchas alternativas (no envié antes sin 
querer al correo).

¿Qué alternativa esta utilizando? Carlos Ortega y Carlos J. Gil Bellosta 
aportaron dos soluciones posibles, ¿Cuál le da problemas? 


Javier Rubén Marcuzzi

De: Javier Marcuzzi
Enviado: martes, 31 de mayo de 2016 14:57
Para: Enrique RAMOS via R-help-es; R-help-es@r-project.org
Asunto: RE: [R-es] sumar una variable con cast

Estimado Enrique Ramos

Yo podría decir ¿y data.table?. Hay muchas alternativas

Javier Rubén Marcuzzi

De: Enrique RAMOS via R-help-es
Enviado: martes, 31 de mayo de 2016 14:03
Para: R-help-es@r-project.org
Asunto: Re: [R-es] sumar una variable con cast

yo de nuevo, ahora se me presento otro problema en la base de datos del ejemplo 
solo tenia unas cuantas columnas mi base de datos tiene mas columnas ahora el 
detalle es como puedo elegir la columna que quiero que sume porque siempre me 
suma la que está en el extremo derechomil gracias
Saludos 
Enrique RAMOS 

    El Lunes, 30 de mayo, 2016 14:06:11, Enrique RAMOS via R-help-es 
 escribió:

agradezco la ayuda, el problema se resumía a que el Rstudio me ponía unos 
paréntesis de forma automática los quite y asunto solucionado Saludos Enrique 
RAMOS 

    El Lunes, 30 de mayo, 2016 12:26:33, Carlos J. Gil Bellosta 
 escribió:

Hola, ¿qué tal?
Mira el argumento fun.aggregate en ?dcast.
Un saludo,
Carlos J. Gil Bellostahttp://www.datanalytics.com
El 30 de mayo de 2016, 18:15, Enrique RAMOS via R-help-es 
 escribió:

buenas tardes les envío este mensaje de ayuda porque ya le batalle mucho y no 
he podido hacerlo lo que necesito, tengo una tabla como la que pongo en el 
archivo anexo ejemplo he estado utilizando la instrucción cast de reshape2 para 
generar algo como lo que sigue 

| Suma de evento | Etiquetas de columna |  |  |  |  |
| Etiquetas de fila | 2000 | 2001 | 2002 | 2003 | 2004 | Total general |
| D | 2 | 3 | 1 | 4 | 1 | 11 |
| AU | 2 | 1 | 1 | 1 |  | 5 |
| CA |  | 1 |  |  |  | 1 |
| GV |  | 1 |  | 3 | 1 | 5 |
| F | 3 | 4 | 1 | 3 | 3 | 14 |
| AU | 1 |  |  |  | 2 | 3 |
| CA | 1 | 3 |  |  |  | 4 |
| GV | 1 | 1 | 1 | 3 | 1 | 7 |
| Total general | 5 | 7 | 2 | 7 | 4 | 25 |

 donde se obtiene la suma de los eventos en función del tipo y grupo por cada 
año, lo que he logrado es obtener solo la cuenta de reglones
de antemano mil gracias, 
Saludos Enrique RAMOSOficina de confiabilidadLAPEM-CFE
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es




  
    [[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

  
    [[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es



[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Application of "merge" and "within"

2016-05-31 Thread Santosh
Thanks for response.. I want to merge two data frames using "within"
function..the columns to used for merge could vary.. then the other
commands become simpler..

Thanks so much for your help!
Santosh

On Sat, May 28, 2016 at 1:53 PM, Duncan Murdoch 
wrote:

> On 27/05/2016 7:00 PM, Santosh wrote:
>
>> Dear Rxperts!
>>
>> Is there a way to compute relative values.. using within().. function?
>>
>> Any assistance/suggestions are highly welcome!!
>> Thanks again,
>> Santosh...
>> ___
>> A sample dataset and the computation "outside" within()  function is
>> shown..
>>
>> q <- data.frame(GL = rep(paste("G",1:3,sep = ""),each = 50),
>> G  = rep(1:3,each = 50),
>> D = rep(paste("D",1:5,sep = ""),each = 30),
>> a = rep(1:15,each = 10),
>> t = rep(seq(10),15),
>> b = round(runif(150,10,20)))
>> r <- subset(q,!duplicated(paste(G,a)),sel=c(G,a,b))
>> names(r)[3] <- "bl"
>> s <- merge(q,r)
>>  s$db <- s$b-s$bl
>>
>> head(s,5)
>>>
>> G  a GL  D  t  b bl db
>> 1   1  1 G1 D1  1 13 13  0
>> 2   1  1 G1 D1  2 16 13  3
>> 3   1  1 G1 D1  3 19 13  6
>> 4   1  1 G1 D1  4 12 13 -1
>> 5   1  1 G1 D1  5 19 13  6
>>
>
> Just use
>
>  s <- within(s, db <- b - bl)
>
> Duncan Murdoch
>
>

[[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] Fortune candidate: Re: Whether statistical background is must to learn R language

2016-05-31 Thread Achim Zeileis

Thanks, Sarah, added now in the devel-package on R-Forge.
Z

On Tue, 31 May 2016, Sarah Goslee wrote:


On Tue, May 31, 2016 at 11:09 AM, Jeff Newmiller
 wrote:



However, please don't apply R like a magic answers box, because you can mislead 
others and cause harm.


__
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] sandwich package: HAC estimators

2016-05-31 Thread Achim Zeileis

On Tue, 31 May 2016, T.Riedle wrote:


Many thanks for your feedback.

If I get the code for the waldtest right I can calculate the Chi2 and 
the F statistic using waldtest().


Yes. In a logit model you would usually use the chi-squared statistic.

Can I use the waldtest() without using bread()/ estfun()? That is, I 
estimate the logit regression using glm() e.g. logit<-glm(...) and 
insert logit into the waldtest() function.


Does that work to get chi2 under HAC standard errors?


I'm not sure what you mean here but I include a worked example. Caveat: 
The data I use are cross-section data with an overly simplified set of 
regressors. So none of this makes sense for the application - but it shows 
how to use the commands.


## load AER package which provides the example data
## and automatically loads "lmtest" and "sandwich"
library("AER")
data("PSID1976", package = "AER")

## fit a simple logit model and obtain marginal Wald tests
## for the coefficients and an overall chi-squared statistic
m <- glm(participation ~ education, data = PSID1976, family = binomial)
summary(m)
anova(m, test = "Chisq")

## replicate the same statistics with coeftest() and lrtest()
coeftest(m)
lrtest(m)

## the likelihood ratio test is asymptotically equivalent
## to the Wald test leading to a similar chi-squared test here
waldtest(m)

## obtain HAC-corrected (Newey-West) versions of the Wald tests
coeftest(m, vcov = NeweyWest)
waldtest(m, vcov = NeweyWest)

Instead of NeweyWest other covariance estimators (e.g., vcovHAC, kernHAC, 
etc.) can also be plugged in.


hth,
Z



From: Achim Zeileis 
Sent: 31 May 2016 13:18
To: T.Riedle
Cc: r-help@r-project.org
Subject: Re: [R] sandwich package: HAC estimators

On Tue, 31 May 2016, T.Riedle wrote:


I understood. But how do I get the R2 an Chi2 of my logistic regression
under HAC standard errors? I would like to create a table with HAC SE
via e.g. stargazer().

Do I get these information by using the functions

bread.lrm <- function(x, ...) vcov(x) * nobs(x)
estfun.lrm <- function(x, ...) residuals(x, "score")?

Do I need to use the coeftest() in this case?


The bread()/estfun() methods enable application of vcovHAC(), kernHAC(),
NeweyWest(). This in turn enables the application of coeftest(),
waldtest(), or linearHypothesis() with a suitable vcov argument.

All of these give you different kinds of Wald tests with HAC covariances
including marginal tests of individual coefficients (coeftest) or global
tests of nested models (waldtest/linearHypothesis). The latter can serve
as replacement for the "chi-squared test". For pseudo-R-squared values I'm
not familiar with HAC-adjusted variants.

And I'm not sure whether there is a LaTeX export solution that encompasses
all of these aspects simultaneously.



From: R-help  on behalf of Achim Zeileis 

Sent: 31 May 2016 08:36
To: Leonardo Ferreira Fontenelle
Cc: r-help@r-project.org
Subject: Re: [R] sandwich package: HAC estimators

On Mon, 30 May 2016, Leonardo Ferreira Fontenelle wrote:


Em Sáb 28 mai. 2016, às 15:50, Achim Zeileis escreveu:

On Sat, 28 May 2016, T.Riedle wrote:

I thought it would be useful to incorporate the HAC consistent
covariance matrix into the logistic regression directly and generate an
output of coefficients and the corresponding standard errors. Is there
such a function in R?


Not with HAC standard errors, I think.


Don't glmrob() and summary.glmrob(), from robustbase, do that?


No, they implement a different concept of robustness. See also
https://CRAN.R-project.org/view=Robust

glmrob() implements GLMs that are "robust" or rather "resistant" to
outliers and other observations that do not come from the main model
equation. Instead of maximum likelihood (ML) estimation other estimation
techniques (along with corresponding covariances/standard errors) are
used.

In contrast, the OP asked for HAC standard errors. The motivation for
these is that the main model equation does hold for all observations but
that the observations might be heteroskedastic and/or autocorrelated. In
this situation, ML estimation is still consistent (albeit not efficient)
but the covariance matrix estimate needs to be adjusted.



Leonardo Ferreira Fontenelle, MD, MPH

__
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] How to import sensitive data when multiple users collaborate on R-script?

2016-05-31 Thread MacQueen, Don
There are lots of ways to handle this kind of thing, and the other
suggestions are good. But specific to your "something like" idea, see the
output of

  Sys.info()

in particular
  Sys.info()['nodename']
  Sys.info()['user']

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 5/31/16, 3:44 AM, "R-help on behalf of Nikolai Stenfors"

wrote:

>We conduct medical research and our datafiles therefore contain sensitive
>data, not to be shared in the cloud (Dropboc, Box, Drive, Bitbucket,
>GitHub).
>When we collaborate on a r-analysis-script, we stumble upon the following
>annoyance. Researcher 1 has a line in the script importing the sensitive
>data from his/her personal computer. Researcher 2 has to put an additional
>line importing the data from his/her personal computer. Thus, we have
>lines
>in the script that are unnecessery for one or the other researcher. How
>can
>we avoid this? Is there another way of conducting the collaboration. Other
>workflow? 
>
>I'm perhaps looking for something like:
>"If the script is run on researcher 1 computer, load file from this
>directory. If the script is run on researcher 2 computer, load data from
>that directory". 
>
>Example:
>## Import data-
># Researcher 1 import data from laptop1, unnecessery line for Researcher 2
>data <- read.table("/path/to_researcher1_computer/sensitive_data.csv")
>
># Researcher 2 import data from laptop2 (unnecessery line for Researcher
>1)
>data <- read.table("/path/to_researcher2_computer/sensitive_data.csv")
>
>## Clean data
>data$var1 <- NULL
>
>## Analyze data
>boxplot(data$var2)
>
>__
>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] Fortune candidate: Re: Whether statistical background is must to learn R language

2016-05-31 Thread Sarah Goslee
On Tue, May 31, 2016 at 11:09 AM, Jeff Newmiller
 wrote:
>
>
> However, please don't apply R like a magic answers box, because you can 
> mislead others and cause harm.

__
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] Whether statistical background is must to learn R language

2016-05-31 Thread Jeff Newmiller
In every activity, knowing something about it allows you to avoid repeating the 
mistakes of the past. There are non-statistical uses of programming languages, 
so you could use it for domains you are familiar with. Or you could see some 
intriguing statistical analysis and study in that area to understand it so you 
can apply it.  The difficulty in such ad-hoc approaches to learning is that it 
can be inefficient and leave big holes in your knowledge. Of course, you may 
have limited options at this point, so inefficient may be better than not at 
all.  To minimize the risk of missing a significant point, you should try to be 
thorough in your self-study and use expert consultation if you are unsure. 
(This list is not a good venue for purely theoretical questions, but such 
venues like stats.stackexchange.com or your local university do exist.)

However, please don't apply R like a magic answers box, because you can mislead 
others and cause harm. 
-- 
Sent from my phone. Please excuse my brevity.

On May 31, 2016 12:22:59 AM PDT, Prasad Kale  
wrote:
>Hi,
>
>I am very new to R and just started learning R. But i am not from
>statistical background so can i learn R or to learn R statistical
>background is must.
>
>Please guide.
>
>Thanks in Advance
>Prasad
>
>   [[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] sandwich package: HAC estimators

2016-05-31 Thread T.Riedle
Many thanks for your feedback.

If I get the code for the waldtest right I can calculate the Chi2 and the F 
statistic using waldtest(). Can I use the waldtest() without using bread()/ 
estfun()? That is, I estimate the logit regression using glm() e.g. 
logit<-glm(...) and insert logit into the waldtest() function.

Does that work to get chi2 under HAC standard errors?


From: Achim Zeileis 
Sent: 31 May 2016 13:18
To: T.Riedle
Cc: r-help@r-project.org
Subject: Re: [R] sandwich package: HAC estimators

On Tue, 31 May 2016, T.Riedle wrote:

> I understood. But how do I get the R2 an Chi2 of my logistic regression
> under HAC standard errors? I would like to create a table with HAC SE
> via e.g. stargazer().
>
> Do I get these information by using the functions
>
> bread.lrm <- function(x, ...) vcov(x) * nobs(x)
> estfun.lrm <- function(x, ...) residuals(x, "score")?
>
> Do I need to use the coeftest() in this case?

The bread()/estfun() methods enable application of vcovHAC(), kernHAC(),
NeweyWest(). This in turn enables the application of coeftest(),
waldtest(), or linearHypothesis() with a suitable vcov argument.

All of these give you different kinds of Wald tests with HAC covariances
including marginal tests of individual coefficients (coeftest) or global
tests of nested models (waldtest/linearHypothesis). The latter can serve
as replacement for the "chi-squared test". For pseudo-R-squared values I'm
not familiar with HAC-adjusted variants.

And I'm not sure whether there is a LaTeX export solution that encompasses
all of these aspects simultaneously.

> 
> From: R-help  on behalf of Achim Zeileis 
> 
> Sent: 31 May 2016 08:36
> To: Leonardo Ferreira Fontenelle
> Cc: r-help@r-project.org
> Subject: Re: [R] sandwich package: HAC estimators
>
> On Mon, 30 May 2016, Leonardo Ferreira Fontenelle wrote:
>
>> Em Sáb 28 mai. 2016, às 15:50, Achim Zeileis escreveu:
>>> On Sat, 28 May 2016, T.Riedle wrote:
 I thought it would be useful to incorporate the HAC consistent
 covariance matrix into the logistic regression directly and generate an
 output of coefficients and the corresponding standard errors. Is there
 such a function in R?
>>>
>>> Not with HAC standard errors, I think.
>>
>> Don't glmrob() and summary.glmrob(), from robustbase, do that?
>
> No, they implement a different concept of robustness. See also
> https://CRAN.R-project.org/view=Robust
>
> glmrob() implements GLMs that are "robust" or rather "resistant" to
> outliers and other observations that do not come from the main model
> equation. Instead of maximum likelihood (ML) estimation other estimation
> techniques (along with corresponding covariances/standard errors) are
> used.
>
> In contrast, the OP asked for HAC standard errors. The motivation for
> these is that the main model equation does hold for all observations but
> that the observations might be heteroskedastic and/or autocorrelated. In
> this situation, ML estimation is still consistent (albeit not efficient)
> but the covariance matrix estimate needs to be adjusted.
>
>>
>> Leonardo Ferreira Fontenelle, MD, MPH
>>
>> __
>> 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-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] Whether statistical background is must to learn R language

2016-05-31 Thread Michael Dewey

Dear Prasad

If you want to use R to do statistics then statistical knowledge is 
essential. If you want to use R to do one of the many, many other things 
it can do then you only need knowledge of whichever of those is your target.


On 31/05/2016 08:22, Prasad Kale wrote:

Hi,

I am very new to R and just started learning R. But i am not from
statistical background so can i learn R or to learn R statistical
background is must.

Please guide.

Thanks in Advance
Prasad

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



--
Michael
http://www.dewey.myzen.co.uk/home.html

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


[R] Return Misalignment in Return.portfolio function in PerformanceAnalytics Package

2016-05-31 Thread Suphajak Ngamlak
Dear R users,



I am trying to calculate NAV of portfolio using Return.portfolio function in 
PerformanceAnalytics Package. I am having difficulties with how I should 
specify weight in the function.

I tried to replicate using fixed weights with rebalance_on = "months" by 
specifying weights explicitly. However, the returns I got were different



Below is the example of the code



# clear memory



rm(list=ls())



library(quantmod)

library(PerformanceAnalytics)



symbols = c(

  "SPY", # US equities, SP500

  "AGG"  # US bonds, Barclay Agg

)

getSymbols(symbols, from="1970-01-01" , to="2014-09-15")

x.P <- do.call(merge, lapply(symbols, function(x) {

  Cl(to.monthly(Ad(get(x)), drop.time = TRUE,

indexAt='endof'))

}))

colnames(x.P) = paste0(symbols, ".Adjusted")

x.R <- na.omit(Return.calculate(x.P))



# Create a weights vector

w = c(.6,.4) # Traditional 60/40 Equity/Bond portfolio weights



# Create monthly weight

w_mon = x.R[endpoints(x.R, on="months")]

w_mon$SPY.Adjusted = 0.6

w_mon$AGG.Adjusted = 0.4



# Rebalance back to 60/40 proportion

result.months1 = Return.portfolio(x.R, weights=w, rebalance_on = "months", 
verbose=TRUE)

result.months2 = Return.portfolio(x.R, weights=w_mon, verbose=TRUE)



test1 = data.frame(BOP = result.months1$BOP.Value, EOP = 
result.months1$EOP.Value, Ret = x.R)

test2 = data.frame(BOP = result.months2$BOP.Value, EOP = 
result.months2$EOP.Value, Ret = x.R)



# Show input and result



w

head(w_mon)



head(test1)

head(test2)



> w

[1] 0.6 0.4

> head(w_mon)

   SPY.Adjusted AGG.Adjusted

2003-10-31  0.6  0.4

2003-11-28  0.6  0.4

2003-12-31  0.6  0.4

2004-01-30  0.6  0.4

2004-02-27  0.6  0.4

2004-03-31  0.6  0.4

>

> head(test1)

   BOP.SPY.Adjusted BOP.AGG.Adjusted EOP.SPY.Adjusted EOP.AGG.Adjusted 
Ret.SPY.Adjusted Ret.AGG.Adjusted

2003-10-310.6000.4000.63211610.3962610  
 0.05352682 -0.009347612

2003-11-280.61702620.41135080.62376480.4127263  
 0.01092112  0.003343882

2003-12-310.62189470.41459650.65318410.4186563  
 0.05031296  0.009792217

2004-01-300.64310420.42873610.65581840.4306248  
 0.01976999  0.004405247

2004-02-270.65186590.43457730.66071210.4395380  
 0.01357061  0.011414925

2004-03-310.66015010.44010000.65140600.4431095  
-0.01324559  0.006838188

> head(test2)

   BOP.SPY.Adjusted BOP.AGG.Adjusted EOP.SPY.Adjusted EOP.AGG.Adjusted 
Ret.SPY.Adjusted Ret.AGG.Adjusted

2003-10-310.6000.4000.60655270.4013376  
 0.05352682 -0.009347612

2003-11-280.60473410.40315610.63516010.4071039  
 0.01092112  0.003343882

2003-12-310.62535840.41690560.63772170.4187422  
 0.05031296  0.009792217

2004-01-300.63387830.42258560.64248040.4274093  
 0.01976999  0.004405247

2004-02-270.64193390.42795590.63343110.4308824  
 0.01357061  0.011414925

2004-03-310.63858810.42572540.62650510.413  
-0.01324559  0.006838188



We can see that even though test1 (from using rebalance_on) and test2 (from 
specifying weight) showed the same Ret.SPY.Adjusted and Ret.AGG.Adjusted.

The return that test 2 used in calculating EOP was from the next period. For 
example, for test2, EOP.SPY.Adjusted on 2003-10-31 (0.6065527) = 
BOP.SPY.Adjusted on 2003-10-31 (0.600) * Ret.SPY.Adjusted on 2003-11-28 
(1+0.01092112)

Could you please suggest how should I set weight to get the same result as in 
test1?





[[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] Variable labels and value labels

2016-05-31 Thread Bert Gunter
I am not sure this is relevant or helpful, but see ?abbreviate, which
one can use to abbreviate long strings as labels (but only for
English-like languages, I believe).

-- Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, May 31, 2016 at 5:00 AM,   wrote:
> Hi All,
>
> I am using R for social sciences. In this field I am used to use short
> variable names like "q1" for question 1, "q2" for question 2 and so on and
> label the variables like q1 : "Please tell us your age" or q2 : "Could you
> state us your household income?" or something similar indicating which
> question is stored in the variable.
>
> Similar I am used to label values like 1: "Less than 18 years", 2 : "18 to
> 30 years", 3 : "31 to 60 years" and 4 : "61 years and more".
>
> I know that the packages Hmisc and memisc have a functionality for this
> but these labeling functions are limited to the packages they were defined
> for. Using the question tests as variable names is possible but very
> inconvenient.
>
> I there another way for labeling variables and values in R?
>
> Kind regards
>
> Georg Maubach
>
> __
> 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] Whether statistical background is must to learn R language

2016-05-31 Thread James Henson
Greetings Prasad,

Here are some tutorials on statistics using R.Statistics and Actuarial
Science – Carl James Schwarz

http://people.stat.sfu.ca/~cschwarz/CourseNotes/



Statistics and Actuarial Science – Carl James Schwarz - Programs

http://people.stat.sfu.ca/~cschwarz/Stat-650/Notes/MyPrograms/



Design Analysis and Interpretation of Experiments

http://www.unh.edu/halelab/BIOL933/

Great YouTube channel of R tutorials by Mike Marin,

https://www.youtube.com/user/marinstatlectures

Best regards,
James


On Tue, May 31, 2016 at 8:04 AM, PIKAL Petr  wrote:
> Hi
>
> Well, it seems to me like cooking.
>
> You does not have to be educated cook to be able prepare some food in your 
> kitchen, but knowledge of some recipes can lead to tasty results
>
> Regards
> Petr
>
>> -Original Message-
>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Prasad
>> Kale
>> Sent: Tuesday, May 31, 2016 9:23 AM
>> To: R-help@r-project.org
>> Subject: [R] Whether statistical background is must to learn R language
>>
>> Hi,
>>
>> I am very new to R and just started learning R. But i am not from statistical
>> background so can i learn R or to learn R statistical background is must.
>>
>> Please guide.
>>
>> Thanks in Advance
>> Prasad
>>
>>   [[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.
>
> 
> Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou 
> určeny pouze jeho adresátům.
> Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
> jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
> svého systému.
> Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
> jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
> Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
> zpožděním přenosu e-mailu.
>
> V případě, že je tento e-mail součástí obchodního jednání:
> - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, 
> a to z jakéhokoliv důvodu i bez uvedení důvodu.
> - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
> Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany 
> příjemce s dodatkem či odchylkou.
> - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
> dosažením shody na všech jejích náležitostech.
> - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
> žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
> pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu 
> případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je 
> adresátovi či osobě jím zastoupené známá.
>
> This e-mail and any documents attached to it may be confidential and are 
> intended only for its intended recipients.
> If you received this e-mail by mistake, please immediately inform its sender. 
> Delete the contents of this e-mail with all attachments and its copies from 
> your system.
> If you are not the intended recipient of this e-mail, you are not authorized 
> to use, disseminate, copy or disclose this e-mail in any manner.
> The sender of this e-mail shall not be liable for any possible damage caused 
> by modifications of the e-mail or by delay with transfer of the email.
>
> In case that this e-mail forms part of business dealings:
> - the sender reserves the right to end negotiations about entering into a 
> contract in any time, for any reason, and without stating any reasoning.
> - if the e-mail contains an offer, the recipient is entitled to immediately 
> accept such offer; The sender of this e-mail (offer) excludes any acceptance 
> of the offer on the part of the recipient containing any amendment or 
> variation.
> - the sender insists on that the respective contract is concluded only upon 
> an express mutual agreement on all its aspects.
> - the sender of this e-mail informs that he/she is not authorized to enter 
> into any contracts on behalf of the company except for cases in which he/she 
> is expressly authorized to do so in writing, and such authorization or power 
> of attorney is submitted to the recipient or the person represented by the 
> recipient, or the existence of such authorization is known to the recipient 
> of the person represented by the recipient.
> __
> 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, 

Re: [R] Fractional Factorial Design on 4-level factor

2016-05-31 Thread Bert Gunter
Inline.

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 Breathed in his "Bloom County" comic strip )


On Tue, May 31, 2016 at 12:05 AM, Michael Haenlein
 wrote:
> Dear all,
>
> I am running a simulation experiment with 8 factors that each have 4
> levels. Each combination is repeated 100 times. If I run a full factorial
> this would mean 100*8^4 = 409,600 runs.

Come again?!  8 factors at 4 levels each is 4^8 possible combinations!

I will reply in more detail off list, as this is OT for r-help.


>
> I am trying to reduce the number of scenarios to run using a fractional
> factorial design. I'm interested in estimating the main effects of the 8
> factors plus their 2-way interactions. Any higher level interactions are
> not of interest to me. My plan is to use a standard OLS regression for
> that, once the simulations are over.
>
> I tried to use the FrF2 package to derive a fractional factorial design but
> it seems that this is only working for factors on two levels. Any idea how
> I could derive a fractional factorial design on factors with four levels?
>
> Thanks for your help,
>
> Michael
>
>
>
> Michael Haenlein
> Professor of Marketing
> ESCP Europe
>
> [[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] How to import sensitive data when multiple users collaborate on R-script?

2016-05-31 Thread Jeff Newmiller
Assume everyone will begin their work in a suitable working directory for their 
computer. Put data in that working directory or some directory "near" it. Then 
use relative paths to the data instead of absolute paths (don't use paths that 
start with "/"). I usually start by reading in a "configuration" file that I 
keep customized for per computer, that includes such things as the names of 
files I want to analyze. Sometimes there is only one row in that file, other 
times I select one row on the fly to use. 
-- 
Sent from my phone. Please excuse my brevity.

On May 31, 2016 3:44:21 AM PDT, Nikolai Stenfors 
 wrote:
>We conduct medical research and our datafiles therefore contain
>sensitive
>data, not to be shared in the cloud (Dropboc, Box, Drive, Bitbucket,
>GitHub).
>When we collaborate on a r-analysis-script, we stumble upon the
>following
>annoyance. Researcher 1 has a line in the script importing the
>sensitive
>data from his/her personal computer. Researcher 2 has to put an
>additional
>line importing the data from his/her personal computer. Thus, we have
>lines
>in the script that are unnecessery for one or the other researcher. How
>can
>we avoid this? Is there another way of conducting the collaboration.
>Other
>workflow? 
>
>I'm perhaps looking for something like:
>"If the script is run on researcher 1 computer, load file from this
>directory. If the script is run on researcher 2 computer, load data
>from
>that directory". 
>
>Example:
>## Import data-
># Researcher 1 import data from laptop1, unnecessery line for
>Researcher 2
>data <- read.table("/path/to_researcher1_computer/sensitive_data.csv") 
>
># Researcher 2 import data from laptop2 (unnecessery line for
>Researcher 1)
>data <- read.table("/path/to_researcher2_computer/sensitive_data.csv") 
>
>## Clean data
>data$var1 <- NULL
>
>## Analyze data
>boxplot(data$var2)
>
>__
>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] Pairwise table from cloumns

2016-05-31 Thread PIKAL Petr
Hi

your message is rather scrambled and to be honest not well understandable (by 
me).

having two column matrix

> mat<-matrix(1:8, 4,2)
> mat
 [,1] [,2]
[1,]15
[2,]26
[3,]37
[4,]48

You can calculate eg. distance

> dist(mat, diag=T, upper=T)
 1234
1 0.00 1.414214 2.828427 4.242641
2 1.414214 0.00 1.414214 2.828427
3 2.828427 1.414214 0.00 1.414214
4 4.242641 2.828427 1.414214 0.00

But from your description I do not understand how you want to reshape your data.

Example, please.

Regards
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of ameneh
> deljoo
> Sent: Tuesday, May 31, 2016 12:13 PM
> To: r-help@r-project.org
> Subject: [R] Pairwise table from cloumns
>
> *Hi Group
> **I have a large data set of individual pairwise values (100 rows) **that I**
> need to reshape into a pairwise matrix for mantel tests of similarity these
> values** .
> **I need this matrix for a Pathfinder network analysis. *
>
> *I have a different data(word) such as :*
>
>
>
>
>
>   living thing
>   0
>
>
>   animal
>   1
>
>
>   blood
>   2
>
>
>   bird
>   3
>
>
>   feathers
>   4
>
>
>   robin
>   5
>
>
>   chicken
> 
>   6
>
>
>
>   *I need the final matrix to be formatted as based on the similarity
> **  A1A2A3A4
> ** A1  0 32   40 32
> * *A2  32049 38
> ** A3  4049   0  53
> ** A4  3238   53 0*
>
> **
>
>
> Are there any functions/packages that will make this easier? Thanks Ameneh
>
>   [[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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
R-help@r-project.org mailing list -- To 

Re: [R] How to import sensitive data when multiple users collaborate on R-script?

2016-05-31 Thread John McKown
On Tue, May 31, 2016 at 5:44 AM, Nikolai Stenfors <
nikolai.stenf...@gapps.umu.se> wrote:

> We conduct medical research and our datafiles therefore contain sensitive
> data, not to be shared in the cloud (Dropboc, Box, Drive, Bitbucket,
> GitHub).
> When we collaborate on a r-analysis-script, we stumble upon the following
> annoyance. Researcher 1 has a line in the script importing the sensitive
> data from his/her personal computer. Researcher 2 has to put an additional
> line importing the data from his/her personal computer. Thus, we have lines
> in the script that are unnecessery for one or the other researcher. How can
> we avoid this? Is there another way of conducting the collaboration. Other
> workflow?
>
> I'm perhaps looking for something like:
> "If the script is run on researcher 1 computer, load file from this
> directory. If the script is run on researcher 2 computer, load data from
> that directory".
>
> Example:
> ## Import data-
> # Researcher 1 import data from laptop1, unnecessery line for Researcher 2
> data <- read.table("/path/to_researcher1_computer/sensitive_data.csv")
>
> # Researcher 2 import data from laptop2 (unnecessery line for Researcher 1)
> data <- read.table("/path/to_researcher2_computer/sensitive_data.csv")
>
> ## Clean data
> data$var1 <- NULL
>
> ## Analyze data
> boxplot(data$var2)
>
>
​Can you have the researchers input the name of the data file to be
analyzed? I use code similar to:

arguments <- commandArgs(trailingOnly=TRUE);
#
# I put in the next command due to my own ignorance
# If you invoke an R script file using just R, you
# need to say something like:
# R BATCH CMD script.R --args ... other arguments ...
#
# but if you use Rscript, you invoke it like:
# Rscript script.R ... other arguments ...
#
# Well, I got confused and did:
# Rscript script.R --args ... other arguments ...
#
# The next line adjusts for my own idiocy.
if ("--args" == arguments[1]) arguments <- arguments[-1];
#
for (file in arguments) {
...
}

Please ignore the line about my own idiocy :-}

Another thought is to use an environment variable which is set in the
user's logon profile (or the Windows registry, forgive my ignorance of
Windows). I think this would be something like:

filename <- Sys.getenv("FILENAME")
if (filename = "") {
... no file name in environment, what to do?
}

You could have someone do this for the user, if he is not familiar with ​
the process.
​


-- 
The unfacts, did we have them, are too imprecisely few to warrant our
certitude.

Maranatha! <><
John McKown

[[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] Whether statistical background is must to learn R language

2016-05-31 Thread PIKAL Petr
Hi

Well, it seems to me like cooking.

You does not have to be educated cook to be able prepare some food in your 
kitchen, but knowledge of some recipes can lead to tasty results

Regards
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Prasad
> Kale
> Sent: Tuesday, May 31, 2016 9:23 AM
> To: R-help@r-project.org
> Subject: [R] Whether statistical background is must to learn R language
>
> Hi,
>
> I am very new to R and just started learning R. But i am not from statistical
> background so can i learn R or to learn R statistical background is must.
>
> Please guide.
>
> Thanks in Advance
> Prasad
>
>   [[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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
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] How to import sensitive data when multiple users collaborate on R-script?

2016-05-31 Thread Tom Wright
My general approach to this is to put the function for loading data
into a separate file which is then sourced in the main analysis file.
Occasionally I'll use a construct like:

if file.exists("loadData_local.R")
  {
source("loadData_local.R")
  }else{
source("loadData_generic.R")
  }

Where loadData_generic.R contains the path to some sample (non-sensitive) data.

On Tue, May 31, 2016 at 6:44 AM, Nikolai Stenfors
 wrote:
> We conduct medical research and our datafiles therefore contain sensitive
> data, not to be shared in the cloud (Dropboc, Box, Drive, Bitbucket, GitHub).
> When we collaborate on a r-analysis-script, we stumble upon the following
> annoyance. Researcher 1 has a line in the script importing the sensitive
> data from his/her personal computer. Researcher 2 has to put an additional
> line importing the data from his/her personal computer. Thus, we have lines
> in the script that are unnecessery for one or the other researcher. How can
> we avoid this? Is there another way of conducting the collaboration. Other
> workflow?
>
> I'm perhaps looking for something like:
> "If the script is run on researcher 1 computer, load file from this
> directory. If the script is run on researcher 2 computer, load data from
> that directory".
>
> Example:
> ## Import data-
> # Researcher 1 import data from laptop1, unnecessery line for Researcher 2
> data <- read.table("/path/to_researcher1_computer/sensitive_data.csv")
>
> # Researcher 2 import data from laptop2 (unnecessery line for Researcher 1)
> data <- read.table("/path/to_researcher2_computer/sensitive_data.csv")
>
> ## Clean data
> data$var1 <- NULL
>
> ## Analyze data
> boxplot(data$var2)
>
> __
> 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] Whether statistical background is must to learn R language

2016-05-31 Thread John McKown
On Tue, May 31, 2016 at 2:22 AM, Prasad Kale 
wrote:

> Hi,
>
> I am very new to R and just started learning R. But i am not from
> statistical background so can i learn R or to learn R statistical
> background is must.
>

​Well, I got a B.Sc. in Math back many years ago. I "earned" a C- in
Statistics (deserved). I don't use statistics normally. And I use R for
non-statistical purposes. In particular, I use it to read files into data
frames; do some minor statistical stuff (sum, mean, standard deviation,
other really simple stuff); then use ggplot2 to create really nice graphs
which I embed into a web page. I also use R to read a web site in order to
extract data in an HTML table into an R data frame. I then do some minor
manipulation and put the data into a PostgreSQL data base​. I even use it
to create Excel spreadsheets (for people at work who aren't wise enough to
abandon it for LibreOffice).

All that to say that, depending on your need, you don't need to learn
statistics to be able to use R. Of course, R was designed to make it easy
to do statistics. And many users here use it for that. But it is not a "one
trick pony".



>
> Please guide.
>
> Thanks in Advance
> Prasad
>
>

-- 
The unfacts, did we have them, are too imprecisely few to warrant our
certitude.

Maranatha! <><
John McKown

[[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] Variable labels and value labels

2016-05-31 Thread PIKAL Petr
Hi

see in line

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of
> g.maub...@weinwolf.de
> Sent: Tuesday, May 31, 2016 2:01 PM
> To: r-help@r-project.org
> Subject: [R] Variable labels and value labels
>
> Hi All,
>
> I am using R for social sciences. In this field I am used to use short 
> variable
> names like "q1" for question 1, "q2" for question 2 and so on and label the
> variables like q1 : "Please tell us your age" or q2 : "Could you state us your
> household income?" or something similar indicating which question is stored
> in the variable.
>
> Similar I am used to label values like 1: "Less than 18 years", 2 : "18 to
> 30 years", 3 : "31 to 60 years" and 4 : "61 years and more".

Seems to me that it is work for factors

nnn <- sample(1:4, 20, replace=TRUE)
q1 <-factor(nnn, labels=c("Less than 18 years", "18 to 30 years", "31 to 60 
years","61 years and more"))

You can store such variables in data.frame with names "q1" to "qwhatever" and 
possibly "Subject"

And you can store annotation of questions in another data frame with 2 columns 
e.g. "Question" and "Description"

Basically it is an approach similar to database and in R you can merge those 
two data.frames by ?merge.
>
> I know that the packages Hmisc and memisc have a functionality for this but
> these labeling functions are limited to the packages they were defined for.

It seems to me strange. What prevents you to use functions from Hmisc?

Regards
Petr

> Using the question tests as variable names is possible but very inconvenient.
>
> I there another way for labeling variables and values in R?
>
> Kind regards
>
> Georg Maubach
>
> __
> 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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__

[R] How to replace all commas with semicolon in a string

2016-05-31 Thread Mohammad Goodarzi
here is the solution to your question

test <- data.frame(C1=c('a,b,c,d'),C2=c('g,h,f'))

you should use gsub instead sub if you want it to be on all elements of
each column

tFun <- function(x) {gsub(",",";",x)}
newTest <- apply(test, 2, tFun )

Cheers,

[[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] Utility Functions

2016-05-31 Thread G . Maubach
Hi All,

I was new to R and this list a couple of mounths ago. When processing my 
data I got tremendous support from R-Help mailing list.

The solutions I have worked out with your help might be also helpful for 
others. I have put the solutions in a couple of small functions with 
documentation and tests. You can find the software on Sourceforge.net at

https://sourceforge.net/projects/r-project-utilities/files/?source=navbar

You should download at least "r_toolbox.R" and store it in a directory 
like "r_toolbox" in your favourite project folder. Within "r_toolbox" 
folder put all the other files. You have to adjust the variable 
"t_toolbox_path" to your favourite project directory including the 
"r_toolbox" folder, e. g. "C:\My-Projects\t-toolbox\" on Windows or 
"/home/username/my-projects/r-toolbox" on Unix-like systems.

You can use them for your projects. Although I developed them with great 
care these functions come with absolutely no warrenty. You need to use 
them at your own risk. As the functions are small and overseeable you will 
find out quickly by reading the source code that the functions are save to 
use.

If you have any recommendations or improvement proposals please get back 
to me.

Kind regards

Georg Maubach

__
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] How to import sensitive data when multiple users collaborate on R-script?

2016-05-31 Thread Nikolai Stenfors
We conduct medical research and our datafiles therefore contain sensitive
data, not to be shared in the cloud (Dropboc, Box, Drive, Bitbucket, GitHub).
When we collaborate on a r-analysis-script, we stumble upon the following
annoyance. Researcher 1 has a line in the script importing the sensitive
data from his/her personal computer. Researcher 2 has to put an additional
line importing the data from his/her personal computer. Thus, we have lines
in the script that are unnecessery for one or the other researcher. How can
we avoid this? Is there another way of conducting the collaboration. Other
workflow? 

I'm perhaps looking for something like:
"If the script is run on researcher 1 computer, load file from this
directory. If the script is run on researcher 2 computer, load data from
that directory". 

Example:
## Import data-
# Researcher 1 import data from laptop1, unnecessery line for Researcher 2
data <- read.table("/path/to_researcher1_computer/sensitive_data.csv") 

# Researcher 2 import data from laptop2 (unnecessery line for Researcher 1)
data <- read.table("/path/to_researcher2_computer/sensitive_data.csv") 

## Clean data
data$var1 <- NULL

## Analyze data
boxplot(data$var2)

__
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] Whether statistical background is must to learn R language

2016-05-31 Thread Prasad Kale
Hi,

I am very new to R and just started learning R. But i am not from
statistical background so can i learn R or to learn R statistical
background is must.

Please guide.

Thanks in Advance
Prasad

[[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] Fractional Factorial Design on 4-level factor

2016-05-31 Thread PIKAL Petr
Hi

I do not consider myself as an expert in factorial design but why do you insist 
on 4 levels in factors. My opinion is that you need more than 2 levels only if 
you expect and you want to evaluate nonlinear relationship of the response on 
such factor.

If you used only 2 levels you could find which factors are influential and they 
can be further tested on nonlinear response.

And even if you used only 2 levels you have to test 8 factors in at least 16 
runs which, with 100 repetitions, gives me 1600 experiments (that seems to me 
quite a big deal).

Regards
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Michael
> Haenlein
> Sent: Tuesday, May 31, 2016 9:05 AM
> To: r-help@r-project.org
> Subject: [R] Fractional Factorial Design on 4-level factor
>
> Dear all,
>
> I am running a simulation experiment with 8 factors that each have 4 levels.
> Each combination is repeated 100 times. If I run a full factorial this would
> mean 100*8^4 = 409,600 runs.
>
> I am trying to reduce the number of scenarios to run using a fractional
> factorial design. I'm interested in estimating the main effects of the 8 
> factors
> plus their 2-way interactions. Any higher level interactions are not of 
> interest
> to me. My plan is to use a standard OLS regression for that, once the
> simulations are over.
>
> I tried to use the FrF2 package to derive a fractional factorial design but it
> seems that this is only working for factors on two levels. Any idea how I 
> could
> derive a fractional factorial design on factors with four levels?
>
> Thanks for your help,
>
> Michael
>
>
>
> Michael Haenlein
> Professor of Marketing
> ESCP Europe
>
>   [[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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person 

[R] Pairwise table from cloumns

2016-05-31 Thread ameneh deljoo
*Hi Group
**I have a large data set of individual pairwise values (100 rows)
**that I** need to reshape into a pairwise matrix for mantel tests of
similarity these values** .
**I need this matrix for a Pathfinder network analysis. *

*I have a different data(word) such as :*





  living thing
  0


  animal
  1


  blood
  2


  bird
  3


  feathers
  4


  robin
  5


  chicken

  6



  *I need the final matrix to be formatted as based on the similarity
**  A1A2A3A4
** A1  0 32   40 32
* *A2  32049 38
** A3  4049   0  53
** A4  3238   53 0*

**


Are there any functions/packages that will make this easier? Thanks Ameneh

[[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] sandwich package: HAC estimators

2016-05-31 Thread Achim Zeileis

On Tue, 31 May 2016, T.Riedle wrote:

I understood. But how do I get the R2 an Chi2 of my logistic regression 
under HAC standard errors? I would like to create a table with HAC SE 
via e.g. stargazer().


Do I get these information by using the functions

bread.lrm <- function(x, ...) vcov(x) * nobs(x)
estfun.lrm <- function(x, ...) residuals(x, "score")?

Do I need to use the coeftest() in this case?


The bread()/estfun() methods enable application of vcovHAC(), kernHAC(), 
NeweyWest(). This in turn enables the application of coeftest(),

waldtest(), or linearHypothesis() with a suitable vcov argument.

All of these give you different kinds of Wald tests with HAC covariances 
including marginal tests of individual coefficients (coeftest) or global 
tests of nested models (waldtest/linearHypothesis). The latter can serve 
as replacement for the "chi-squared test". For pseudo-R-squared values I'm 
not familiar with HAC-adjusted variants.


And I'm not sure whether there is a LaTeX export solution that encompasses 
all of these aspects simultaneously.




From: R-help  on behalf of Achim Zeileis 

Sent: 31 May 2016 08:36
To: Leonardo Ferreira Fontenelle
Cc: r-help@r-project.org
Subject: Re: [R] sandwich package: HAC estimators

On Mon, 30 May 2016, Leonardo Ferreira Fontenelle wrote:


Em Sáb 28 mai. 2016, às 15:50, Achim Zeileis escreveu:

On Sat, 28 May 2016, T.Riedle wrote:

I thought it would be useful to incorporate the HAC consistent
covariance matrix into the logistic regression directly and generate an
output of coefficients and the corresponding standard errors. Is there
such a function in R?


Not with HAC standard errors, I think.


Don't glmrob() and summary.glmrob(), from robustbase, do that?


No, they implement a different concept of robustness. See also
https://CRAN.R-project.org/view=Robust

glmrob() implements GLMs that are "robust" or rather "resistant" to
outliers and other observations that do not come from the main model
equation. Instead of maximum likelihood (ML) estimation other estimation
techniques (along with corresponding covariances/standard errors) are
used.

In contrast, the OP asked for HAC standard errors. The motivation for
these is that the main model equation does hold for all observations but
that the observations might be heteroskedastic and/or autocorrelated. In
this situation, ML estimation is still consistent (albeit not efficient)
but the covariance matrix estimate needs to be adjusted.



Leonardo Ferreira Fontenelle, MD, MPH

__
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-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] Variable labels and value labels

2016-05-31 Thread G . Maubach
Hi All,

I am using R for social sciences. In this field I am used to use short 
variable names like "q1" for question 1, "q2" for question 2 and so on and 
label the variables like q1 : "Please tell us your age" or q2 : "Could you 
state us your household income?" or something similar indicating which 
question is stored in the variable.

Similar I am used to label values like 1: "Less than 18 years", 2 : "18 to 
30 years", 3 : "31 to 60 years" and 4 : "61 years and more".

I know that the packages Hmisc and memisc have a functionality for this 
but these labeling functions are limited to the packages they were defined 
for. Using the question tests as variable names is possible but very 
inconvenient.

I there another way for labeling variables and values in R?

Kind regards

Georg Maubach

__
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] graphic device Windows tickmarks

2016-05-31 Thread Christian Brandstätter

Hi,

thank you for your answer. To tackle down the problem, I tried this 
(modified from your code):


thickticks <- c(0,60,130,210,290,370,450,530,610,690,770,850,930)

png("test.png",width=864,height=834,res=150)
plot(seq(0,1000),rep(10,1001),xaxt="n")
axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)
dev.off()

x11()
plot(seq(0,1000),rep(10,1001),xaxt="n")
axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)

On my machine the x-axis-labels differ.
In the test.png the labels are 0,70,170,...
In the x11 window they are the same values as in the thickticks-vector.
Why? I tried to play with different resolution values, this didn't help.

Best, Christian


Am 31.05.2016 um 08:17 schrieb Duncan Mackay:

Hi

Without looking at the help guide I think there are restrictions on
resolution
and just in case of unit problems I worked in the default units


png("test.png",units="in",width=12,height=12,res=300)

Error in png("test.png", units = "in", width = 12, height = 12, res = 300) :

   unable to start png() device
In addition: Warning messages:
1: In png("test.png", units = "in", width = 12, height = 12, res = 300) :
   unable to allocate bitmap
2: In png("test.png", units = "in", width = 12, height = 12, res = 300) :
   opening device failed

12*72

[1] 864

png("test.png",width=864,height=834,res=150)
plot(seq(0,1000),rep(10,1001),xaxt="n")
axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)
dev.off()

Check ?postscript and the options as eps and pdf require different
arguments.

postscript("test.eps", paper = "special", width = 12,height = 12)
plot(seq(0,1000),rep(10,1001),xaxt="n")
axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)
dev.off()
pdf("test.pdf", paper = "special", width = 12,height = 12)
plot(seq(0,1000),rep(10,1001),xaxt="n")
axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)
dev.off()

All the above work for me on Win 7 32

platform   i386-w64-mingw32
arch   i386
os mingw32
system i386, mingw32

Similar to the above has worked on Win 64

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Christian
Brandstätter
Sent: Tuesday, 31 May 2016 05:24
To: r-help@r-project.org
Subject: [R] graphic device Windows tickmarks

Dear List,

I discovered an issue; when plotting (base) in R, the tickmark-labels
are slightly off (Windows machine).

Thus, when saving the plot in R with x11() and dev(...) the
plot-tickmarks shift, see the example below.

Session Info:

R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

With savePlot it works, but the graph quality is not as nice. Am I
missing something here?


Example:
thickticks <-
c(0,40,90,140,200,260,320,380,440,500,560,620,680,740,800,860,920,980)

x11(width=12,height=12)
plot(seq(0,1000),rep(10,1001),xaxt="n")
axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)

# plots
dev.print(device=png,"test.png",units="in",width=12,height=12,res=500) #
won't display prop.
dev.print(device=postscript,"test.eps",width=12,height=12)  # won't
display prop.
dev.print(device=pdf,"test.pdf",width=12,height=12)  # won't display prop.
savePlot("test_2.png",type="png") # displays prop.

__
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] sandwich package: HAC estimators

2016-05-31 Thread T.Riedle
I understood. But how do I get the R2 an Chi2 of my logistic regression under 
HAC standard errors? I would like to create a table with HAC SE via e.g. 
stargazer(). 

Do I get these information by using the functions

bread.lrm <- function(x, ...) vcov(x) * nobs(x)
estfun.lrm <- function(x, ...) residuals(x, "score")?
 
Do I need to use the coeftest() in this case?

From: R-help  on behalf of Achim Zeileis 

Sent: 31 May 2016 08:36
To: Leonardo Ferreira Fontenelle
Cc: r-help@r-project.org
Subject: Re: [R] sandwich package: HAC estimators

On Mon, 30 May 2016, Leonardo Ferreira Fontenelle wrote:

> Em Sáb 28 mai. 2016, às 15:50, Achim Zeileis escreveu:
>> On Sat, 28 May 2016, T.Riedle wrote:
>> > I thought it would be useful to incorporate the HAC consistent
>> > covariance matrix into the logistic regression directly and generate an
>> > output of coefficients and the corresponding standard errors. Is there
>> > such a function in R?
>>
>> Not with HAC standard errors, I think.
>
> Don't glmrob() and summary.glmrob(), from robustbase, do that?

No, they implement a different concept of robustness. See also
https://CRAN.R-project.org/view=Robust

glmrob() implements GLMs that are "robust" or rather "resistant" to
outliers and other observations that do not come from the main model
equation. Instead of maximum likelihood (ML) estimation other estimation
techniques (along with corresponding covariances/standard errors) are
used.

In contrast, the OP asked for HAC standard errors. The motivation for
these is that the main model equation does hold for all observations but
that the observations might be heteroskedastic and/or autocorrelated. In
this situation, ML estimation is still consistent (albeit not efficient)
but the covariance matrix estimate needs to be adjusted.

>
> Leonardo Ferreira Fontenelle, MD, MPH
>
> __
> 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-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] Regression and Sub-Groups Analysis in Metafor

2016-05-31 Thread Michael Dewey

In-line

On 30/05/2016 19:27, Dan Kolubinski wrote:

I am completing a meta-analysis on the effect of CBT on low self-esteem and
I could use some help regarding the regression feature in metafor.  Based
on the studies that I am using for the analysis, I identified 4 potential
moderators that I want to explore:
- Some of the studies that I am using used RCTs to compare an intervention
with a waitlist and others used the pre-score as the control in a
single-group design.
- Some of the groups took place in one day and others took several weeks.
- There are three discernible interventions being represented
- The initial level of self-esteem varies

Based on the above, I used this command to conduct a meta-analysis using
standarized mean differences:



MetaMod<-rma(m1i=m1, m2i=m2, sd1i=sd1, sd2i=sd2, n1i=n1, n2i=n2,
mods=cbind(dur, rct, int, level),measure = "SMD")



You could also say mods = ~ dur + rct + int + level




Would this be the best command to use for what I described?  Also, what
could I add to the command so that the forest plot shows a sub-group
analysis using the 'dur' variable as a between-groups distinction?



You have to adjust the forest plot by hand and then use add.polygon to 
add the summaries for each level of dur.




Also, with respect to the moderators, this is what was delivered:



Test of Moderators (coefficient(s) 2,3,4,5):
QM(df = 4) = 8.7815, p-val = 0.0668

Model Results:

 estimate  se zvalpvalci.lb   ci.ub
intrcpt0.7005  0.6251   1.1207  0.2624  -0.5246  1.9256
dur0.5364  0.2411   2.2249  0.0261   0.0639  1.0090  *
rct   -0.3714  0.1951  -1.9035  0.0570  -0.7537  0.0110  .
int0.0730  0.1102   0.6628  0.5075  -0.1430  0.2890
level -0.2819  0.2139  -1.3180  0.1875  -0.7010  0.1373

---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1




So the totality of moderators did not reach an arbitrary level of 
significance.





From this, can I interpret that the variable 'dur' (duration of

intervention) has a significant effect and the variable 'rct' (whether a
study was an RCT or used pre-post scores) was just shy of being
statistically significant?  I mainly ask, because the QM-score has a
p-value of 0.0668, which I thought would mean that none of the moderators
would be significant.  Would I be better off just listing one or two
moderators instead of four?



At the moment you get an overall test of the moderators which you had a 
scientific reason for using. If you start selecting based on the data 
you run the risk of ending up with confidence intervals and significance 
levels which do not have the meaning they are supposed to have.




Much appreciated,
Dan

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



--
Michael
http://www.dewey.myzen.co.uk/home.html

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

Re: [R] sandwich package: HAC estimators

2016-05-31 Thread Achim Zeileis

On Mon, 30 May 2016, Leonardo Ferreira Fontenelle wrote:


Em Sáb 28 mai. 2016, às 15:50, Achim Zeileis escreveu:

On Sat, 28 May 2016, T.Riedle wrote:
> I thought it would be useful to incorporate the HAC consistent 
> covariance matrix into the logistic regression directly and generate an 
> output of coefficients and the corresponding standard errors. Is there 
> such a function in R?


Not with HAC standard errors, I think.


Don't glmrob() and summary.glmrob(), from robustbase, do that?


No, they implement a different concept of robustness. See also
https://CRAN.R-project.org/view=Robust

glmrob() implements GLMs that are "robust" or rather "resistant" to 
outliers and other observations that do not come from the main model 
equation. Instead of maximum likelihood (ML) estimation other estimation 
techniques (along with corresponding covariances/standard errors) are 
used.


In contrast, the OP asked for HAC standard errors. The motivation for 
these is that the main model equation does hold for all observations but 
that the observations might be heteroskedastic and/or autocorrelated. In 
this situation, ML estimation is still consistent (albeit not efficient) 
but the covariance matrix estimate needs to be adjusted.




Leonardo Ferreira Fontenelle, MD, MPH

__
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 subsetting (dataset$variable vs. dataset["variable"]

2016-05-31 Thread Jeff Newmiller
You were clearly mistaken. 

dataframe$column is almost the same as dataframe[["column"]], except that the $ 
does partial matching. Both of these "extract" a list element. 

A data frame is a list where all elements are vectors of the same length.  A 
list is a vector where each element can refer to any of a variety of types of 
objects. The names of the objects in the list are associated with the list 
vector, not the referred objects (e.g. columns).  The [] operator "slices" the 
list but keeps the names and referring semantics. The [[]] extraction operator 
(and its pal $) refer to a single element out of the list, losing access to the 
containing list and the names that go with it. 

The Introduction to R document has all this in it... it just usually glazes 
your eyes the first few times you read it.  You might find the R Inferno more 
entertaining. 

-- 
Sent from my phone. Please excuse my brevity.

On May 30, 2016 11:45:52 PM PDT, g.maub...@weinwolf.de wrote:
>Hi All,
>
>I thought dataset$variable is the same as dataset["variable"]. I tried
>the 
>following:
>
>> str(ZWW_Kunden$Branche)
>chr [1:49673] "231" "151" "151" "231" "231" "111" "231" "111" "231"
>"231" 
>"151" "111" ...
>> str(ZWW_Kunden["Branche"])
>'data.frame':49673 obs. of  1 variable:
> $ Branche: chr  "231" "151" "151" "231" ...
>
>and get different results: "chr {1:49673]" vs. "data.frame". First one
>is 
>a simple vector, second one is a data.frame.
>
>This has consequences when subsetting a dataset and filter cases:
>
>> ZWW_Kunden["Branche"] %in% c("315", "316", "317")
>[1] FALSE
>
>> head(ZWW_Kunden$Branche %in% c("315", "316", "317")) # head() only to
>
>shorten output
>[1] FALSE FALSE FALSE FALSE FALSE FALSE
>
>I have thought dataset$variable is the same as dataset["variable"] but 
>actually it's not.
>
>Can you explain what the difference is?
>
>Kind regards
>
>Georg
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

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


[R] Fractional Factorial Design on 4-level factor

2016-05-31 Thread Michael Haenlein
Dear all,

I am running a simulation experiment with 8 factors that each have 4
levels. Each combination is repeated 100 times. If I run a full factorial
this would mean 100*8^4 = 409,600 runs.

I am trying to reduce the number of scenarios to run using a fractional
factorial design. I'm interested in estimating the main effects of the 8
factors plus their 2-way interactions. Any higher level interactions are
not of interest to me. My plan is to use a standard OLS regression for
that, once the simulations are over.

I tried to use the FrF2 package to derive a fractional factorial design but
it seems that this is only working for factors on two levels. Any idea how
I could derive a fractional factorial design on factors with four levels?

Thanks for your help,

Michael



Michael Haenlein
Professor of Marketing
ESCP Europe

[[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] Difference subsetting (dataset$variable vs. dataset["variable"]

2016-05-31 Thread G . Maubach
Hi All,

I thought dataset$variable is the same as dataset["variable"]. I tried the 
following:

> str(ZWW_Kunden$Branche)
 chr [1:49673] "231" "151" "151" "231" "231" "111" "231" "111" "231" "231" 
"151" "111" ...
> str(ZWW_Kunden["Branche"])
'data.frame':49673 obs. of  1 variable:
 $ Branche: chr  "231" "151" "151" "231" ...

and get different results: "chr {1:49673]" vs. "data.frame". First one is 
a simple vector, second one is a data.frame.

This has consequences when subsetting a dataset and filter cases:

> ZWW_Kunden["Branche"] %in% c("315", "316", "317")
[1] FALSE

> head(ZWW_Kunden$Branche %in% c("315", "316", "317")) # head() only to 
shorten output
[1] FALSE FALSE FALSE FALSE FALSE FALSE

I have thought dataset$variable is the same as dataset["variable"] but 
actually it's not.

Can you explain what the difference is?

Kind regards

Georg

__
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] graphic device Windows tickmarks

2016-05-31 Thread Duncan Mackay
Hi 

Without looking at the help guide I think there are restrictions on
resolution
and just in case of unit problems I worked in the default units

> png("test.png",units="in",width=12,height=12,res=300)
Error in png("test.png", units = "in", width = 12, height = 12, res = 300) :

  unable to start png() device
In addition: Warning messages:
1: In png("test.png", units = "in", width = 12, height = 12, res = 300) :
  unable to allocate bitmap
2: In png("test.png", units = "in", width = 12, height = 12, res = 300) :
  opening device failed
> 12*72
[1] 864
> png("test.png",width=864,height=834,res=150)
> plot(seq(0,1000),rep(10,1001),xaxt="n")
> axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
> axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)
> dev.off()

Check ?postscript and the options as eps and pdf require different
arguments.
> postscript("test.eps", paper = "special", width = 12,height = 12)
> plot(seq(0,1000),rep(10,1001),xaxt="n")
> axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
> axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)
> dev.off()

> pdf("test.pdf", paper = "special", width = 12,height = 12)
> plot(seq(0,1000),rep(10,1001),xaxt="n")
> axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
> axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)
> dev.off()

All the above work for me on Win 7 32

platform   i386-w64-mingw32   
arch   i386   
os mingw32
system i386, mingw32

Similar to the above has worked on Win 64

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Christian
Brandstätter
Sent: Tuesday, 31 May 2016 05:24
To: r-help@r-project.org
Subject: [R] graphic device Windows tickmarks

Dear List,

I discovered an issue; when plotting (base) in R, the tickmark-labels 
are slightly off (Windows machine).

Thus, when saving the plot in R with x11() and dev(...) the 
plot-tickmarks shift, see the example below.

Session Info:

R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

With savePlot it works, but the graph quality is not as nice. Am I 
missing something here?


Example:
thickticks <- 
c(0,40,90,140,200,260,320,380,440,500,560,620,680,740,800,860,920,980)

x11(width=12,height=12)
plot(seq(0,1000),rep(10,1001),xaxt="n")
axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)

# plots
dev.print(device=png,"test.png",units="in",width=12,height=12,res=500) # 
won't display prop.
dev.print(device=postscript,"test.eps",width=12,height=12)  # won't 
display prop.
dev.print(device=pdf,"test.pdf",width=12,height=12)  # won't display prop.
savePlot("test_2.png",type="png") # displays prop.

__
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] Extract from a text file

2016-05-31 Thread Jeff Newmiller
Please learn to post in plain text (the setting is in your email client... 
somewhere), as HTML is "What We See Is Not What You Saw" on this mailing 
list.  In conjunction with that, try reading some of the fine material 
mentioned in the Posting Guide about making reproducible examples like 
this one:


# You could read in a file
# indta <- readLines( "out.txt" )
# but there is no "current directory" in an email
# so here I have used the dput() function to make source code
# that creates a self-contained R object

indta <- c(
"Mean of weight  group 1, SE of mean  :  72.289037489555276",
" 11.512956539215610",
"Average weight of group 2, SE of Mean :  83.940053900595013",
"  10.198495690144522",
"group 3 mean , SE of Mean :78.310441258245469",
" 13.015876679555",
"Mean of weight of group 4, SE of Mean   : 76.967516495101669",
" 12.1254882985", "")

# Regular expression patterns are discussed all over the internet
# in many places OTHER than R
# You can start with ?regex, but there are many fine tutorials also

pattern <- "^.*group (\\d+)[^:]*: *([-+0-9.eE]*).*$"
# For this task the regex has to match the whole "first line" of each set
#  ^ =match starting at the beginning of the string
#  .* =any character, zero or more times
#  "group " =match these characters
#  ( =first capture string starts here
#  \\d = any digit (first backslash for R, second backslash for regex)
#  + =one or more of the preceding (any digit)
#  ) =end of first capture string
#  [^:] =any non-colon character
#  * =zero or more of the preceding (non-colon character)
#  : =match a colon exactly
#  " *" =match zero or more spaces
#  ( =second capture string starts here
#  [ =start of a set of equally acceptable characters
#  -+ =either of these characters are acceptable
#  0-9 =any digit would be acceptable
#  . =a period is acceptable (this is inside the [])
#  eE =in case you get exponential notation input
#  ] =end of the set of acceptable characters (number)
#  * =number of acceptable characters can be zero or more
#  ) =second capture string stops here
#  .* =zero or more of any character (just in case)
#  $ =at end of pattern, requires that the match reach the end
# of the string

# identify indexes of strings that match the pattern
firstlines <- grep( pattern, indta )
# Replace the matched portion (entire string) with the first capture 
# string

v1 <- as.numeric( sub( pattern, "\\1", indta[ firstlines ] ) )
# Replace the matched portion (entire string) with the second capture 
# string

v2 <- as.numeric( sub( pattern, "\\2", indta[ firstlines ] ) )
# Convert the lines just after the first lines to numeric
v3 <- as.numeric( indta[ firstlines + 1 ] )
# put it all into a data frame
result <- data.frame( Group = v1, Mean = v2, SE = v3 )

Figuring out how to deliver your result (output) is a separate question 
that depends where you want it to go.


On Mon, 30 May 2016, Val wrote:


Hi all,

I have a messy text file and from this text file I want extract some
information
here is the text file (out.txt).  One record has tow lines. The mean comes
in the first line and the SE of the mean is on the second line. Here is the
sample of the data.

Mean of weight  group 1, SE of mean  :  72.289037489555276
11.512956539215610
Average weight of group 2, SE of Mean :  83.940053900595013
 10.198495690144522
group 3 mean , SE of Mean :78.310441258245469
13.015876679555
Mean of weight of group 4, SE of Mean   : 76.967516495101669
12.1254882985

I want produce the following  table. How do i read it first and then
produce a


Gr1  72.289037489555276   11.512956539215610
Gr2  83.940053900595013   10.198495690144522
Gr3  78.310441258245469   13.015876679555
Gr4  76.967516495101669   12.1254882985


Thank you in advance

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



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