Re: [R] Establishing dates in Time Series Data

2016-09-21 Thread David Winsemius

> On Sep 21, 2016, at 7:20 PM, Jeff Reichman  wrote:
> 
> R-Help Forum
> 
> 
> 
> I'm working with a time series data set whose times periods are days of the
> year.  While it's pretty straight forward of how, for example, to start my
> series on (say) January 2015,but  how do I write the code such that my time
> series starts on (say) the 3rd of Jan 2015?
> 
> 
> 
>> Mytsdata <-  ts(variable, frequency=12, start=c(2015,1))  
> 

Wouldn't this require a frequency that matched the number of days in a year?

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

David Winsemius
Alameda, CA, USA

__
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] Establishing dates in Time Series Data

2016-09-21 Thread Jeff Reichman
R-Help Forum

 

I'm working with a time series data set whose times periods are days of the
year.  While it's pretty straight forward of how, for example, to start my
series on (say) January 2015,but  how do I write the code such that my time
series starts on (say) the 3rd of Jan 2015?

 

> Mytsdata <-  ts(variable, frequency=12, start=c(2015,1))  

 

Jeff


[[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] Problem Mixstock in R

2016-09-21 Thread Nordlund, Dan (DSHS/RDA)
Googling "mixstock CRAN" I found the following:

Package 'mixstock' was removed from the CRAN repository.
Formerly available versions can be obtained from the archive.
Archived on 2014-08-30 as long-term memory-access errors were not corrected.


You might want to contact the maintainer of the package directly with your 
questions.

Dan

Daniel Nordlund, PhD
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services


> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marc
> Girondot via R-help
> Sent: Wednesday, September 21, 2016 12:18 PM
> To: r-help@r-project.org; t.fiorava...@pm.univpm.it
> Subject: Re: [R] Problem Mixstock in R
> 
> Le 19/09/2016 à 10:53, FIORAVANTI TATIANA a écrit :
> > Dear members of the R-project
> >
> > I am doing a mixed stock analysis with the Mixstock Package in R, at
> > the end of the analysis I would summarize all my results (mean,
> > standard deviation, median, percentile, etc...) using the mysum(x,
> > name=NULL) function, but I don't understand which is the correct
> > manner to set up it, what "x" and "name"are? ..Can you help me? Thank
> > you very much,
> >
> > Tatiana
> >
> Dear Tatiana,
> 
> First: I don't find the Mixstock package in CRAN. You should indicate how to
> install it.
> Second: I don't find anywhere a function mysum(). Is it part of the Mixstock
> package?
> Third: Send a reproducible exemple to show what you tried to use the
> function.
> 
> Finaly you should read the posting guide in this list to have more chance to
> have answers.
> 
> Sincerely,
> 
> Marc
> 
> __
> 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] Problem Mixstock in R

2016-09-21 Thread Marc Girondot via R-help

Le 19/09/2016 à 10:53, FIORAVANTI TATIANA a écrit :

Dear members of the R-project

I am doing a mixed stock analysis with the Mixstock Package in R, at the end of the analysis I 
would summarize all my results (mean, standard deviation, median, percentile, etc...) using the 
mysum(x, name=NULL) function, but I don't understand which is the correct manner to set up it, what 
"x" and "name"are? ..Can you help me? Thank you very much,

Tatiana


Dear Tatiana,

First: I don't find the Mixstock package in CRAN. You should indicate 
how to install it.
Second: I don't find anywhere a function mysum(). Is it part of the 
Mixstock package?
Third: Send a reproducible exemple to show what you tried to use the 
function.


Finaly you should read the posting guide in this list to have more 
chance to have answers.


Sincerely,

Marc

__
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] "invalid argument to unary operator" while selecting rows by name

2016-09-21 Thread William Dunlap via R-help
The OP cannot be entirely blamed for thinking that x[,-"ColName"]
would omit x's "ColName" from the result.  Base R and many packages
have commonly used functions that do context-sensitive (aka 'nonstandard')
evaluation.

E.g. subset() evaluates each argument in a different way:
  > subset(data.frame(ColA=1:3,ColB=-(11:13)), -ColB>11, -ColA)
ColB
  2  -12
  3  -13



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Sep 21, 2016 at 7:45 AM, Bert Gunter  wrote:

