Re: [R] GlobalEnv error

2018-03-22 Thread William Dunlap via R-help
Find the .RData file and rename it to anything else.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Mar 22, 2018 at 7:09 PM, Haida  wrote:

> Previously, the R software was perfectly run without error and I am not
> sure why this happens. I have not installed any new R. If the *RData file
> is the problem, what should I do?
> Thank you
>
> On Fri, Mar 23, 2018 at 7:58 AM, William Dunlap  wrote:
>
>> You haven't given much context, but these error message can come from
>> load() when loading a *.RData file that contains objects reference
>> packages
>> not installed in the current installation of R.  When R starts it will
>> load
>> a ".RData" file if one exists, this file is typically created when R
>> shuts down
>> and you ask it to save the current session.  If you recently upgraded R
>> you
>> the newly installed R may not have all the packages that were installed in
>> the version that you last used.
>>
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>>
>> On Thu, Mar 22, 2018 at 2:07 PM, Haida  wrote:
>>
>>> Dear all
>>>
>>> May I know how to solve this problem? I have encountered this problem
>>> after
>>> I have logged out from Rstudio. Thank you
>>>
>>> Warning: namespace ‘caret’ is not available and has been replaced
>>> by .GlobalEnv when processing object ‘fit.ann’
>>> Warning: namespace ‘ggplot2’ is not available and has been replaced
>>> by .GlobalEnv when processing object ‘p1’
>>> Warning: namespace ‘plotly’ is not available and has been replaced
>>> by .GlobalEnv when processing object ‘p’
>>> Warning: namespace ‘easyGgplot2’ is not available and has been replaced
>>> by .GlobalEnv when processing object ‘plot’
>>> Warning: namespace ‘RSNNS’ is not available and has been replaced
>>> by .GlobalEnv when processing object ‘fit.mlp’
>>> Warning: namespace ‘ipred’ is not available and has been replaced
>>> by .GlobalEnv when processing object ‘fit.treebag’
>>>
>>> [[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/posti
>>> ng-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] Calculate weighted proportions for several factors at once

2018-03-22 Thread Striessnig, Erich
Hi,

I have a grouped data set and would like to calculate weighted proportions for 
a large number of factor variables within each group member. Rather than using 
dplyr::count() on each of these factors individually, the idea would be to do 
it for all factors at once. Does anyone know how this would work? Here is a 
reproducible example:


# reproducible example
df1 <- data.frame(wt=rnorm(90),
  group=paste0('reg', 1:5),
  var1=rep(c('male','female'), times=45),
  var2=rep(c('low','med','high'), each=30)) %>% tbl_df()

# instead of doing this separately for each factor ...
df2 <- df1 %>%
  group_by(group) %>%
  dplyr::count(var1, wt=wt) %>%
  mutate(prop1=n/sum(n))

df3 <- df1 %>%
  group_by(group) %>%
  dplyr::count(var2, wt=wt) %>%
  mutate(prop2=n/sum(n)) %>%
  left_join(df2, by='group')

# I would like to do something like the following (which does of course not 
work):
my_fun <- function(x,wt){
  freq1 <- dplyr::count(x, wt=wt)
  prop1 <- freq1 / sum(freq1)
  return(prop)
}

df1 %>%
  group_by(group) %>%
  summarise_all(.funs=my_fun(.), .vars=c('var1', 'var2'))


Best regards,
Erich

