Rui Barradas | 1 Aug 2012 01:54
Picon
Favicon

Re: Alternating between "for loops"

Hello,

You're right, and there's a way without loops. Summarizing:

J <- 10
N <- 10

cols <- rep(c(TRUE, TRUE, FALSE, FALSE), ceiling(J / 4))[seq_len(J)]

#--- 1st way: nested loops
y <- matrix(0, N, J)
for(j in which(cols)){
     for (q in 1:N)
         y[q, j] <- if(j %% 2) 1 else 2
}
for(j in which(!cols)){
     for (q in 1:N)
         y[q, j] <- if(j %% 2) "A" else "B"
}

#--- 2nd way: one loop only
z <- matrix(0, N, J)
for(j in which(cols))
     z[, j] <- if(j %% 2) 1 else 2
for(j in which(!cols))
     z[, j] <- if(j %% 2) "A" else "B"

#--- 3rd way: no loops
w <- matrix(0, J, N)  # reversed order
w[cols, ] <- ifelse(which(cols) %% 2, 1, 2)
(Continue reading)

Ario Ario | 1 Aug 2012 02:27
Picon

Re: cannot install RSTAR, MSVAR, and MSVECM packages

---------- message ----------
From: peter dalgaard <pdalgd <at> gmail.com>
Date: Tue, Jul 31, 2012 at 6:40 PM
Subject: Re: [R] cannot install RSTAR, MSVAR, and MSVECM packages
To: Ario Ario <garionet <at> gmail.com>
Cc: Uwe Ligges <ligges <at> statistik.tu-dortmund.de>

Check out the CRAN Task Views for Finance and Time Series, and the
R-SIG-Finance mailing list.

-pd

On Jul 31, 2012, at 11:17 , Ario Ario wrote:

> Hi,
> I need to do non-linear time series analysis. The models used are the
family of Threshold Auto Regressive models (TAR, SETAR, and LTAR), Smooth
Transition Auto Regressive models (STAR, LSTAR, and ESTAR), and Markov
Switching models (MS-AR, MS-VAR, and MS-VECM).
>
> For Threshold Auto Regressive models, I can use TsDyn package. But for
the rest, I cannot find any suitable packages except the one that I
couldn't install. In short, I need R-package to estimate Smooth Transition
Auto Regressive models and Markov Switching models.
>
> Regards,
> Ario
>
>
> On Tue, Jul 31, 2012 at 3:28 PM, peter dalgaard <pdalgd <at> gmail.com> wrote:
(Continue reading)

Michael Friendly | 1 Aug 2012 03:19
Picon
Favicon
Gravatar

Re: Mediation analysis

Subset your data first and/or use the data= and subset= arguments to 
lm() so the same data is used in all models.

On 7/31/2012 2:14 PM, jawortman wrote:
> Hello all,
>
> I apologize for the simplistic question, but I have been having some trouble
> learning how to do mediation analysis in R. Ideally, I would like to use
> Preacher's Bootstrapping test for mediation (Preacher & Hayes, 2004). I have
> attempted to use the mediate package to set this up, using code that looks
> basically like this:
>
> model.m <- lm(data$outcome ~ data$mediator + desirdata$predictor)
> model.y <- lm(data$outcome ~ data$predictor)
> age1 <- mediate(model.m, model.y, treat = "predictor", mediator =
> "mediator", conf.level=.95, boot=TRUE, sims=50)
>
>   However, I get an error indicating that the number of observations doesn't
> match across the two models. This may be true,  because it's a somewhat
> large sample (13,000) with a pretty substantial amount of missing data, but
> I'm not sure how to deal with that issue. Is there any way to get this to
> run given that there may be different numbers of observations in the two
> models?
>
> Thanks,
>
> Jessica
>
>
>
(Continue reading)

Xu Jun | 1 Aug 2012 02:57
Picon

optim() for ordered logit model with parallel regression assumption

Dear R listers,