> No, Rui, your example misses the point. Your initial sentence hits it.
>
> The OP needs to carefully read
> ?"["
> and/or spend some time with a suitable R tutorial to learn proper
> syntax for subscripting. Asking foolish questions in lieu of doing her
> homework seems wrongheaded to me. Others may disagree, of course.
>
> Cheers,
> Bert
>
>
>
>
> 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, Sep 21, 2016 at 1:26 AM,   wrote:
> > Hello,
> >
> > The error message means exactly what it says. The operator '-' is
> > unary and cannot be followed by a non-numeric atomic object (a vector).
> > Try for instance
> >
> > x <- list(a=1:10, b=rnorm(5))
> > -x
> >
> > Rui Barradas
> >
> >
> > Citando Pauline Laïlle :
> >
> >> Works like a charm, thanks! Still don't know what that error message
> >> means though. Any idea?
> >>
> >>   2016-09-20 20:13 GMT+02:00 :
> >>> Sorry, I've made a stupid mistake.
> >>> It's obviously the other way around.
> >>>
> >>> ix <- which(rownames(data) %in% c("601", "604"))
> >>> clean <- data[-ix, ]
> >>>
> >>> Rui Barradas
> >>>
> >>> Citando ruipbarra...@sapo.pt:
>  Hello,
> 
>  Try something like the following.
> 
>  ix <- which(c("601", "604") %in% rownames(data))
>  clean <- data[-ix, ]
> 
>  Hope this helps,
> 
>  Rui Barradas
> 
>  Citando Pauline Laïlle :
> 
> > Dear all,
> >
> > I built a dataframe with read.csv2(). Initially, row names are
> integers
> > (order of answers to a survey). They are listed in the csv's first
> column.
> > The import works well and my dataframe looks like I wanted it to
> look.
> >
> > Row names go as follows :
> > [1] "6"   "29"  "31"  "32"  "52"  "55"  "63"  "71"  "72"  "80"
> "88"  "89"
> > "91"  "93"  "105" "110" "111" "117" "119" "120"
> > [21] "122" "127" "128" "133" "137" "140" "163" "165" "167" "169"
> "177"
> > "178" "179" "184" "186" "192" "193" "200" "201" "228"
> > etc.
> >
> > I would like to drop rows "601" & "604" to clean the dataframe.
> >
> > While data["601",] shows me the first row i'd like to drop,
> data[-"601",]
> > returns the following :
> > Error in -"601" : invalid argument to unary operator
> >
> > idem with data[c("601","604"),] and data[-c("601","604"),]
> >
> > It is the first time that I run into this specific error. After
> reading a
> > bit about it I still don't understand what it means and how to fix
> it.
> >
> > Thanks for reading!
> > Best,
> > Pauline.
> >
> > [[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.
> >>>
> >>>
> >
> >
> >
> > [[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.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see

Re: [R] if/else help

2016-09-21 Thread David Winsemius

> On Sep 21, 2016, at 8:26 AM, MacQueen, Don  wrote:
> 
> Hopefully this is not a homework question.
> 
> The other responses are fine, but I would suggest the simplest way to do
> exactly what you ask is
> 
> 
> if (!exists('r4')) r4 <- data.frame(a=0, b=0, c=0, d='x')
> 
> 
> The exists() function requires a character string for its first argument,
> i.e., the name of the object, not the object itself (check the help page
> for exists).

Since the implicit goal is to determine whether a data.frame by that name is in 
the search path one could add the requirement that the 'list'-mode be added as 
a requirement in the search:

 if ( !exists('r4', mode='list') ){ r4 <- data.frame(a=0, b=0, c=0, d='x')}

That would avoid a 'false'-detection (or at least an unintended detection) for 
a function by that name if one `exist`-ed. It would also mask any `r4` that 
might have been a matrix or other atomic vector outside the local evaluation 
frame.

-- 
David.


> 
> Using "get" to get it doesn't make sense if it already exists.
> 
> -Don
> 
> -- 
> Don MacQueen
> 
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> 
> 
> 
> 
> 
> On 9/20/16, 12:31 PM, "R-help on behalf of Crombie, Burnette N"
>  wrote:
> 
>> If a data.frame (r4) does not exist in my R environment, I would like to
>> create it before I move on to the next step in my script. How do I make
>> that happen?  Here is what I want to do from a code perspective:
>> 
>> if (exists(r4))
>> {
>> is.data.frame(get(r4))
>> }
>> else
>> {
>> a <- 0, b <- 0, c <- 0, d <- "x", r4 <- data.frame(cbind(a,b,c,d))
>> }
>> 
>> Thanks for your help,
>> 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.
> 
> __
> 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.

David Winsemius
Alameda, CA, USA

__
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] FW: Why removing the (Intercept) from lm is done by adding -1?

2016-09-21 Thread S Ellison
> Subject: Re: [R] Why removing the (Intercept) from lm is done by adding -1?
> 
> And in R, - means omit, as in
> mydataframe[, -1]
> right?

Not really, no. 
In the specific interpretation of an R model formula, '-' means 'remove the 
_term_ following '-'  ...'.  As below:
> This is all in the help for formula, where it says "The - operator removes the
> specified terms".

Almost everywhere else, '-'  it means negate as a unary operator and subtract 
as a binary operator. 
In '[', '-' still means negate, not remove. It's just that '[' uses negative 
_numbers_ as a special case to denote omission. As a recent post noted, 
[-"601",] does not work.

> > Adding (or setting the (Intercept) term) zero seems more logical than
> > subtracting one, but why is there the method of subtracting one? Why
> > does subtracting one mean that the (Intercept) term disappears?
See above; '-' _in a formula_ means 'remove the following term'

Following that consistently, if there's a weirdness there, it's that ~0+x works 
to omit the intercept, not that ~x-1 does. 

But that arises from a slightly different, but still fairly reasonable, 
perspective on describing the model.

S Ellison



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

__
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] Help with PCA data file prep and R code

2016-09-21 Thread Sarah Stinson
Hello DRUGs,
I'm new to R and would appreciate some expert advice on prepping files for,
and running, PCA...

My data set consists of aquatic invertebrate and zooplankton count data and
physicochemical measurements from an ecotoxicology study. Four chemical
treatments were applied to mesocosm tanks, 4 replicates per treatment (16
tanks total), then data were collected weekly over a 3 month period.

I cleaned the data in excel by removing columns with all zero values, and
all rows with NA values.
All zooplankton values were volume normalized, then log normalized. All
other data was log normalized in excel prior to analysis in R. All vectorss
are numeric. I've attached the .txt file to this email rather that using
dput(dataframe).

My questions are:

1. Did I do the cleaning step appropriately? I know that there are ways to
run PCA's using data that contain NA values (pcaMethods), but wasn't able
to get the code to work...
(I understand that this isn't strictly an R question, but any help would be
appreciated.)
2. Does my code look correct for the PCA and visualization (see below)?

Thanks in advance,
Sarah

#read data
mesocleaned <- read.csv("MesoCleanedforPCA.9.16.16.csv")

#run PCA
meso.pca <- prcomp(mesocleaned,
   center = TRUE,
   scale. = TRUE)

# print method
print(meso.pca)

#compute standard deviation of each principal component
std_dev <- meso.pca$sdev

#compute variance
pr_var <- std_dev^2

#check variance of first 10 components
pr_var[1:10]

#proportion of variance explained
prop_varex <- pr_var/sum(pr_var)
prop_varex[1:20]

#The first principal component explains 12.7% of the variance
#The second explains 8.1%

#visualize
biplot(meso.pca)

#for visualization, make Treatment vector a factor instead of numeric
meso.treatment <- as.factor(mesocleaned[, 3])

#ggbiplot to visualize by Treatment group
#reference: https://www.r-bloggers.com/computing-and-visualizing-pca-in-r/

library(devtools)
install_github("ggbiplot", "vqv")
library(ggbiplot)

print(ggbiplot(meso.pca, obs.scale = 1, var.scale = 1, groups =
meso.treatment, ellipse = TRUE, circle = TRUE))
g <- ggbiplot(meso.pca, obs.scale = 1, var.scale = 1,
  groups = meso.treatment, ellipse = TRUE,
  circle = TRUE)
g <- g + scale_color_brewer(name = deparse(substitute(Treatments)), palette
= 'Dark2') #must change meso.treatment to a factor for this to work
g <- g + theme(legend.direction = 'horizontal',
   legend.position = 'top')
print(g)

#Circle plot
#plot each variables coefficients inside a unit circle to get insight on a
possible interpretation for PCs.
#reference: https://www.r-bloggers.com/computing-and-visualizing-pca-in-r/

theta <- seq(0,2*pi,length.out = 100)
circle <- data.frame(x = cos(theta), y = sin(theta))
p <- ggplot(circle,aes(x,y)) + geom_path()

loadings <- data.frame(meso.pca$rotation,
   .names = row.names(meso.pca$rotation))
p + geom_text(data=loadings,
  mapping=aes(x = PC1, y = PC2, label = .names, colour =
.names)) +
  coord_fixed(ratio=1) +
  labs(x = "PC1", y = "PC2")

On Tue, Sep 20, 2016 at 10:28 PM, Sarah Stinson 
wrote:

> Hello DRUGs,
> I'm new to R and would appreciate some expert advice on prepping files
> for, and running, PCA...
>
> My data set consists of aquatic invertebrate and zooplankton count data
> and physicochemical measurements from an ecotoxicology study. Four chemical
> treatments were applied to mesocosm tanks, 4 replicates per treatment (16
> tanks total), then data were collected weekly over a 3 month period.
>
> I cleaned the data in excel by removing columns with all zero values, and
> all rows with NA values.
> All zooplankton values were volume normalized, then log normalized. All
> other data was log normalized in excel prior to analysis in R. All vectorss
> are numeric. I've attached the .csv file to this email rather that using
> dput(dataframe). I hope that's acceptable.
>
> My questions are:
>
> 1. Did I do the cleaning step appropriately? I know that there are ways to
> run PCA's using data that contain NA values (pcaMethods), but wasn't able
> to get the code to work...
> (I understand that this isn't strictly an R question, but any help would
> be appreciated.)
> 2. Does my code look correct for the PCA and visualization (see below)?
>
> Thanks in advance,
> Sarah
>
> #read data
> mesocleaned <- read.csv("MesoCleanedforPCA.9.16.16.csv")
>
> #run PCA
> meso.pca <- prcomp(mesocleaned,
>center = TRUE,
>scale. = TRUE)
>
> # print method
> print(meso.pca)
>
> #compute standard deviation of each principal component
> std_dev <- meso.pca$sdev
>
> #compute variance
> pr_var <- std_dev^2
>
> #check variance of first 10 components
> pr_var[1:10]
>
> #proportion of variance explained
> prop_varex <- pr_var/sum(pr_var)
> prop_varex[1:20]
>
> #The first principal component explains 12.7% of the variance
> #The second explains 8.1%
>
> 

Re: [R] if/else help

2016-09-21 Thread MacQueen, Don
Hopefully this is not a homework question.

The other responses are fine, but I would suggest the simplest way to do
exactly what you ask is


if (!exists('r4')) r4 <- data.frame(a=0, b=0, c=0, d='x')


The exists() function requires a character string for its first argument,
i.e., the name of the object, not the object itself (check the help page
for exists).

Using "get" to get it doesn't make sense if it already exists.

-Don

-- 
Don MacQueen

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





On 9/20/16, 12:31 PM, "R-help on behalf of Crombie, Burnette N"
 wrote:

>If a data.frame (r4) does not exist in my R environment, I would like to
>create it before I move on to the next step in my script. How do I make
>that happen?  Here is what I want to do from a code perspective:
>
>if (exists(r4))
>{
>is.data.frame(get(r4))
>}
>else
>{
>a <- 0, b <- 0, c <- 0, d <- "x", r4 <- data.frame(cbind(a,b,c,d))
>}
>
>Thanks for your help,
>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.

__
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] if/else help

2016-09-21 Thread William Dunlap via R-help
If you write your code as functions you can avoid the nasty
'if(exists("x"))x<-...' business this by writing default values for
arguments to your function.   They will be computed only when
they are used.  E.g.,

analyzeData <- function(a=0, b=0, c=0, d="x", r4 = data.frame(a, b, c, d)) {
summary(r4)
}

> analyzeData(c=101:102)
   a   b   c d
 Min.   :0   Min.   :0   Min.   :101.0   x:2
 1st Qu.:0   1st Qu.:0   1st Qu.:101.2
 Median :0   Median :0   Median :101.5
 Mean   :0   Mean   :0   Mean   :101.5
 3rd Qu.:0   3rd Qu.:0   3rd Qu.:101.8
 Max.   :0   Max.   :0   Max.   :102.0
> analyzeData(r4=data.frame(a=10:11,b=20:21,c=30:31,d=c("x","y")))
   a   b   c d
 Min.   :10.00   Min.   :20.00   Min.   :30.00   x:1
 1st Qu.:10.25   1st Qu.:20.25   1st Qu.:30.25   y:1
 Median :10.50   Median :20.50   Median :30.50
 Mean   :10.50   Mean   :20.50   Mean   :30.50
 3rd Qu.:10.75   3rd Qu.:20.75   3rd Qu.:30.75
 Max.   :11.00   Max.   :21.00   Max.   :31.00



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Tue, Sep 20, 2016 at 12:31 PM, Crombie, Burnette N 
wrote:

> If a data.frame (r4) does not exist in my R environment, I would like to
> create it before I move on to the next step in my script. How do I make
> that happen?  Here is what I want to do from a code perspective:
>
> if (exists(r4))
> {
> is.data.frame(get(r4))
> }
> else
> {
> a <- 0, b <- 0, c <- 0, d <- "x", r4 <- data.frame(cbind(a,b,c,d))
> }
>
> Thanks for your help,
> 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.
>

[[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] "invalid argument to unary operator" while selecting rows by name

2016-09-21 Thread Bert Gunter
No, Rui, your example misses the point. Your initial sentence hits it.

The OP needs to carefully read
?"["
and/or spend some time with a suitable R tutorial to learn proper
syntax for subscripting. Asking foolish questions in lieu of doing her
homework seems wrongheaded to me. Others may disagree, of course.

Cheers,
Bert




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, Sep 21, 2016 at 1:26 AM,   wrote:
> Hello,
>
> The error message means exactly what it says. The operator '-' is
> unary and cannot be followed by a non-numeric atomic object (a vector).
> Try for instance
>
> x <- list(a=1:10, b=rnorm(5))
> -x
>
> Rui Barradas
>
>
> Citando Pauline Laïlle :
>
>> Works like a charm, thanks! Still don't know what that error message
>> means though. Any idea?
>>
>>   2016-09-20 20:13 GMT+02:00 :
>>> Sorry, I've made a stupid mistake.
>>> It's obviously the other way around.
>>>
>>> ix <- which(rownames(data) %in% c("601", "604"))
>>> clean <- data[-ix, ]
>>>
>>> Rui Barradas
>>>
>>> Citando ruipbarra...@sapo.pt:
 Hello,

 Try something like the following.

 ix <- which(c("601", "604") %in% rownames(data))
 clean <- data[-ix, ]

 Hope this helps,

 Rui Barradas

 Citando Pauline Laïlle :

> Dear all,
>
> I built a dataframe with read.csv2(). Initially, row names are integers
> (order of answers to a survey). They are listed in the csv's first column.
> The import works well and my dataframe looks like I wanted it to look.
>
> Row names go as follows :
> [1] "6"   "29"  "31"  "32"  "52"  "55"  "63"  "71"  "72"  "80"  "88"  "89"
> "91"  "93"  "105" "110" "111" "117" "119" "120"
> [21] "122" "127" "128" "133" "137" "140" "163" "165" "167" "169" "177"
> "178" "179" "184" "186" "192" "193" "200" "201" "228"
> etc.
>
> I would like to drop rows "601" & "604" to clean the dataframe.
>
> While data["601",] shows me the first row i'd like to drop, data[-"601",]
> returns the following :
> Error in -"601" : invalid argument to unary operator
>
> idem with data[c("601","604"),] and data[-c("601","604"),]
>
> It is the first time that I run into this specific error. After reading a
> bit about it I still don't understand what it means and how to fix it.
>
> Thanks for reading!
> Best,
> Pauline.
>
> [[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.
>>>
>>>
>
>
>
> [[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] Why removing the (Intercept) from lm is done by adding -1?

2016-09-21 Thread Sarah Goslee
Linear regression is of the form

y = mx + b

right?

And in R, - means omit, as in

mydataframe[, -1]

right?

But when you specify a formula within lm(), the intercept is implicit.
That is, you write:

y ~ x

and m and b are fitted.

So if you want to omit the intercept, you use 1 as a placeholder
rather than leaving the - dangling somewhere.

y ~ x - 1

But as you say, there are other ways, so use the one you like.

Note that if you really wanted to subtract 1 from x before fitting the
model, you'd need to make that clear to R:

y ~ I(x - 1)

This is all in the help for formula, where it says "The - operator
removes the specified terms".


Sarah

On Wed, Sep 21, 2016 at 10:19 AM, mviljamaa  wrote:
> So I found out that to remove the (Intercept) term from lm's model one can
> add -1 to the predictors. I.e. do lm(resp ~ x1 + x2 - 1)
>
> Another way is to add 0, e.g. lm(resp ~ 0 + x1 + x2).
>
> Adding (or setting the (Intercept) term) zero seems more logical than
> subtracting one, but why is there the method of subtracting one? Why does
> subtracting one mean that the (Intercept) term disappears?
>
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] Why removing the (Intercept) from lm is done by adding -1?

2016-09-21 Thread mviljamaa
So I found out that to remove the (Intercept) term from lm's model one 
can add -1 to the predictors. I.e. do lm(resp ~ x1 + x2 - 1)


Another way is to add 0, e.g. lm(resp ~ 0 + x1 + x2).

Adding (or setting the (Intercept) term) zero seems more logical than 
subtracting one, but why is there the method of subtracting one? Why 
does subtracting one mean that the (Intercept) term disappears?


__
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] Help with PCA data file prep and R code

2016-09-21 Thread David L Carlson
It was not acceptable. Files with a .csv extension are stripped by the list. If 
you rename it as .txt it should survive. It appears that you have a controlled 
experimental design with explanatory and response variables, so why are you 
using pca which lumps them together? Alternatives might be canonical 
correlations or canonical correspondence analysis that would let you analyze 
the count data in terms of the treatments.

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Sarah Stinson
Sent: Wednesday, September 21, 2016 12:28 AM
To: r-help@r-project.org
Subject: [R] Help with PCA data file prep and R code

Hello DRUGs,
I'm new to R and would appreciate some expert advice on prepping files for,
and running, PCA...

My data set consists of aquatic invertebrate and zooplankton count data and
physicochemical measurements from an ecotoxicology study. Four chemical
treatments were applied to mesocosm tanks, 4 replicates per treatment (16
tanks total), then data were collected weekly over a 3 month period.

I cleaned the data in excel by removing columns with all zero values, and
all rows with NA values.
All zooplankton values were volume normalized, then log normalized. All
other data was log normalized in excel prior to analysis in R. All vectorss
are numeric. I've attached the .csv file to this email rather that using
dput(dataframe). I hope that's acceptable.

My questions are:

1. Did I do the cleaning step appropriately? I know that there are ways to
run PCA's using data that contain NA values (pcaMethods), but wasn't able
to get the code to work...
(I understand that this isn't strictly an R question, but any help would be
appreciated.)
2. Does my code look correct for the PCA and visualization (see below)?

Thanks in advance,
Sarah

#read data
mesocleaned <- read.csv("MesoCleanedforPCA.9.16.16.csv")

#run PCA
meso.pca <- prcomp(mesocleaned,
   center = TRUE,
   scale. = TRUE)

# print method
print(meso.pca)

#compute standard deviation of each principal component
std_dev <- meso.pca$sdev

#compute variance
pr_var <- std_dev^2

#check variance of first 10 components
pr_var[1:10]

#proportion of variance explained
prop_varex <- pr_var/sum(pr_var)
prop_varex[1:20]

#The first principal component explains 12.7% of the variance
#The second explains 8.1%

#visualize
biplot(meso.pca)

#for visualization, make Treatment vector a factor instead of numeric
meso.treatment <- as.factor(mesocleaned[, 3])

#ggbiplot to visualize by Treatment group
#reference: https://www.r-bloggers.com/computing-and-visualizing-pca-in-r/

library(devtools)
install_github("ggbiplot", "vqv")
library(ggbiplot)

print(ggbiplot(meso.pca, obs.scale = 1, var.scale = 1, groups =
meso.treatment, ellipse = TRUE, circle = TRUE))
g <- ggbiplot(meso.pca, obs.scale = 1, var.scale = 1,
  groups = meso.treatment, ellipse = TRUE,
  circle = TRUE)
g <- g + scale_color_brewer(name = deparse(substitute(Treatments)), palette
= 'Dark2') #must change meso.treatment to a factor for this to work
g <- g + theme(legend.direction = 'horizontal',
   legend.position = 'top')
print(g)

#Circle plot
#plot each variables coefficients inside a unit circle to get insight on a
possible interpretation for PCs.
#reference: https://www.r-bloggers.com/computing-and-visualizing-pca-in-r/

theta <- seq(0,2*pi,length.out = 100)
circle <- data.frame(x = cos(theta), y = sin(theta))
p <- ggplot(circle,aes(x,y)) + geom_path()

loadings <- data.frame(meso.pca$rotation,
   .names = row.names(meso.pca$rotation))
p + geom_text(data=loadings,
  mapping=aes(x = PC1, y = PC2, label = .names, colour =
.names)) +
  coord_fixed(ratio=1) +
  labs(x = "PC1", y = "PC2")
__
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] "invalid argument to unary operator" while selecting rows by name

2016-09-21 Thread S Ellison
> > Works like a charm, thanks! Still don't know what that error message
> > means though. Any idea?

You tried to negate a character string.
-"601"

'-' can't do that.

[-x] relies on negative _numbers_ to remove elements, not on separate 
interpretation of '-' and 'x'.



S Ellison


***
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about data problem

2016-09-21 Thread Martin Maechler
> Joe Ceradini 
> on Tue, 20 Sep 2016 17:06:17 -0600 writes:

> read.csv("your_data.csv", stringsAsFactors=FALSE)
> (I'm just reiterating Jianling said...)

If you do not have very many columns, and want to become more
efficient and knowledgeable,
I strongly recommend alternatively to use the 'colClasses' argument
to read.csv or read.table (they are the same apart from defaults
for arguments!) and set "numeric" for numeric columns.

This has a similar effect to the *combination* of
 1)  stringsAsFactors = FALSE
 2)  foo <- as.numeric(foo) # for respective columns

Martin


> Joe

> On Tue, Sep 20, 2016 at 4:56 PM, lily li  wrote:

>> Is there a function in read.csv that I can use to avoid converting 
numeric
>> to factor? Thanks a lot.
>> 
>> 
>> 
>> On Tue, Sep 20, 2016 at 4:42 PM, lily li  wrote:
>> 
>> > Thanks. Then what should I do to solve the problem?
>> >
>> > On Tue, Sep 20, 2016 at 4:30 PM, Jeff Newmiller <
>> jdnew...@dcn.davis.ca.us>
>> > wrote:
>> >
>> >> I suppose you can do what works for your data, but I wouldn't 
recommend
>> >> na.rm=TRUE because it hides problems rather than clarifying them.
>> >>
>> >> If in fact your data includes true NA values (the letters NA or simply
>> >> nothing between the commas are typical ways this information may be
>> >> indicated), then read.csv will NOT change from integer to factor
>> >> (particularly if you have specified which markers represent NA using 
the
>> >> na.strings argument documented under read.table)... so you probably DO
>> have
>> >> unexpected garbage still in your data which could be obscuring 
valuable
>> >> information that could affect your conclusions.
>> >> --
>> >> Sent from my phone. Please excuse my brevity.
>> >>
>> >> On September 20, 2016 3:11:42 PM PDT, lily li 
>> >> wrote:
>> >> >I reread the data, and use 'na.rm = T' when reading the data. This 
time
>> >> >it
>> >> >has no such problem. It seems that the existence of NAs convert the
>> >> >integer
>> >> >to factor. Thanks for your help.
>> >> >
>> >> >
>> >> >On Tue, Sep 20, 2016 at 4:09 PM, Jianling Fan 
>> >> >wrote:
>> >> >
>> >> >> Add the "stringsAsFactors = F"  when you read the data, and then
>> >> >> convert them to numeric.
>> >> >>
>> >> >> On 20 September 2016 at 16:00, lily li  wrote:
>> >> >> > Yes, it is stored as factor. I can't check out any problem in the
>> >> >> original
>> >> >> > data. Reread data doesn't help either. I use read.csv to read in
>> >> >the
>> >> >> data,
>> >> >> > do you think it is better to use read.table? Thanks again.
>> >> >> >
>> >> >> > On Tue, Sep 20, 2016 at 3:55 PM, Greg Snow <538...@gmail.com>
>> >> >wrote:
>> >> >> >
>> >> >> >> This indicates that your Discharge column has been
>> >> >stored/converted as
>> >> >> >> a factor (run str(df) to verify and check other columns).  This
>> >> >> >> usually happens when functions like read.table are left to try 
to
>> >> >> >> figure out what each column is and it finds something in that
>> >> >column
>> >> >> >> that cannot be converted to a number (possibly an oh instead of 
a
>> >> >> >> zero, an el instead of a one, or just a letter or punctuation 
mark
>> >> >> >> accidentally in the file).  You can either find the error in 
your
>> >> >> >> original data, fix it, and reread the data, or specify that the
>> >> >column
>> >> >> >> should be numeric using the colClasses argument to read.table or
>> >> >other
>> >> >> >> function.
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> On Tue, Sep 20, 2016 at 3:46 PM, lily li 
>> >> >wrote:
>> >> >> >> > Hi R users,
>> >> >> >> >
>> >> >> >> > I have a problem in reading data.
>> >> >> >> > For example, part of my dataframe is like this:
>> >> >> >> >
>> >> >> >> > df
>> >> >> >> > month day year  Discharge
>> >> >> >> >31   20106.4
>> >> >> >> >32   2010   7.58
>> >> >> >> >33   2010   6.82
>> >> >> >> >34   2010   8.63
>> >> >> >> >35   2010   8.16
>> >> >> >> >36   2010   7.58
>> >> >> >> >
>> >> >> >> > Then if I type summary(df), why it converts the discharge data
>> >> >to
>> >> >> >> levels? I
>> >> >> >> > also met the same problem when reading some other csv files. 
How
>> >> >to
>> >> >> solve
>> >> >> >> > this problem? Thanks.
>> >> >> >> >
>> >> >> >> > Discharge
>> >> >> >> > 7.58 :2
>> >> >> >> > 6.4   

Re: [R] Query on the R of free soft version 3

2016-09-21 Thread John Kane
What is your operating system?

Please do not post in HTML.

John Kane
Kingston ON Canada


> -Original Message-
> From: kkam-...@echigo.ne.jp
> Sent: Wed, 21 Sep 2016 09:30:15 +0900
> To: r-help@r-project.org
> Subject: [R] Query on the R of free soft version 3
> 
> Dear
> 
> 
> 
> Although I can install the new version of the R, I can not open the soft.
> 
> 
> 
> How do I do it?
> 
> 
> 
> Kyuzi Kamoi, MD.
> 
> 
>   [[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.


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your 
desktop!

__
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] "invalid argument to unary operator" while selecting rows by name

2016-09-21 Thread ruipbarradas
Hello,

The error message means exactly what it says. The operator '-' is  
unary and cannot be followed by a non-numeric atomic object (a vector).
Try for instance

x <- list(a=1:10, b=rnorm(5))
-x

Rui Barradas
 

Citando Pauline Laïlle :

> Works like a charm, thanks! Still don't know what that error message  
> means though. Any idea?
>
>   2016-09-20 20:13 GMT+02:00 :
>> Sorry, I've made a stupid mistake.
>> It's obviously the other way around.
>>
>> ix <- which(rownames(data) %in% c("601", "604"))
>> clean <- data[-ix, ]
>>
>> Rui Barradas
>>
>> Citando ruipbarra...@sapo.pt:   
>>> Hello,
>>>
>>> Try something like the following.
>>>
>>> ix <- which(c("601", "604") %in% rownames(data))
>>> clean <- data[-ix, ]
>>>
>>> Hope this helps,
>>>
>>> Rui Barradas
>>>
>>> Citando Pauline Laïlle :
>>>  
 Dear all,

 I built a dataframe with read.csv2(). Initially, row names are integers
 (order of answers to a survey). They are listed in the csv's first column.
 The import works well and my dataframe looks like I wanted it to look.

 Row names go as follows :
 [1] "6"   "29"  "31"  "32"  "52"  "55"  "63"  "71"  "72"  "80"  "88"  "89"
 "91"  "93"  "105" "110" "111" "117" "119" "120"
 [21] "122" "127" "128" "133" "137" "140" "163" "165" "167" "169" "177"
 "178" "179" "184" "186" "192" "193" "200" "201" "228"
 etc.

 I would like to drop rows "601" & "604" to clean the dataframe.

 While data["601",] shows me the first row i'd like to drop, data[-"601",]
 returns the following :
 Error in -"601" : invalid argument to unary operator

 idem with data[c("601","604"),] and data[-c("601","604"),]

 It is the first time that I run into this specific error. After reading a
 bit about it I still don't understand what it means and how to fix it.

 Thanks for reading!
 Best,
 Pauline.

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

 

[[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] mgcv: bam(), error in models with random intercepts and random slopes

2016-09-21 Thread Simon Wood
Any chance you could send me the data and exact code that produces this 
(I'll only use the data for investigating this issue of course - often 
data with the predictor replaced by noise will produce the same error, 
if sending the raw data is a problem)?

best, Simon (mgcv maintainer)

On 20/09/16 17:22, Fotis Fotiadis wrote:

Hi all

I am using the bam function of the mgcv package to model behavioral data of
a learning experiment. To model individual variation in learning rate, I am
testing models with (a) by-participant random intercepts of trial, (b)
by-participant random slopes and random intercepts of trial, and (c)
by-participant random smooth terms.

While all (a) and (c) models converge, I am getting an error for every
possible variation of a model with random intercepts and random slopes. For
example:

m1.rs<-bam(acc~ 1 + igc + s(ctrial) + s(sbj, bs="re") + s(ctrial, sbj,
bs="re") , data=data_a, family=binomial)
Error in G$smooth[[i]]$first.para:G$smooth[[i]]$last.para :
   argument of length 0

Any idea on what that error might be?

Thank you in advance for your time.
Fotis

P.S.: R version: 3.3.1, mgcv version: 1.8.15




--
Simon Wood, School of Mathematics, University of Bristol BS8 1TW UK
+44 (0)117 33 18273 http://www.maths.bris.ac.uk/~sw15190

__
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] Query on the R of free soft version 3

2016-09-21 Thread PIKAL Petr
Hi

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Kamin
> Kyuji
> Sent: Wednesday, September 21, 2016 2:30 AM
> To: R-help@r-project.org
> Subject: [R] Query on the R of free soft version 3
>
> Dear
>
>
>
> Although I can install the new version of the R, I can not open the soft.
>
>
>
> How do I do it?

Did you try to doubleclick on R icon?

Your short question imply either our mind reading capability or our presence in 
your office. The later is not the case however some clever helpers are better 
in first option than other, so you maybe get better hints.

Cheers
Petr

>
>
>
> Kyuzi Kamoi, MD.
>
>
>   [[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] Query on the R of free soft version 3

2016-09-21 Thread David Winsemius

> On Sep 20, 2016, at 5:30 PM, Kamin Kyuji  wrote:
> 
> Dear
> 
> 
> 
> Although I can install the new version of the R, I can not open the soft.
> 
> 
> 
> How do I do it?

Surely you will need to tell us more than that. This just tells us you are 
having problems but nothing else.


> 
> 
> 
> Kyuzi Kamoi, MD.
> 
> 
>   [[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.

David Winsemius
Alameda, CA, USA

__
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] if/else help

2016-09-21 Thread David Winsemius

> On Sep 20, 2016, at 12:31 PM, Crombie, Burnette N  wrote:
> 
> If a data.frame (r4) does not exist in my R environment, I would like to 
> create it before I move on to the next step in my script. How do I make that 
> happen?  Here is what I want to do from a code perspective:
> 
> if (exists(r4))
> {
> is.data.frame(get(r4))
> }
> else
> {
> a <- 0, b <- 0, c <- 0, d <- "x", r4 <- data.frame(cbind(a,b,c,d))
> }
> 
> Thanks for your help,
> B
> 
>   [[alternative HTML version deleted]]

Please, please, please, do not encourage people to use the construction:

data.frame(cbind(

...and learn to distrust whatever misguided example you learned it from. (Yes, 
I know there is one in the help pages but that is an exception to the rule.)

There is no reason to use it. It would be much clearer to do this:

r4 <- data.frame(a = 0, b = 0, c = 0, d = "x")# only one column is 
factor-class.

If you did it your way you would have gotten four columns of factors, (first 
cbind() creates a character matrix, and then data.frame() creates factors)  ... 
which does not appear to be what you expected.

And ... as always has been the case on Rhelp, ... learn to post in plain text.

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

David Winsemius
Alameda, CA, USA

__
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] if/else help

2016-09-21 Thread Jeff Newmiller
Get rid of the commas? Get rid of the get() function call? Get rid of the 
cbind() function call?  Post using plain text format so the HTML doesn't screw 
up code? Read the Posting Guide? All of these ideas have merit IMHO...
-- 
Sent from my phone. Please excuse my brevity.

On September 20, 2016 12:31:47 PM PDT, "Crombie, Burnette N"  
wrote:
>If a data.frame (r4) does not exist in my R environment, I would like
>to create it before I move on to the next step in my script. How do I
>make that happen?  Here is what I want to do from a code perspective:
>
>if (exists(r4))
>{
>is.data.frame(get(r4))
>}
>else
>{
>a <- 0, b <- 0, c <- 0, d <- "x", r4 <- data.frame(cbind(a,b,c,d))
>}
>
>Thanks for your help,
>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.

__
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] Issue on LGP solving

2016-09-21 Thread PIKAL Petr
Hi

> -Original Message-
> From: Dr. Debasis Ghosh [mailto:d...@debasis.in]
> Sent: Tuesday, September 20, 2016 3:59 PM
> To: PIKAL Petr ; R-help@r-project.org
> Subject: RE: [R] Issue on LGP solving
>
> Thanks Petr!! However, I found in the goalprog package I found
> "achievements" as "a  data frame with the deviation variables for each
> objective together with the priority level". I defined
>
> > p1<-c(2,0,0,0,0,0)
> > p2 <- c(0,0,0,0,1,0)
> > p3<- c(0,0,0,0,0,1)
> > achievement <- data.frame(p1,p2,p3)
>
> Here p1, p2 and p3 are the 3 priority levels.
>
> I understand the problem is at "achievement" data frame. To your point,
> data frame with four named columns (objective, priority, p and n), how
> these four columns are defined ?

I have no idea as I never used this package. It was just my guess from 
difference between your call and manual pages I found on internet.
If I were you I would go through help pages for the package and tried to 
understand what is going on.
If I did not understand it I would try to find some extended tutorial about 
this method.
If I did not find anything I would either gave up or seek some help from local 
statistical expert or contacted maintainer of this package.

Cheers
Petr

>
> Appreciate your time Petr. Thanks again!!
>
> Regards,
> Debasis Ghosh, Ph.D
>
> -Original Message-
> From: PIKAL Petr [mailto:petr.pi...@precheza.cz]
> Sent: Tuesday, September 20, 2016 6:55 AM
> To: Dr. Debasis Ghosh; R-help@r-project.org
> Subject: RE: [R] Issue on LGP solving
>
> Hi
>
> Just a wild guess. Achievement in the goalprog package is data frame with
> four named columns (objective, priority, p and n).
>
> Your achievement is 3 column data.frame with names p1, p2 and p3.
>
> Maybe data frame with defined structure is required.
>
> Cheers
> Petr
>
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dr.
> > Debasis Ghosh
> > Sent: Tuesday, September 20, 2016 8:12 AM
> > To: R-help@r-project.org
> > Subject: [R] Issue on LGP solving
> >
> > I was solving a LGP problem which is very basic.
> >
> >
> >
> > Find x0 = [x1; x2], n0 = [n1; n2; n3] and p0 = [p1; p2; p3] that
> > minimize a = [(2p1); (n2); (n3)]
> >
> > The objectives are as follows
> >
> > 10x1 + 15x2 + n1 - p1 = 40
> >
> > 100x1 + 100x2 + n2 - p2 = 1000
> >
> > x2 + n3 - p3 = 7
> >
> > x; n; p >= 0
> >
> > The solution is x' = [4; 0] and a = [0; 600; 7]
> >
> >
> >
> >
> >
> > > local({pkg <- select.list(sort(.packages(all.available =
> > TRUE)),graphics=TRUE)
> >
> > + if(nchar(pkg)) library(pkg, character.only=TRUE)})
> >
> > > local({pkg <- select.list(sort(.packages(all.available =
> > TRUE)),graphics=TRUE)
> >
> > + if(nchar(pkg)) library(pkg, character.only=TRUE)})
> >
> >
> >
> >
> >
> > > coeff<-matrix (c(10,15,100,100,0,1), nrow=3, ncol=2, byrow=TRUE)
> >
> > > target<-c(40,1000,7)
> >
> > > p1<-c(2,0,0,0,0,0)
> >
> > > p2 <- c(0,0,0,0,1,0)
> >
> > > p3<- c(0,0,0,0,0,1)
> >
> > > achievement <- data.frame(p1,p2,p3)
> >
> > > achievement
> >
> >   p1 p2 p3
> >
> > 1  2  0  0
> >
> > 2  0  0  0
> >
> > 3  0  0  0
> >
> > 4  0  0  0
> >
> > 5  0  1  0
> >
> > 6  0  0  1
> >
> > > llgp(coeff,target,achievement)
> >
> >
> >
> > Do you have any idea why I am seeing below error ?
> >
> >
> >
> >
> >
> > Error in matrix(0, nrow = levels, ncol = nonbasics) :
> >
> >   invalid 'nrow' value (too large or NA)
> >
> > In addition: Warning messages:
> >
> > 1: In max(achievements$priority) :
> >
> >   no non-missing arguments to max; returning -Inf
> >
> > 2: In matrix(0, nrow = levels, ncol = nonbasics) :
> >
> >   NAs introduced by coercion to integer range
> >
> >
> >
> > Regards,
> >
> > Debasis Ghosh, Ph.D
> >
> >
> >
> >
> >   [[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 

Re: [R] Run a fixed effect regression and a logit regression on a national survey that need to be "weighted"

2016-09-21 Thread laura roncaglia
Thank you for the answer but I had already tried that way; when I introduce
weights in the glm appears the error:

Warning: non-integer #successes in a binomial glm!

I tried to run the glm regression using the family quasibinomial:

eq <- glm(pip ~ men + age_pr + age_c + I(age_pr^2) + I(age_c^2),
weights = dfweights, data = df, family = quasibinomial(link =
"logit"))

Do you think it could be a right solution?

2016-09-20 18:23 GMT+02:00 Adams, Jean :

> If you want your records to be weighted by the survey weights during the
> analysis, then use the weights= argument of the glm() function.
>
> Jean
>
> On Tue, Sep 20, 2016 at 5:04 AM, laura roncaglia <
> roncaglia.la...@gmail.com> wrote:
>
>> I am a beginner user of R. I am using a national survey to test what
>> variables influence the partecipation in complementary pensions (the
>> partecipation in complementary pension is voluntary in my country).
>>
>> Since the dependent variable is a dummy (1 if the person partecipate and 0
>> otherwise) I want to run a logit or probit regression; moreover I want to
>> run a fixed effect regression since I subset the survey in order to have
>> only the individuals interviewed more than one time.
>>
>> The data frame is composed by several social and economical variables and
>> it also contain a variable "weight" which is the survey weight (they are
>> weighting coefficients to adjust the results of the sample to the national
>> data).
>>
>>  family pers sex income pension1 101   F  1   12
>> 201   F  2   13 202   M  4   04 30
>> 1   M  25000   05 302   F  5   06 401   M
>> 6   1
>>
>> pers is the component of the family and pension takes 1 if the person
>> partecipate to complementary pension (it is a semplification of the
>> original survey, which contains more variables and observation (aroun 22k
>> observations)).
>>
>> I know how to use the plm and glm functions for a fixed effect or logit
>> regressoin; in this case I don't know what to do since I need to take
>> account of the survey weights.
>>
>> I used the svydesing function to "weight" the data frame:
>>
>> df1 <- svydesign(ids=~1, data=df, weights=~dfweight)
>>
>> I used ids=~1 because there isn't a "cluster" variable in the survey (I
>> know that the towns are ramdomly selected and then individuals are
>> ramdomly
>> selected, but there isn't a variable that indicate the stratification).
>>
>> At this point I am lost: I don't know if it is right to use the survey
>> package and then what function use to run the regression, or there is a
>> way
>> to use the plm or glm functions taking account of the weights.
>>
>> I tried so hard to search a solution on the website but if you could give
>> me an answer I'd be glad.
>>
>> [[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] Query on the R of free soft version 3

2016-09-21 Thread Kamin Kyuji
Dear

 

Although I can install the new version of the R, I can not open the soft.

 

How do I do it?

 

Kyuzi Kamoi, MD.


[[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] if/else help

2016-09-21 Thread Crombie, Burnette N
If a data.frame (r4) does not exist in my R environment, I would like to create 
it before I move on to the next step in my script. How do I make that happen?  
Here is what I want to do from a code perspective:

if (exists(r4))
{
is.data.frame(get(r4))
}
else
{
a <- 0, b <- 0, c <- 0, d <- "x", r4 <- data.frame(cbind(a,b,c,d))
}

Thanks for your help,
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.


[R] Help with PCA data file prep and R code

2016-09-21 Thread Sarah Stinson
Hello DRUGs,
I'm new to R and would appreciate some expert advice on prepping files for,
and running, PCA...

My data set consists of aquatic invertebrate and zooplankton count data and
physicochemical measurements from an ecotoxicology study. Four chemical
treatments were applied to mesocosm tanks, 4 replicates per treatment (16
tanks total), then data were collected weekly over a 3 month period.

I cleaned the data in excel by removing columns with all zero values, and
all rows with NA values.
All zooplankton values were volume normalized, then log normalized. All
other data was log normalized in excel prior to analysis in R. All vectorss
are numeric. I've attached the .csv file to this email rather that using
dput(dataframe). I hope that's acceptable.

My questions are:

1. Did I do the cleaning step appropriately? I know that there are ways to
run PCA's using data that contain NA values (pcaMethods), but wasn't able
to get the code to work...
(I understand that this isn't strictly an R question, but any help would be
appreciated.)
2. Does my code look correct for the PCA and visualization (see below)?

Thanks in advance,
Sarah

#read data
mesocleaned <- read.csv("MesoCleanedforPCA.9.16.16.csv")

#run PCA
meso.pca <- prcomp(mesocleaned,
   center = TRUE,
   scale. = TRUE)

# print method
print(meso.pca)

#compute standard deviation of each principal component
std_dev <- meso.pca$sdev

#compute variance
pr_var <- std_dev^2

#check variance of first 10 components
pr_var[1:10]

#proportion of variance explained
prop_varex <- pr_var/sum(pr_var)
prop_varex[1:20]

#The first principal component explains 12.7% of the variance
#The second explains 8.1%

#visualize
biplot(meso.pca)

#for visualization, make Treatment vector a factor instead of numeric
meso.treatment <- as.factor(mesocleaned[, 3])

#ggbiplot to visualize by Treatment group
#reference: https://www.r-bloggers.com/computing-and-visualizing-pca-in-r/

library(devtools)
install_github("ggbiplot", "vqv")
library(ggbiplot)

print(ggbiplot(meso.pca, obs.scale = 1, var.scale = 1, groups =
meso.treatment, ellipse = TRUE, circle = TRUE))
g <- ggbiplot(meso.pca, obs.scale = 1, var.scale = 1,
  groups = meso.treatment, ellipse = TRUE,
  circle = TRUE)
g <- g + scale_color_brewer(name = deparse(substitute(Treatments)), palette
= 'Dark2') #must change meso.treatment to a factor for this to work
g <- g + theme(legend.direction = 'horizontal',
   legend.position = 'top')
print(g)

#Circle plot
#plot each variables coefficients inside a unit circle to get insight on a
possible interpretation for PCs.
#reference: https://www.r-bloggers.com/computing-and-visualizing-pca-in-r/

theta <- seq(0,2*pi,length.out = 100)
circle <- data.frame(x = cos(theta), y = sin(theta))
p <- ggplot(circle,aes(x,y)) + geom_path()

loadings <- data.frame(meso.pca$rotation,
   .names = row.names(meso.pca$rotation))
p + geom_text(data=loadings,
  mapping=aes(x = PC1, y = PC2, label = .names, colour =
.names)) +
  coord_fixed(ratio=1) +
  labs(x = "PC1", y = "PC2")
__
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.