[[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] MCMCglmm multinomial model results

2018-03-22 Thread Michelle Kline
Hi,

Thanks in advance for any help on this question. I'm running multinomial
models using the MCMCglmm package. The models have 5 outcome variables
(each with count data), and an additional two random effects built into the
models. The issue is that when I use the following code, the summary only
gives me results for four of the outcome variables.

Here is the code for my model:

m3.random <- MCMCglmm(cbind(Opp_teacher , Dir_teacher, Enh_teacher,
SocTol_teacher, Eval_teacher) ~ trait -1,
   random = ~ us(trait):other + us(trait):focal,
   rcov = ~ us(trait):units,
   prior = list(
 R = list(fix=1, V=0.5 * (I + J), n = 4),
 G = list(
   G1 = list(V = diag(4), n = 4),
   G2 = list(V = diag(4), n = 4))),
   burnin = burn,
   nitt = iter,
   family = "multinomial5",
   data = data,
   pr=TRUE,
   pl=TRUE,
   DIC = TRUE,
   verbose = FALSE)

And the summary of the main effects:

post.mean  l-95% CI  u-95% CI eff.samppMCMC
traitOpp_teacher-3.828752 -4.616731 -3.067424 184.4305 5.263158e-05
traitDir_teacher-3.400481 -4.041069 -2.813063 259.1084 5.263158e-05
traitEnh_teacher-1.779129 -2.197415 -1.366496 624.9759 5.263158e-05
traitSocTol_teacher -2.852684 -3.429799 -2.332909 468.7098 5.263158e-05


It is not an issue of the suppressing the intercept, since I'm already
doing that (see the -1 term. When I remove that term, the model solutions
includes an intercept and only 3 additional main effects).

The model does throw the following error, but after searching previous
messages on this list, I've concluded that this error message doesn't have
to do with  my current problem. Just in case: " observations with zero
weight not used for calculating dispersion"

I have also posted a similar question on stackoverflow about a week ago,
but with no response, so I thought I would try here. Link in case people
want to gain reputation points for a
response: 
https://stackoverflow.com/questions/49309027/missing-term-in-mcmcglmm-multinomial-model-results-not-in-intercept-issue


And of course I've checked various other sources including the course
notes, but can't make sense of why the 5th term is dropped from the model.
Any help is much appreciated.

Best,

Michelle

-- 
Michelle A. Kline, PhD

Assistant Professor
Department of Psychology
Simon Fraser University

[[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] GlobalEnv error

2018-03-22 Thread Haida
Previously, the R software was perfectly run without error and I am not
sure why this happens. I have not installed any new R. If the *RData file
is the problem, what should I do?
Thank you

On Fri, Mar 23, 2018 at 7:58 AM, William Dunlap  wrote:

> You haven't given much context, but these error message can come from
> load() when loading a *.RData file that contains objects reference packages
> not installed in the current installation of R.  When R starts it will load
> a ".RData" file if one exists, this file is typically created when R shuts
> down
> and you ask it to save the current session.  If you recently upgraded R you
> the newly installed R may not have all the packages that were installed in
> the version that you last used.
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Thu, Mar 22, 2018 at 2:07 PM, Haida  wrote:
>
>> Dear all
>>
>> May I know how to solve this problem? I have encountered this problem
>> after
>> I have logged out from Rstudio. Thank you
>>
>> Warning: namespace ‘caret’ is not available and has been replaced
>> by .GlobalEnv when processing object ‘fit.ann’
>> Warning: namespace ‘ggplot2’ is not available and has been replaced
>> by .GlobalEnv when processing object ‘p1’
>> Warning: namespace ‘plotly’ is not available and has been replaced
>> by .GlobalEnv when processing object ‘p’
>> Warning: namespace ‘easyGgplot2’ is not available and has been replaced
>> by .GlobalEnv when processing object ‘plot’
>> Warning: namespace ‘RSNNS’ is not available and has been replaced
>> by .GlobalEnv when processing object ‘fit.mlp’
>> Warning: namespace ‘ipred’ is not available and has been replaced
>> by .GlobalEnv when processing object ‘fit.treebag’
>>
>> [[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/posti
>> ng-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] GlobalEnv error

2018-03-22 Thread William Dunlap via R-help
You haven't given much context, but these error message can come from
load() when loading a *.RData file that contains objects reference packages
not installed in the current installation of R.  When R starts it will load
a ".RData" file if one exists, this file is typically created when R shuts
down
and you ask it to save the current session.  If you recently upgraded R you
the newly installed R may not have all the packages that were installed in
the version that you last used.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Mar 22, 2018 at 2:07 PM, Haida  wrote:

> Dear all
>
> May I know how to solve this problem? I have encountered this problem after
> I have logged out from Rstudio. Thank you
>
> Warning: namespace ‘caret’ is not available and has been replaced
> by .GlobalEnv when processing object ‘fit.ann’
> Warning: namespace ‘ggplot2’ is not available and has been replaced
> by .GlobalEnv when processing object ‘p1’
> Warning: namespace ‘plotly’ is not available and has been replaced
> by .GlobalEnv when processing object ‘p’
> Warning: namespace ‘easyGgplot2’ is not available and has been replaced
> by .GlobalEnv when processing object ‘plot’
> Warning: namespace ‘RSNNS’ is not available and has been replaced
> by .GlobalEnv when processing object ‘fit.mlp’
> Warning: namespace ‘ipred’ is not available and has been replaced
> by .GlobalEnv when processing object ‘fit.treebag’
>
> [[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] GlobalEnv error

2018-03-22 Thread Jeff Newmiller
Error messages are useful, but without knowing what you did during your session 
it is hard to look more closely. It would also be helpful to see the output of 
the sessioInfo function, and the contents of your .Rprofile file in your home 
directory. Read the Posting Guide, which cautions you that this is a plain 
text-only mailing list... your "formatted" email gets damaged to some varying 
extent when it goes through the formatting stripper.

Also, this is an R support area, not an RStudio support area. You should 
confirm that these errors occur when you use R or RGui.
-- 
Sent from my phone. Please excuse my brevity.

On March 22, 2018 2:07:40 PM PDT, Haida  wrote:
>Dear all
>
>May I know how to solve this problem? I have encountered this problem
>after
>I have logged out from Rstudio. Thank you
>
>Warning: namespace ‘caret’ is not available and has been replaced
>by .GlobalEnv when processing object ‘fit.ann’
>Warning: namespace ‘ggplot2’ is not available and has been replaced
>by .GlobalEnv when processing object ‘p1’
>Warning: namespace ‘plotly’ is not available and has been replaced
>by .GlobalEnv when processing object ‘p’
>Warning: namespace ‘easyGgplot2’ is not available and has been replaced
>by .GlobalEnv when processing object ‘plot’
>Warning: namespace ‘RSNNS’ is not available and has been replaced
>by .GlobalEnv when processing object ‘fit.mlp’
>Warning: namespace ‘ipred’ is not available and has been replaced
>by .GlobalEnv when processing object ‘fit.treebag’
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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


[R] GlobalEnv error

2018-03-22 Thread Haida
Dear all

May I know how to solve this problem? I have encountered this problem after
I have logged out from Rstudio. Thank you

Warning: namespace ‘caret’ is not available and has been replaced
by .GlobalEnv when processing object ‘fit.ann’
Warning: namespace ‘ggplot2’ is not available and has been replaced
by .GlobalEnv when processing object ‘p1’
Warning: namespace ‘plotly’ is not available and has been replaced
by .GlobalEnv when processing object ‘p’
Warning: namespace ‘easyGgplot2’ is not available and has been replaced
by .GlobalEnv when processing object ‘plot’
Warning: namespace ‘RSNNS’ is not available and has been replaced
by .GlobalEnv when processing object ‘fit.mlp’
Warning: namespace ‘ipred’ is not available and has been replaced
by .GlobalEnv when processing object ‘fit.treebag’

[[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] adjusted values

2018-03-22 Thread Bert Gunter
Tis list is about R programming issues; statistical questons are generally
OT. The r-sig-mixed-models list would be a much better place to post your
queries.

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 Thu, Mar 22, 2018 at 8:43 AM, Cristiano Alessandro <
cri.alessan...@gmail.com> wrote:

> Hi all,
>
> I am fitting a linear mixed model with lme4 in R. The model has a single
> factor (des_days) with 4 levels (-1,1,14,48), and I am using random
> intercept and slopes.
>
> Fixed effects: data ~ des_days
>  Value   Std.Error  DF   t-value p-value
> (Intercept)  0.8274313 0.007937938 962 104.23757  0.
> des_days1   -0.0026322 0.007443294 962  -0.35363  0.7237
> des_days14  -0.0011319 0.006635512 962  -0.17058  0.8646
> des_days48   0.0112579 0.005452614 962   2.06469  0.0392
>
> I can clearly use the previous results to compare the estimations of each
> "des_day" to the intercept, using the provided t-statistics. Alternatively,
> I could use post-hoc tests (z-statistics):
>
> > ph_conditional <- c("des_days1  = 0",
>   "des_days14  = 0",
>   "des_days48 = 0");
> > lev.ph <- glht(lev.lm, linfct = ph_conditional);
> > summary(lev.ph)
>
> Simultaneous Tests for General Linear Hypotheses
>
> Fit: lme.formula(fixed = data ~ des_days, data = data_red_trf, random
> = ~des_days |
> ratID, method = "ML", na.action = na.omit, control = lCtr)
>
> Linear Hypotheses:
>  Estimate Std. Error z value Pr(>|z|)
> des_days1 == 0  -0.002632   0.007428  -0.3540.971
> des_days14 == 0 -0.001132   0.006622  -0.1710.996
> des_days48 == 0  0.011258   0.005441   2.0690.101
> (Adjusted p values reported -- single-step method)
>
>
> The p-values of the coefficient estimates and those of the post-hoc tests
> differ because the latter are adjusted with Bonferroni correction. I wonder
> whether there is any form of correction in the coefficient estimated of the
> LMM, and which p-values are more appropriate to use.
>
> Thanks
> Cristiano
>
> [[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] how to add a child to a child in XML

2018-03-22 Thread David L Carlson
It is not listed in the table of contents, but as Ben mentioned, it is 
documented with newXMLDoc (pages 52-58) along with newXMLDoc, newHTMLDoc, 
newXMLTextNode, newXMLCDataNode, newXMLCommentNoe, newXMLPINode, and 
newXMLDTDNode on page 53:

newXMLNode(name, ..., attrs = NULL, namespace = character(),
 namespaceDefinitions = character(),
 doc = NULL, .children = list(...), parent = NULL,
 at = NA, cdata = FALSE, suppressNamespaceWarning =
 getOption("suppressXMLNamespaceWarning", FALSE),
 sibling = NULL, addFinalizer = NA,
 noNamespace = length(namespace) == 0 && !missing(namespace),
 fixNamespaces = c(dummy = TRUE, default = TRUE))


David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352

-Original Message-
From: R-help  On Behalf Of Bond, Stephen
Sent: Thursday, March 22, 2018 9:51 AM
To: 'Ben Tupper' 
Cc: 'r-help' 
Subject: Re: [R] how to add a child to a child in XML

Just to clarify and hopefully catch the attention of the maintainer:

The newXMLNode function is not mentioned in:

https://cran.r-project.org/web/packages/XML/XML.pdf

which supposedly describes all functions in the package.


Stephen

From: Ben Tupper [mailto:btup...@bigelow.org]
Sent: Thursday, March 22, 2018 10:40 AM
To: Bond, Stephen
Cc: r-help
Subject: Re: [R] how to add a child to a child in XML

Hi,

It's a reasonable question. The answer is that it actually is included, but 
there are many instances across packages where multiple functions are 
documented on a single help page.  The following brings up such a page... (for 
XML_3.98-1.9)

> library(XML)
> ?newXMLNode

You can see the same on line...

https://www.rdocumentation.org/packages/XML/versions/3.98-1.9/topics/newXMLDoc

You have dig in to find it.

If you are just starting out with XML, you might want to spend some time 
comparison shopping with the xml2 package. 
https://www.rdocumentation.org/packages/xml2/versions/1.2.0  I like each one, 
and I use both XML and xml2 (not at the same time). I have been slowly 
migrating toward xml2 as I use more of the tidyverse stuff.

Cheers,
Ben

On Mar 22, 2018, at 9:19 AM, Bond, Stephen 
mailto:stephen.b...@cibc.com>> wrote:

Big thanks. newXMLNode works great. Wonder why it is not included in the 
documentation.
There is newXMLDoc and newXMLNamespace, but no mention of newXMLNode.

Stephen

From: Ben Tupper [mailto:btup...@bigelow.org]
Sent: Wednesday, March 21, 2018 6:18 PM
To: Bond, Stephen
Cc: r-help
Subject: Re: [R] how to add a child to a child in XML

Hi,

XML doesn't use the `$` to access child nodes.  Instead use either `[name]` to 
get a list of children of that name or `[[name]]` to get the just the first 
child of that name encountered in the genealogy.  Thus for your example...

> root$child1
NULL

> root[['child1']]



On the other hand, you might consider using newXMLNode() instead of xmlNode() 
as it accepts a "parent = " argument.  The alternative using newXMLNode() would 
look like...

atts_root <- c("val1","val2","val3")
names(atts_root) <- c("att1","att2","att3") root <- newXMLNode("root", attrs = 
atts_root)

atts_child <- LETTERS[1:3]
names(atts_child) <- paste("name",1:3,sep="") child <- newXMLNode("child",attrs 
= atts_child, parent = root)

atts_grandchild <- letters[1:3]
names(atts_grandchild) <- paste("name",4:6,sep="") grandchild <- 
newXMLNode("grandchild",attrs = atts_grandchild, parent = child)

root
# #  
#
#  
#


Cheers,
Ben

On Mar 21, 2018, at 4:25 PM, Bond, Stephen 
mailto:stephen.b...@cibc.com>> wrote:

I am trying to add a child to a child using XML package in R. the following 
fails

library(XML)

node1 <- c("val1","val2","val3")

names(node1) <- c("att1","att2","att3")

root <- xmlNode("root", attrs=node1)

node2 <- LETTERS[1:3]

names(node2) <- paste("name",1:3,sep="")

root <- addChildren(root,xmlNode("child1",attrs=node2))

node3 <- letters[1:3]

names(node3) <- paste("name",4:6,sep="")

root <- addChildren(root$child1,xmlNode("child2",attrs=node3))



Error in UseMethod("addChildren") : no applicable method for 'addChildren' 
applied to an object of class "NULL"


Stephen B


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

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Tick Forecasting: https://eco.bigelow.org/

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Tick Forecasting: https://eco.bigelow.org/





Re: [R] Sum of columns of a data frame equal to NA when all the elements are NA

2018-03-22 Thread Jeff Newmiller
I can see that one might regard having

sum( sum( 1 ), sum( NULL ) ) == sum( 1 )

be TRUE as a necessary consistency, but going down that road one might expect 
Bert's

v+NULL == v

for all numeric vectors also. I have always avoided that construction as poor 
computing practice, but if NULL is supposed to represent the empty set 
mathematically [1] then this would seem to follow. 

[1] 
https://cran.r-project.org/doc/contrib/de_Jonge+van_der_Loo-Introduction_to_data_cleaning_with_R.pdf

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

On March 21, 2018 1:06:46 PM PDT, Bert Gunter  wrote:
>"I see: consistency with additive identity. "
>
>Ummm, well:
>
>> 1+NULL
>numeric(0)
>
>> sum(1,NULL)
>[1] 1
>
>Of course, there could well be something here I don't get, but that
>doesn't
>look very consistent to me. However, as I said privately, so long as
>the
>corner case behavior is documented, which it is, I don't care.
>
>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 Wed, Mar 21, 2018 at 10:26 AM, Boris Steipe
>
>wrote:
>
>> I see: consistency with additive identity. That makes sense. Thanks.
>>
>> B.
>>
>>
>> > On Mar 21, 2018, at 1:22 PM, peter dalgaard 
>wrote:
>> >
>> > No. The empty sum is zero. Adding it to another sum should not
>change
>> it. Nothing audacious about that. This is consistent; other
>definitions
>> just cause trouble.
>> >
>> > -pd
>> >
>> >> On 21 Mar 2018, at 18:05 , Boris Steipe 
>> wrote:
>> >>
>> >> Surely the result of summation of non-existent values is not
>defined,
>> is it not? And since the NA values have been _removed_, there's
>nothing
>> left to sum over. In fact, pretending the the result in that case is
>zero
>> would appear audacious, no?
>> >>
>> >> Cheers,
>> >> Boris
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>> On Mar 21, 2018, at 12:58 PM, Jeff Newmiller
>
>> wrote:
>> >>>
>> >>> What do you mean by "should not"?
>> >>>
>> >>> NULL means "missing object" in R. The result of the sum function
>is
>> always expected to be numeric... so NA_real or NA_integer could make
>sense
>> as possible return values. But you cannot compute on NULL so no, that
>> doesn't work.
>> >>>
>> >>> See the note under the "Value" section of ?sum as to why zero is
>> returned when all inputs are removed.
>> >>> --
>> >>> Sent from my phone. Please excuse my brevity.
>> >>>
>> >>> On March 21, 2018 9:03:29 AM PDT, Boris Steipe <
>> boris.ste...@utoronto.ca> wrote:
>>  Should not the result be NULL if you have removed the NA with
>>  na.rm=TRUE ?
>> 
>>  B.
>> 
>> 
>> 
>> > On Mar 21, 2018, at 11:44 AM, Stefano Sofia
>>   wrote:
>> >
>> > Dear list users,
>> > let me ask you this trivial question. I worked on that for a
>long
>>  time, by now.
>> > Suppose to have a data frame with NAs and to sum some columns
>with
>>  rowSums:
>> >
>> > df <- data.frame(A = runif(10), B = runif(10), C = rnorm(10))
>> > df[1, ] <- NA
>> > rowSums(df[ , which(names(df) %in% c("A","B"))], na.rm=T)
>> >
>> > If all the elements of the selected columns are NA, rowSums
>returns 0
>>  while I need NA.
>> > Is there an easy and efficient way to use rowSums within a
>function
>>  like
>> >
>> > function(x) ifelse(all(is.na(x)), as.numeric(NA), rowSums...)?
>> >
>> > or an equivalent function?
>> >
>> > Thank you for your help
>> > Stefano
>> >
>> >
>> >
>> >  (oo)
>> > --oOO--( )--OOo
>> > Stefano Sofia PhD
>> > Area Meteorologica e  Area nivologica - Centro Funzionale
>> > Servizio Protezione Civile - Regione Marche
>> > Via del Colle Ameno 5
>> > 60126 Torrette di Ancona, Ancona
>> > Uff: 071 806 7743
>> > E-mail: stefano.so...@regione.marche.it
>> > ---Oo-oO
>> >
>> > 
>> >
>> > AVVISO IMPORTANTE: Questo messaggio di posta elettronica può
>>  contenere informazioni confidenziali, pertanto è destinato solo
>a
>>  persone autorizzate alla ricezione. I messaggi di posta
>elettronica
>> per
>>  i client di Regione Marche possono contenere informazioni
>> confidenziali
>>  e con privilegi legali. Se non si è il destinatario specificato,
>non
>>  leggere, copiare, inoltrare o archiviare questo messaggio. Se si
>è
>>  ricevuto questo messaggio per errore, inoltrarlo al mittente ed
>>  eliminarlo completamente dal sistema del proprio computer. Ai
>sensi
>>  dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di
>> necessità
>>  ed urgenza, la risposta al presente messaggio di posta
>elettronica può
>>  essere visionata da persone estranee al destinatario.
>> > IMPORTANT NOTICE: This e-mail message is intended to be
>received only
>>  by persons entitled 

[R] adjusted values

2018-03-22 Thread Cristiano Alessandro
Hi all,

I am fitting a linear mixed model with lme4 in R. The model has a single
factor (des_days) with 4 levels (-1,1,14,48), and I am using random
intercept and slopes.

Fixed effects: data ~ des_days
 Value   Std.Error  DF   t-value p-value
(Intercept)  0.8274313 0.007937938 962 104.23757  0.
des_days1   -0.0026322 0.007443294 962  -0.35363  0.7237
des_days14  -0.0011319 0.006635512 962  -0.17058  0.8646
des_days48   0.0112579 0.005452614 962   2.06469  0.0392

I can clearly use the previous results to compare the estimations of each
"des_day" to the intercept, using the provided t-statistics. Alternatively,
I could use post-hoc tests (z-statistics):

> ph_conditional <- c("des_days1  = 0",
  "des_days14  = 0",
  "des_days48 = 0");
> lev.ph <- glht(lev.lm, linfct = ph_conditional);
> summary(lev.ph)

Simultaneous Tests for General Linear Hypotheses

Fit: lme.formula(fixed = data ~ des_days, data = data_red_trf, random
= ~des_days |
ratID, method = "ML", na.action = na.omit, control = lCtr)

Linear Hypotheses:
 Estimate Std. Error z value Pr(>|z|)
des_days1 == 0  -0.002632   0.007428  -0.3540.971
des_days14 == 0 -0.001132   0.006622  -0.1710.996
des_days48 == 0  0.011258   0.005441   2.0690.101
(Adjusted p values reported -- single-step method)


The p-values of the coefficient estimates and those of the post-hoc tests
differ because the latter are adjusted with Bonferroni correction. I wonder
whether there is any form of correction in the coefficient estimated of the
LMM, and which p-values are more appropriate to use.

Thanks
Cristiano

[[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] How do I include a factor in a groupedData object? Meaning and use of inner and outer parameters

2018-03-22 Thread Sorkin, John
Michael,

I apprecate your response. The inner and outer parameters to do not affect the 
results produced by lme. I am still left with the same questions I had before;

(1) How does one include factors in groupData

(2) What is the meaning and use of the outer and inner parameters in groupData?

Thank you again,

John


John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)




From: Michael Dewey 
Sent: Thursday, March 22, 2018 10:30 AM
To: Sorkin, John; RHELP 
Subject: Re: [R] How do I include a factor in a groupedData object? Meaning and 
use of inner and outer parameters

CAUTION: This message originated from a non UMB, UMSOM, FPI, or UMMS email 
system. Whether the sender is known or not known, hover over any links before 
clicking and use caution opening attachments.



Dear John

You are only allowed to have the primary covariate on the left hand side
of the vertical bar. Other covariates go in inner or outer.

Michael

On 22/03/2018 12:59, Sorkin, John wrote:
> Windows 10 64-bit, R-Studio, R version 3.4.3
>
>
> Several questions relating to groupedData:
>
> (1) I am trying to create a groupedData object that can be used to run an 
> analysis that I have been able to urn using lmer. When I include the 
> interaction terms in the groupedData opbject I get an error message stating 
> that + is not meaningful for factors. How do I include factors in my model? 
> See code and error below.
>
> (2) I have read the help file for groupedData multiple times. I am unable to 
> understand the meaning or, or the use for the inner= and outer= parameters in 
> the call to groupedData. Can someone either explain the meaning of these 
> parameters or refer me to a source that give a clear explanation?
>
>
>> fit0 <- 
>> lmer(THmean~INTRVNTN+factor(TimePtID)+INTRVNTN*factor(TimePtID)+(1|PatientID),data=smalldata)
>> sdgd <- 
>> groupedData(THmean~INTRVNTN+TimePtID+INTRVNTN*TimePtID|PatientID,data=smalldata)
> Warning messages:
> 1: In Ops.factor(INTRVNTN, TimePtID) : �+� not meaningful for factors
> 2: In Ops.factor(INTRVNTN, TimePtID) : �*� not meaningful for factors
>
>
> Thank you,
>
> John
>
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and 
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
>
>   [[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] Pin package/s

2018-03-22 Thread Luis Puerto
Hi! 

I don’t know if you know package manager for macOS Homebrew. With Homebrew 
there is a way to stop update certain packages: 

brew pin 

Does anyone know a way to do a similar thing with R packages? 

In the same way, it would be great to be able to receive a notification –an 
email– when a new version of a package reach CRAN or any other repository. 

I would like to have something like this because the Data Table package has a 
certain makevars necessities when it’s built in a Homebrew R install. It isn’t 
really problematic since it the package hasn’t built correctly when you load it 
on R it will display a message. However, I’m thinking that perhaps something 
like this could be useful also for other packages. 

Thanks! 


[[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] How do I include a factor in a groupedData object? Meaning and use of inner and outer parameters

2018-03-22 Thread Bert Gunter
r-sig-mixed-models is likely to be a better list for such queries.

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 Thu, Mar 22, 2018 at 5:59 AM, Sorkin, John 
wrote:

> Windows 10 64-bit, R-Studio, R version 3.4.3
>
>
> Several questions relating to groupedData:
>
> (1) I am trying to create a groupedData object that can be used to run an
> analysis that I have been able to urn using lmer. When I include the
> interaction terms in the groupedData opbject I get an error message stating
> that + is not meaningful for factors. How do I include factors in my model?
> See code and error below.
>
> (2) I have read the help file for groupedData multiple times. I am unable
> to understand the meaning or, or the use for the inner= and outer=
> parameters in the call to groupedData. Can someone either explain the
> meaning of these parameters or refer me to a source that give a clear
> explanation?
>
>
> > fit0 <- lmer(THmean~INTRVNTN+factor(TimePtID)+INTRVNTN*factor(
> TimePtID)+(1|PatientID),data=smalldata)
> > sdgd <- groupedData(THmean~INTRVNTN+TimePtID+INTRVNTN*TimePtID|
> PatientID,data=smalldata)
> Warning messages:
> 1: In Ops.factor(INTRVNTN, TimePtID) : ‘+’ not meaningful for factors
> 2: In Ops.factor(INTRVNTN, TimePtID) : ‘*’ not meaningful for factors
>
>
> Thank you,
>
> John
>
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
>
> [[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] how to add a child to a child in XML

2018-03-22 Thread Bond, Stephen
Just to clarify and hopefully catch the attention of the maintainer:

The newXMLNode function is not mentioned in:

https://cran.r-project.org/web/packages/XML/XML.pdf

which supposedly describes all functions in the package.


Stephen

From: Ben Tupper [mailto:btup...@bigelow.org]
Sent: Thursday, March 22, 2018 10:40 AM
To: Bond, Stephen
Cc: r-help
Subject: Re: [R] how to add a child to a child in XML

Hi,

It's a reasonable question. The answer is that it actually is included, but 
there are many instances across packages where multiple functions are 
documented on a single help page.  The following brings up such a page... (for 
XML_3.98-1.9)

> library(XML)
> ?newXMLNode

You can see the same on line...

https://www.rdocumentation.org/packages/XML/versions/3.98-1.9/topics/newXMLDoc

You have dig in to find it.

If you are just starting out with XML, you might want to spend some time 
comparison shopping with the xml2 package. 
https://www.rdocumentation.org/packages/xml2/versions/1.2.0  I like each one, 
and I use both XML and xml2 (not at the same time). I have been slowly 
migrating toward xml2 as I use more of the tidyverse stuff.

Cheers,
Ben

On Mar 22, 2018, at 9:19 AM, Bond, Stephen 
mailto:stephen.b...@cibc.com>> wrote:

Big thanks. newXMLNode works great. Wonder why it is not included in the 
documentation.
There is newXMLDoc and newXMLNamespace, but no mention of newXMLNode.

Stephen

From: Ben Tupper [mailto:btup...@bigelow.org]
Sent: Wednesday, March 21, 2018 6:18 PM
To: Bond, Stephen
Cc: r-help
Subject: Re: [R] how to add a child to a child in XML

Hi,

XML doesn't use the `$` to access child nodes.  Instead use either `[name]` to 
get a list of children of that name or `[[name]]` to get the just the first 
child of that name encountered in the genealogy.  Thus for your example...

> root$child1
NULL

> root[['child1']]



On the other hand, you might consider using newXMLNode() instead of xmlNode() 
as it accepts a "parent = " argument.  The alternative using newXMLNode() would 
look like...

atts_root <- c("val1","val2","val3")
names(atts_root) <- c("att1","att2","att3")
root <- newXMLNode("root", attrs = atts_root)

atts_child <- LETTERS[1:3]
names(atts_child) <- paste("name",1:3,sep="")
child <- newXMLNode("child",attrs = atts_child, parent = root)

atts_grandchild <- letters[1:3]
names(atts_grandchild) <- paste("name",4:6,sep="")
grandchild <- newXMLNode("grandchild",attrs = atts_grandchild, parent = child)

root
#
#  
#
#  
#


Cheers,
Ben

On Mar 21, 2018, at 4:25 PM, Bond, Stephen 
mailto:stephen.b...@cibc.com>> wrote:

I am trying to add a child to a child using XML package in R. the following 
fails

library(XML)

node1 <- c("val1","val2","val3")

names(node1) <- c("att1","att2","att3")

root <- xmlNode("root", attrs=node1)

node2 <- LETTERS[1:3]

names(node2) <- paste("name",1:3,sep="")

root <- addChildren(root,xmlNode("child1",attrs=node2))

node3 <- letters[1:3]

names(node3) <- paste("name",4:6,sep="")

root <- addChildren(root$child1,xmlNode("child2",attrs=node3))



Error in UseMethod("addChildren") : no applicable method for 'addChildren' 
applied to an object of class "NULL"


Stephen B


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

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Tick Forecasting: https://eco.bigelow.org/

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Tick Forecasting: https://eco.bigelow.org/




[[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] how to add a child to a child in XML

2018-03-22 Thread Ben Tupper
Hi,

It's a reasonable question. The answer is that it actually is included, but 
there are many instances across packages where multiple functions are 
documented on a single help page.  The following brings up such a page... (for 
XML_3.98-1.9)

> library(XML)
> ?newXMLNode

You can see the same on line...

https://www.rdocumentation.org/packages/XML/versions/3.98-1.9/topics/newXMLDoc

You have dig in to find it.  

If you are just starting out with XML, you might want to spend some time 
comparison shopping with the xml2 package. 
https://www.rdocumentation.org/packages/xml2/versions/1.2.0 
  I like each one, 
and I use both XML and xml2 (not at the same time). I have been slowly 
migrating toward xml2 as I use more of the tidyverse stuff.

Cheers,
Ben

> On Mar 22, 2018, at 9:19 AM, Bond, Stephen  wrote:
> 
> Big thanks. newXMLNode works great. Wonder why it is not included in the 
> documentation.
> There is newXMLDoc and newXMLNamespace, but no mention of newXMLNode.
>  
> Stephen
>  
> From: Ben Tupper [mailto:btup...@bigelow.org] 
> Sent: Wednesday, March 21, 2018 6:18 PM
> To: Bond, Stephen
> Cc: r-help
> Subject: Re: [R] how to add a child to a child in XML
>  
> Hi,
>  
> XML doesn't use the `$` to access child nodes.  Instead use either `[name]` 
> to get a list of children of that name or `[[name]]` to get the just the 
> first child of that name encountered in the genealogy.  Thus for your 
> example...
>  
> > root$child1
> NULL
>  
> > root[['child1']]
> 
>  
>  
> On the other hand, you might consider using newXMLNode() instead of xmlNode() 
> as it accepts a "parent = " argument.  The alternative using newXMLNode() 
> would look like...
>  
> atts_root <- c("val1","val2","val3")
> names(atts_root) <- c("att1","att2","att3")
> root <- newXMLNode("root", attrs = atts_root)
>  
> atts_child <- LETTERS[1:3]
> names(atts_child) <- paste("name",1:3,sep="")
> child <- newXMLNode("child",attrs = atts_child, parent = root)
>  
> atts_grandchild <- letters[1:3]
> names(atts_grandchild) <- paste("name",4:6,sep="")
> grandchild <- newXMLNode("grandchild",attrs = atts_grandchild, parent = child)
>  
> root
> #
> #  
> #
> #  
> # 
>  
>  
> Cheers,
> Ben
>  
> On Mar 21, 2018, at 4:25 PM, Bond, Stephen  > wrote:
>  
> I am trying to add a child to a child using XML package in R. the following 
> fails
> 
> library(XML)
> 
> node1 <- c("val1","val2","val3")
> 
> names(node1) <- c("att1","att2","att3")
> 
> root <- xmlNode("root", attrs=node1)
> 
> node2 <- LETTERS[1:3]
> 
> names(node2) <- paste("name",1:3,sep="")
> 
> root <- addChildren(root,xmlNode("child1",attrs=node2))
> 
> node3 <- letters[1:3]
> 
> names(node3) <- paste("name",4:6,sep="")
> 
> root <- addChildren(root$child1,xmlNode("child2",attrs=node3))
> 
> 
> 
> Error in UseMethod("addChildren") : no applicable method for 'addChildren' 
> applied to an object of class "NULL"
> 
> 
> Stephen B
> 
> 
> [[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.
> 
>  
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org 
>  
> Tick Forecasting: https://eco.bigelow.org/ 
Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Tick Forecasting: https://eco.bigelow.org/





[[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] How do I include a factor in a groupedData object? Meaning and use of inner and outer parameters

2018-03-22 Thread Michael Dewey

Dear John

You are only allowed to have the primary covariate on the left hand side 
of the vertical bar. Other covariates go in inner or outer.


Michael

On 22/03/2018 12:59, Sorkin, John wrote:

Windows 10 64-bit, R-Studio, R version 3.4.3


Several questions relating to groupedData:

(1) I am trying to create a groupedData object that can be used to run an 
analysis that I have been able to urn using lmer. When I include the 
interaction terms in the groupedData opbject I get an error message stating 
that + is not meaningful for factors. How do I include factors in my model? See 
code and error below.

(2) I have read the help file for groupedData multiple times. I am unable to 
understand the meaning or, or the use for the inner= and outer= parameters in 
the call to groupedData. Can someone either explain the meaning of these 
parameters or refer me to a source that give a clear explanation?



fit0 <- 
lmer(THmean~INTRVNTN+factor(TimePtID)+INTRVNTN*factor(TimePtID)+(1|PatientID),data=smalldata)
sdgd <- 
groupedData(THmean~INTRVNTN+TimePtID+INTRVNTN*TimePtID|PatientID,data=smalldata)

Warning messages:
1: In Ops.factor(INTRVNTN, TimePtID) : �+� not meaningful for factors
2: In Ops.factor(INTRVNTN, TimePtID) : �*� not meaningful for factors


Thank you,

John


John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)


[[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] how to add a child to a child in XML

2018-03-22 Thread Bond, Stephen
Big thanks. newXMLNode works great. Wonder why it is not included in the 
documentation.
There is newXMLDoc and newXMLNamespace, but no mention of newXMLNode.

Stephen

From: Ben Tupper [mailto:btup...@bigelow.org]
Sent: Wednesday, March 21, 2018 6:18 PM
To: Bond, Stephen
Cc: r-help
Subject: Re: [R] how to add a child to a child in XML

Hi,

XML doesn't use the `$` to access child nodes.  Instead use either `[name]` to 
get a list of children of that name or `[[name]]` to get the just the first 
child of that name encountered in the genealogy.  Thus for your example...

> root$child1
NULL

> root[['child1']]



On the other hand, you might consider using newXMLNode() instead of xmlNode() 
as it accepts a "parent = " argument.  The alternative using newXMLNode() would 
look like...

atts_root <- c("val1","val2","val3")
names(atts_root) <- c("att1","att2","att3")
root <- newXMLNode("root", attrs = atts_root)

atts_child <- LETTERS[1:3]
names(atts_child) <- paste("name",1:3,sep="")
child <- newXMLNode("child",attrs = atts_child, parent = root)

atts_grandchild <- letters[1:3]
names(atts_grandchild) <- paste("name",4:6,sep="")
grandchild <- newXMLNode("grandchild",attrs = atts_grandchild, parent = child)

root
#
#  
#
#  
#


Cheers,
Ben

On Mar 21, 2018, at 4:25 PM, Bond, Stephen 
mailto:stephen.b...@cibc.com>> wrote:

I am trying to add a child to a child using XML package in R. the following 
fails

library(XML)

node1 <- c("val1","val2","val3")

names(node1) <- c("att1","att2","att3")

root <- xmlNode("root", attrs=node1)

node2 <- LETTERS[1:3]

names(node2) <- paste("name",1:3,sep="")

root <- addChildren(root,xmlNode("child1",attrs=node2))

node3 <- letters[1:3]

names(node3) <- paste("name",4:6,sep="")

root <- addChildren(root$child1,xmlNode("child2",attrs=node3))



Error in UseMethod("addChildren") : no applicable method for 'addChildren' 
applied to an object of class "NULL"


Stephen B


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

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Tick Forecasting: https://eco.bigelow.org/




[[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] How do I include a factor in a groupedData object? Meaning and use of inner and outer parameters

2018-03-22 Thread Sorkin, John
Windows 10 64-bit, R-Studio, R version 3.4.3


Several questions relating to groupedData:

(1) I am trying to create a groupedData object that can be used to run an 
analysis that I have been able to urn using lmer. When I include the 
interaction terms in the groupedData opbject I get an error message stating 
that + is not meaningful for factors. How do I include factors in my model? See 
code and error below.

(2) I have read the help file for groupedData multiple times. I am unable to 
understand the meaning or, or the use for the inner= and outer= parameters in 
the call to groupedData. Can someone either explain the meaning of these 
parameters or refer me to a source that give a clear explanation?


> fit0 <- 
> lmer(THmean~INTRVNTN+factor(TimePtID)+INTRVNTN*factor(TimePtID)+(1|PatientID),data=smalldata)
> sdgd <- 
> groupedData(THmean~INTRVNTN+TimePtID+INTRVNTN*TimePtID|PatientID,data=smalldata)
Warning messages:
1: In Ops.factor(INTRVNTN, TimePtID) : �+� not meaningful for factors
2: In Ops.factor(INTRVNTN, TimePtID) : �*� not meaningful for factors


Thank you,

John


John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)


[[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] exporting data to stata

2018-03-22 Thread Anthony Damico
hi, you can export the dataset from an R  survey design to stata with

install.packages('survey')
library(survey)
library(foreign)
write.dta( data1$variables , "c:/path/to/file.dta" )

then type "data1" into the R console to look at the weight, id/cluster,
strata, and fpc variables to use for the "svyset" command




On Thu, Mar 22, 2018, 12:33 PM Ista Zahn  wrote:

> On Thu, Mar 22, 2018 at 4:52 AM, Raja, Dr. Edwin Amalraj
>  wrote:
> > Hi ,
> >
> > library(foreign)
> > write.dta(data1,  "data1.dta")
> >
> > should work.
>
>
> I don't think so:
>
> > library(foreign)
> > example(svydesign)
> > write.dta(dstrat, "~/Downloads/foo.dta")
> Error in write.dta(dstrat, "~/Downloads/foo.dta") :
>   The object "dataframe" must have class data.frame
>
>
> The file will be saved in the working directory.
> > Use
> > getwd()
> > to know the working directory.
> >
> > Best wishes
> > Amalraj Raja
> >
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of rosario
> scandurra
> > Sent: 22 March 2018 07:47
> > To: r-help@r-project.org
> > Subject: [R] exporting data to stata
> >
> > Hi,
> >
> > I am new to R and I want to export data into Stata. Could somebody help
> with that? Thanks a lot.
> >
> > This is the code I am using:
> >
> >
> >> setwd("D:/datasets/Seg-bcn/ESBD")
> >> data1 <- readRDS("r17045_ESDB_Habitatges_BDD_V_1_0.rds")
> >> library(foreign)
> >> write.dta(data="data1", file = "D:/datasets/data1.dta")
> > Error in write.dta(data = "data1", file = "D:/datasets/data1.dta") :
> >   The object "dataframe" must have class data.frame
> >> class (data1)
> > [1] "survey.design2" "survey.design"
> >
> >
> > [[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.
> >
> >
> > The University of Aberdeen is a charity registered in Scotland, No
> SC013683.
> > Tha Oilthigh Obar Dheathain na charthannas clàraichte ann an Alba, Àir.
> SC013683.
> > __
> > 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.
>

[[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] exporting data to stata

2018-03-22 Thread Ista Zahn
On Thu, Mar 22, 2018 at 4:52 AM, Raja, Dr. Edwin Amalraj
 wrote:
> Hi ,
>
> library(foreign)
> write.dta(data1,  "data1.dta")
>
> should work.


I don't think so:

> library(foreign)
> example(svydesign)
> write.dta(dstrat, "~/Downloads/foo.dta")
Error in write.dta(dstrat, "~/Downloads/foo.dta") :
  The object "dataframe" must have class data.frame


The file will be saved in the working directory.
> Use
> getwd()
> to know the working directory.
>
> Best wishes
> Amalraj Raja
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of rosario 
> scandurra
> Sent: 22 March 2018 07:47
> To: r-help@r-project.org
> Subject: [R] exporting data to stata
>
> Hi,
>
> I am new to R and I want to export data into Stata. Could somebody help with 
> that? Thanks a lot.
>
> This is the code I am using:
>
>
>> setwd("D:/datasets/Seg-bcn/ESBD")
>> data1 <- readRDS("r17045_ESDB_Habitatges_BDD_V_1_0.rds")
>> library(foreign)
>> write.dta(data="data1", file = "D:/datasets/data1.dta")
> Error in write.dta(data = "data1", file = "D:/datasets/data1.dta") :
>   The object "dataframe" must have class data.frame
>> class (data1)
> [1] "survey.design2" "survey.design"
>
>
> [[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.
>
>
> The University of Aberdeen is a charity registered in Scotland, No SC013683.
> Tha Oilthigh Obar Dheathain na charthannas clàraichte ann an Alba, Àir. 
> SC013683.
> __
> 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] exporting data to stata

2018-03-22 Thread Michael Dewey

Dear Rosario

Your object called data1 is, as you showed us, of the wrong class. You 
therefore need to convert it in some way although i suspect you will 
then use the survey information.


Michael.

On 22/03/2018 07:46, rosario scandurra wrote:

Hi,

I am new to R and I want to export data into Stata. Could somebody help with 
that? Thanks a lot.

This is the code I am using:



setwd("D:/datasets/Seg-bcn/ESBD")
data1 <- readRDS("r17045_ESDB_Habitatges_BDD_V_1_0.rds")
library(foreign)
write.dta(data="data1", file = "D:/datasets/data1.dta")

Error in write.dta(data = "data1", file = "D:/datasets/data1.dta") :
   The object "dataframe" must have class data.frame

class (data1)

[1] "survey.design2" "survey.design"


[[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] R 3.4.4, internet access fails on Windows XP

2018-03-22 Thread Holger Taschenberger
Dear Duncan,

thank you for your reply.

On Wed, 21 Mar 2018 11:58:15 -0400
Duncan Murdoch  wrote:

 
> The Windows FAQ 2.2 says, "Windows XP is no longer supported", so I think 
> you're out of luck.  XP went past "end-of-life" in 2014.
> 

on  it says

"R 3.4.4 for Windows
===

This distribution contains a binary distribution of R-3.4.4 to run on
Windows XP and later (including 64-bit versions of Windows) on ix86
and x86_64 chips."

> Other than switching to a more recent Windows version, your choices are 
> switching to a completely different OS, or switching to an older version of R.

R i386 runs without problems on Windows XP up to and including version 3.4.2.
Only R i386 3.4.3 & R i386 3.4.4 cannot access the internet on my Windows XP.

I supposed this is not so much a problem with the OS (because "IdnToAscii" 
exists on WindowsXP SP3 as well), but rather with the header files and/or 
import libraries of the MinGW environment.

Perhaps it does not take too much effort to restore WindowsXP compatibility. 
The described symptoms are at least easy to debug.

I know that WindowsXP is no longer supported by Microsoft. However, I work in 
an academic environment and we are stuck to Windows XP on some computers 
because some of our data acquisition devices are only properly supported on 
that OS.

Regardless of your conclusion, I'm thankful to the R developer team to make the 
R software freely available to the scientific community.

With kind regards,
Holger

__
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] Sum of columns of a data frame equal to NA when all the elements are NA

2018-03-22 Thread Stefano Sofia
Thank you.
Perfect solution.

Stefano

 (oo)
--oOO--( )--OOo
Stefano Sofia PhD
Area Meteorologica e  Area nivologica - Centro Funzionale
Servizio Protezione Civile - Regione Marche
Via del Colle Ameno 5
60126 Torrette di Ancona, Ancona
Uff: 071 806 7743
E-mail: stefano.so...@regione.marche.it
---Oo-oO

Da: Duncan Murdoch [murdoch.dun...@gmail.com]
Inviato: mercoledì 21 marzo 2018 17.01
A: Stefano Sofia; r-help@r-project.org
Oggetto: Re: [R] Sum of columns of a data frame equal to NA when all the 
elements are NA

On 21/03/2018 11:44 AM, Stefano Sofia wrote:
> Dear list users,
> let me ask you this trivial question. I worked on that for a long time, by 
> now.
> Suppose to have a data frame with NAs and to sum some columns with rowSums:
>
> df <- data.frame(A = runif(10), B = runif(10), C = rnorm(10))
> df[1, ] <- NA
> rowSums(df[ , which(names(df) %in% c("A","B"))], na.rm=T)
>
> If all the elements of the selected columns are NA, rowSums returns 0 while I 
> need NA.
> Is there an easy and efficient way to use rowSums within a function like
>
> function(x) ifelse(all(is.na(x)), as.numeric(NA), rowSums...)?
>
> or an equivalent function?

Something like

apply(df[,c("A", "B")], 1, function(x) if (all(is.na(x))) NA else sum(x,
na.rm = TRUE))

should do what you want.

Duncan Murdoch

>
> Thank you for your help
> Stefano
>
>
>
>   (oo)
> --oOO--( )--OOo
> Stefano Sofia PhD
> Area Meteorologica e  Area nivologica - Centro Funzionale
> Servizio Protezione Civile - Regione Marche
> Via del Colle Ameno 5
> 60126 Torrette di Ancona, Ancona
> Uff: 071 806 7743
> E-mail: stefano.so...@regione.marche.it
> ---Oo-oO
>
> 
>
> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
> informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
> alla ricezione. I messaggi di posta elettronica per i client di Regione 
> Marche possono contenere informazioni confidenziali e con privilegi legali. 
> Se non si è il destinatario specificato, non leggere, copiare, inoltrare o 
> archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, 
> inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio 
> computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso 
> di necessità ed urgenza, la risposta al presente messaggio di posta 
> elettronica può essere visionata da persone estranee al destinatario.
> IMPORTANT NOTICE: This e-mail message is intended to be received only by 
> persons entitled to receive the confidential information it may contain. 
> E-mail messages to clients of Regione Marche may contain information that is 
> confidential and legally privileged. Please do not read, copy, forward, or 
> store this message unless you are an intended recipient of it. If you have 
> received this message in error, please forward it to the sender and delete it 
> completely from your computer system.
>
> --
> Questo messaggio  stato analizzato da Libra ESVA ed  risultato non infetto.
> This message was scanned by Libra ESVA and is believed to be clean.
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>  
> https://urlsand.esvalabs.com/?u=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&e=52342f8a&h=d46bc785&f=y&p=y
> PLEASE do read the posting guide  
> https://urlsand.esvalabs.com/?u=http%3A%2F%2Fwww.R-project.org%2Fposting-guide.html&e=52342f8a&h=9b25bfd5&f=y&p=y
> and provide commented, minimal, self-contained, reproducible code.
>


--

Questo messaggio  stato analizzato con Libra ESVA ed  risultato non infetto.




AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
alla ricezione. I messaggi di posta elettronica per i client di Regione Marche 
possono contenere informazioni confidenziali e con privilegi legali. Se non si 
è il destinatario specificato, non leggere, copiare, inoltrare o archiviare 
questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al 
mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi 
dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed 
urgenza, la risposta al presente messaggio di posta elettronica può essere 
visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by 
persons entitled to receive the confidential information it may contain. E-mail 
messages to clients of Regione Marche may contain information that is 
confidential and legally privileged. Please do not read, copy, forward, or 
store this message unless you are an intended recipient of it. If you have 
rece

Re: [R] R 3.4.4, internet access fails on Windows XP

2018-03-22 Thread Duncan Murdoch

On 22/03/2018 5:28 AM, Holger Taschenberger wrote:

Dear Duncan,

 thank you for your reply.

On Wed, 21 Mar 2018 11:58:15 -0400
Duncan Murdoch  wrote:

  

The Windows FAQ 2.2 says, "Windows XP is no longer supported", so I think you're out of 
luck.  XP went past "end-of-life" in 2014.



on  it says

"R 3.4.4 for Windows
===

This distribution contains a binary distribution of R-3.4.4 to run on
Windows XP and later (including 64-bit versions of Windows) on ix86
and x86_64 chips."


Looks as though that file wasn't updated when the FAQ was.  I am the one 
responsible for that omission, but I can't fix it now, as I retired from 
the core team last year.  The file to fix is src/gnuwin32/CRAN/ReadMe.in.





Other than switching to a more recent Windows version, your choices are 
switching to a completely different OS, or switching to an older version of R.


R i386 runs without problems on Windows XP up to and including version 3.4.2.
Only R i386 3.4.3 & R i386 3.4.4 cannot access the internet on my Windows XP.
I supposed this is not so much a problem with the OS (because "IdnToAscii" 
exists on WindowsXP SP3 as well), but rather with the header files and/or import 
libraries of the MinGW environment

Perhaps it does not take too much effort to restore WindowsXP compatibility. 
The described symptoms are at least easy to debug.

I know that WindowsXP is no longer supported by Microsoft. However, I work in 
an academic environment and we are stuck to Windows XP on some computers 
because some of our data acquisition devices are only properly supported on 
that OS.


In that case, I'd recommend leaving R 3.4.2 on those old machines, and 
doing your main work on different ones.



Regardless of your conclusion, I'm thankful to the R developer team to make the 
R software freely available to the scientific community.



Duncan Murdoch

__
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] exporting data to stata

2018-03-22 Thread Raja, Dr. Edwin Amalraj
Hi ,

library(foreign)
write.dta(data1,  "data1.dta")

should work. The file will be saved in the working directory.
Use
getwd()
to know the working directory.

Best wishes
Amalraj Raja

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of rosario 
scandurra
Sent: 22 March 2018 07:47
To: r-help@r-project.org
Subject: [R] exporting data to stata

Hi,

I am new to R and I want to export data into Stata. Could somebody help with 
that? Thanks a lot.

This is the code I am using:


> setwd("D:/datasets/Seg-bcn/ESBD")
> data1 <- readRDS("r17045_ESDB_Habitatges_BDD_V_1_0.rds")
> library(foreign)
> write.dta(data="data1", file = "D:/datasets/data1.dta")
Error in write.dta(data = "data1", file = "D:/datasets/data1.dta") :
  The object "dataframe" must have class data.frame
> class (data1)
[1] "survey.design2" "survey.design"


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


The University of Aberdeen is a charity registered in Scotland, No SC013683.
Tha Oilthigh Obar Dheathain na charthannas clàraichte ann an Alba, Àir. 
SC013683.
__
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.