I am learning the MLE utility optim() in R to program ordered logit
models just as an exercise. See below I have three independent
variables, x1, x2, and x3. Y is coded as ordinal from 1 to 4. Y is not
yet a factor variable here. The ordered logit model satisfies the
parallel regression assumption. The following codes can run through,
but results were totally different from what I got using the polr
function from the MASS package. I think it might be due to the way how
the p is constructed in the ologit.lf function. I am relatively new to
R, and here I would guess probably something related to the class type
(numeric vs. matrix) or something along that line among those if
conditions. Thanks in advance for any suggestion.

Jun Xu, PhD
Assistant Professor
Department of Sociology
Ball State University
Muncie, IN 47306

####################################################################

library(foreign)
readin <- read.dta("ordfile.dta", convert.factors=FALSE)
myvars <- c("depvar", "x1", "x2", "x3")
mydta <- readin[myvars]
# remove all missings
mydta <- na.omit(mydta)

# theta is the parameter vector
(Continue reading)

arun | 1 Aug 2012 01:32
Picon
Favicon

Re: help with a regression


HI,

Not sure how your dataset looks like.

Is it something like
this?

dat1<-data.frame(ID=rep(1:2,each=5),X1=rnorm(10,10),X2=rnorm(10,3),X3=runif(10,0.4),X4=runif(10,0.8),X5=c(10,7,8,10,15,9,6,5,4,2), Y1=rnorm(10,25),Y2=rnorm(10,18),Y3=rnorm(10,35),
Y4=rnorm(10,45),Y5=rnorm(10,46))
I assume the IDs are subjects.  Then, for each subject, you want to calculate lm(Y(i)~X1+X2+X3+X4+X5),
where i= 1 to 5.

Anyway, it would be better to post 10-15 lines of your dataset using dput.  Please post the output of :
dput(head(data, 15)).

A.K.

----- Original Message -----
From: "R Heberto Ghezzo, Dr" <heberto.ghezzo <at> mcgill.ca>
To: "r-help <at> r-project.org" <r-help <at> r-project.org>
Cc: 
Sent: Tuesday, July 31, 2012 4:33 PM
Subject: [R] help with a regression

Hello, I have a data frame with the following variables:
ID, X1,X2,X3,X4,X5,Y1,Y2,Y3,Y4,Y5 and some other that do not matter, some of the X and Y can be missing
(NA). I want to compute the slope of the linear regression Y ~ X for each subject, so using
apply(DF,1,FUN,ra.rm=TRUE) now How do I define FUN? The X are different for each subject.
Thanks for any help
(Continue reading)

R. Michael Weylandt | 1 Aug 2012 04:07
Picon

Re: optim() for ordered logit model with parallel regression assumption

On Tue, Jul 31, 2012 at 7:57 PM, Xu Jun <junxu.r <at> gmail.com> wrote:
> Dear R listers,
>
> I am learning the MLE utility optim() in R to program ordered logit
> models just as an exercise. See below I have three independent
> variables, x1, x2, and x3. Y is coded as ordinal from 1 to 4. Y is not
> yet a factor variable here. The ordered logit model satisfies the
> parallel regression assumption. The following codes can run through,
> but results were totally different from what I got using the polr
> function from the MASS package. I think it might be due to the way how
> the p is constructed in the ologit.lf function. I am relatively new to
> R, and here I would guess probably something related to the class type
> (numeric vs. matrix) or something along that line among those if
> conditions. Thanks in advance for any suggestion.
>
> Jun Xu, PhD
> Assistant Professor
> Department of Sociology
> Ball State University
> Muncie, IN 47306
>
>
> ####################################################################
>
> library(foreign)
> readin <- read.dta("ordfile.dta", convert.factors=FALSE)
> myvars <- c("depvar", "x1", "x2", "x3")
> mydta <- readin[myvars]
> # remove all missings
> mydta <- na.omit(mydta)
(Continue reading)

Grace Hensen | 1 Aug 2012 04:05
Picon

bivariate localpcf in Spatstat

Hi,
I would like to know if there is a way to carry out a bivariate (e.g.,
between individuals of two tree species) local pair correlation function in
Spatstat. There is currently a function  "localpcf" for univariate data but
I have not found one for bivariate data and was wondering if there is way
to do it either in Spatstat or other R-packages. Thanks for your
suggestions.

Regards,
Grace Hensen

	[[alternative HTML version deleted]]

Dushanthi Pinnaduwage | 1 Aug 2012 04:41

Re: "metafor" package, proportions: single groups wrt to a categorical dependent variable


Thanks for the reply.
Goal of my meta analysis is to compare 2 different surgical procedures to fix the same problem.

Data (after systematic search) are collected from studies with one or the other procedure applied.

There are a couple of outcome variables that measure the effetivenss of the procedures; The same outcome
data was extacted from each study. 
All outcome variables are categorical with number of levels 4 or 5.  Levels can be combined to make
meaningful 2 levels (making binary variables), but prefer not to do this.

My analysis plan (say for outcome variable 1):

1. Do a metanalysis for all the studies with procedure 1 (say), combining proportions for outcome 1
(estimating the proportions). 
2.  Do a metanalysis for all the studies with procedure 2 (say), combining proportions for outcome 1
(estimating the proportions). 
3. Finally just discuss the proportion diffenences between the 2 procedures (descriptive) or test the for
the proportion difference between the 2 procedures. Hope this will give some insight into the
problem.Thank you.Dushanthi

 
> Date: Tue, 31 Jul 2012 17:42:12 +0100
> To: dushanthi <at> bell.net; info <at> aghmed.fsnet.co.uk; r-help <at> r-project.org
> From: info <at> aghmed.fsnet.co.uk
> Subject: RE: [R] "metafor" package, proportions: single groups wrt to a  categorical dependent variable
> 
> At 01:18 31/07/2012, Dushanthi Pinnaduwage wrote:
> 
> >Thanks very much for the reply Michael.
(Continue reading)

Gene Leynes | 1 Aug 2012 06:40
Picon

Re: Zoo panel function

Achim,

Thank you for your response, and for your work on the zoo package in
general.  Also, that implementation of the color scheme looks great.

Frankly, I can't remember exactly what I was originally trying to
accomplish for this particular problem, but I think that your suggestion of
reviewing the plotting section of the zoo vignette would solve the problem.
 Calculating the colors ahead of time and passing them in as a list is
great solution that I didn't know was possible.

I still have some lingering questions about the panel function, which has
been one of those things in R that I would like to understand better.

Using your example, I would like to be able to pass in an additional
variable to make each set of hues like this:

mycol <- function(i, v)  hcl(
  h = ifelse(i > 0, v, 0),
  c = 80 * abs(i)^1.5,
  l = 90 - 60 * abs(i)^1.5)

mypanel <- function(x, y, v, ...) {
  lines(x, y, col = "gray")
  points(x, y, col = mycol(y / max(abs(y)), v), pch = 19)
}
plot(zobj, panel = mypanel, v=0)
plot(zobj, panel = mypanel, v=50)
plot(zobj, panel = mypanel, v=100)
plot(zobj, panel = mypanel, v=150)
(Continue reading)

Favicon

Why the result is coming as NULL?

Why the result is coming as NULL. Can anyone help. I want to find the outliers for a reference

setwd("D:/AZ")

library("RODBC")
cdb_cnct <- odbcConnectExcel("Book1.xls")
cdb_frame <- sqlFetch(cdb_cnct, "Sheet1")
odbcClose(cdb_cnct)
rm(cdb_cnct)

x<- cdb_frame$Publication >=1990 & cdb_frame$Publication <=2012
invalid <- cdb_frame[!x, c("Reference")]
invalid

________________________________
Notice: The information contained in this electronic mail message is intended only for the use of the
designated recipient. This message is privileged and confidential. and the property of GVK BIO or its
affiliates and subsidiaries. If the reader of this message is not the intended recipient or an agent
responsible for delivering it to the intended recipient, you are hereby notified that you have received
this message in error and that any review, dissemination, distribution, or copying of this message is
strictly prohibited. If you have received this communication in error, please notify us immediately by
telephone +91-40-66929999<tel:%2B91-40-66929999> and destroy any and all copies of this message in
your possession (whether hard copies or electronically stored copies).
Why the result is coming as NULL. Can anyone help. I want to find the outliers for a reference

setwd("D:/AZ")

library("RODBC")
(Continue reading)


Gmane