[R] using latticeExtra plotting confidence intervals

2010-06-12 Thread Joe P King
I am wanting to plot a 95% confidence band using segplot, yet I am wanting
to have groups. For example if I have males and females, and then I have
them in different races, I want the racial groups in different panels. I
have this minor code, completely made up but gets at what I am wanting, 4
random samples and 4 samples of confidence, I know how to get A & B into one
panel and C&D in to another but how do I get the x axis to label them
properly and have it categorized as two. I am not sure what to have to the
left side of the formula. This is the example code:

 

library(lattice)

library(latticeExtra)

 

sample1<-rnorm(100,10,2)

sample2<-rnorm(100,50,3)

sample3<-rnorm(100,20,2)

sample4<-rnorm(100,40,1)

mu1<-mean(sample1)

ci.upper1<-mu1+2*2

ci.lower1<-mu1-2*2

mu2<-mean(sample2)

ci.upper2<-mu2+2*3

ci.lower2<-mu2-2*3

mu3<-mean(sample3)

ci.upper3<-mu3+2*2

ci.lower3<-mu3-2*2

mu4<-mean(sample4)

ci.upper4<-mu4+2*1

ci.lower4<-mu4-2*1

categories<-c("A","B")

 

mu<-cbind(mu1,mu2,mu3,mu4)

ci.upper<-cbind(ci.upper1,ci.upper2,ci.upper3,ci.upper4)

ci.lower<-cbind(ci.lower1,ci.lower2,ci.lower3,ci.lower4)

segplot(mu~ci.upper+ci.lower|categories, centers = mu, horizontal=FALSE)

 

I also tried this

 

seq1<-seq(1,4,1)

segplot(seq1~ci.upper+ci.lower|categories, centers = mu,horizontal=FALSE)

 

but it also gives poor x axis, I know this is probably an elementary problem
but any help would be greatly appreciated.

 

Heres my data structure, sorry for bombarding with all the code.

 

structure(c(9.85647167881417, 50.1856561919426, 19.8477661576365, 

39.8575819498655, 13.8564716788142, 56.1856561919426, 23.8477661576365, 

41.8575819498655, 5.85647167881417, 44.1856561919426, 15.8477661576365, 

37.8575819498655), .Dim = c(1L, 12L), .Dimnames = list(NULL, 

c("mu1", "mu2", "mu3", "mu4", "ci.upper1", "ci.upper2", "ci.upper3", 

"ci.upper4", "ci.lower1", "ci.lower2", "ci.lower3", "ci.lower4"

)))

---

Joe King, M.A.

Ph.D. Student 

University of Washington - Seattle

Office: 404A

Miller Hall

206-913-2912  

  j...@joepking.com

---

"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] using latticeExtra plotting confidence intervals

2010-06-14 Thread Joe P King
So if the categories was race (A and B) and I had a male and female nested in 
each group, that would give me 4 different data points but I want two data 
points within each panel.

Joe King
206-913-2912
j...@joepking.com
"Never throughout history has a man who lived a life of ease left a name worth 
remembering." --Theodore Roosevelt



-Original Message-
From: Deepayan Sarkar [mailto:deepayan.sar...@gmail.com] 
Sent: Sunday, June 13, 2010 10:15 PM
To: Joe P King
Cc: r-help@r-project.org
Subject: Re: [R] using latticeExtra plotting confidence intervals

On Sun, Jun 13, 2010 at 10:10 AM, Joe P King  wrote:
> I am wanting to plot a 95% confidence band using segplot, yet I am wanting
> to have groups. For example if I have males and females, and then I have
> them in different races, I want the racial groups in different panels. I
> have this minor code, completely made up but gets at what I am wanting, 4
> random samples and 4 samples of confidence, I know how to get A & B into one
> panel and C&D in to another but how do I get the x axis to label them
> properly and have it categorized as two. I am not sure what to have to the
> left side of the formula. This is the example code:

(1) Your code results in

> length(categories)
[1] 2
> length(mu)
[1] 4

which makes the formula mu~ci.upper+ci.lower|categories meaningless.

(2) You are effectively plotting xyplot(mu ~ mu | categories), with
additional confidence intervals in one direction. I'm sure that's not
what you want, but it's not clear what it is that you do actually
want.

-Deepayan



>
>
>
> library(lattice)
>
> library(latticeExtra)
>
>
>
> sample1<-rnorm(100,10,2)
>
> sample2<-rnorm(100,50,3)
>
> sample3<-rnorm(100,20,2)
>
> sample4<-rnorm(100,40,1)
>
> mu1<-mean(sample1)
>
> ci.upper1<-mu1+2*2
>
> ci.lower1<-mu1-2*2
>
> mu2<-mean(sample2)
>
> ci.upper2<-mu2+2*3
>
> ci.lower2<-mu2-2*3
>
> mu3<-mean(sample3)
>
> ci.upper3<-mu3+2*2
>
> ci.lower3<-mu3-2*2
>
> mu4<-mean(sample4)
>
> ci.upper4<-mu4+2*1
>
> ci.lower4<-mu4-2*1
>
> categories<-c("A","B")
>
>
>
> mu<-cbind(mu1,mu2,mu3,mu4)
>
> ci.upper<-cbind(ci.upper1,ci.upper2,ci.upper3,ci.upper4)
>
> ci.lower<-cbind(ci.lower1,ci.lower2,ci.lower3,ci.lower4)
>
> segplot(mu~ci.upper+ci.lower|categories, centers = mu, horizontal=FALSE)
>
>
>
> I also tried this
>
>
>
> seq1<-seq(1,4,1)
>
> segplot(seq1~ci.upper+ci.lower|categories, centers = mu,horizontal=FALSE)
>
>
>
> but it also gives poor x axis, I know this is probably an elementary problem
> but any help would be greatly appreciated.
>
>
>
> Heres my data structure, sorry for bombarding with all the code.
>
>
>
> structure(c(9.85647167881417, 50.1856561919426, 19.8477661576365,
>
> 39.8575819498655, 13.8564716788142, 56.1856561919426, 23.8477661576365,
>
> 41.8575819498655, 5.85647167881417, 44.1856561919426, 15.8477661576365,
>
> 37.8575819498655), .Dim = c(1L, 12L), .Dimnames = list(NULL,
>
>c("mu1", "mu2", "mu3", "mu4", "ci.upper1", "ci.upper2", "ci.upper3",
>
>"ci.upper4", "ci.lower1", "ci.lower2", "ci.lower3", "ci.lower4"
>
>)))
>
> ---
>
> Joe King, M.A.
>
> Ph.D. Student
>
> University of Washington - Seattle
>
> Office: 404A
>
> Miller Hall
>
> 206-913-2912
>
>  <mailto:j...@joepking.com> j...@joepking.com
>
> ---
>
> "Never throughout history has a man who lived a life of ease left a name
> worth remembering." --Theodore Roosevelt
>
>
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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
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] loop troubles

2010-07-17 Thread Joe P King
Hi all, I appreciate the help this list has given me before. I have a
question which has been perplexing me. I have been working on doing a
Bayesian calculating inserting studies sequentially after using a
non-informative prior to get a meta-analysis type result. I created a
function using three iterations of this, my code is below. I insert prior
mean and precision (I add precision manually because I want it to be zero
but if I include zero as prior variance I get an error cant divide by zero.
Now my question is instead of having the three iterations below, is there
anyway to create a loop, the only problem is I want to have elements from
the previous posterior to be the new prior and now I cant figure out how to
do the code below in a loop. The data below is dummy data, I used a starting
mu of 1, and starting precision of 0.

 

bayes.analysis.treat<-function(mu0,p0){

n1 = 5

n2 = 10

n3 = 15

ybar1 = 12

ybar2 = 13

ybar3 = 14

sd1 = 2

sd2 = 3

sd3 = 4

#posterior 1

var1 = sd1^2 #sample variance

p1 = n1/var1 #sample precision

p1n = p0+p1

mu1 = ((p0)/(p1n)*mu0)+((p1)/(p1n))*ybar1

sigma1 = 1/sqrt(p1n)

#posterior 2

var2 = sd2^2 #sample variance

p2 = n2/var2 #sample precision

p2n = p1n+p2

mu2 = ((p1n)/(p2n)*mu1)+((p2)/(p2n))*ybar2

sigma2 = 1/sqrt(p2n)

#posterior 3

var3 = sd3^2 #sample variance

p3 = n3/var3 #sample precision

p3n = p2n+p3

mu3 = ((p2n)/(p3n)*mu2)+((p3)/(p3n))*ybar3

sigma3 = 1/sqrt(p3n)

posterior<-cbind(rbind(mu1,mu2,mu3),rbind(sigma1,sigma2,sigma3))

rownames(posterior)<-c("Posterior 1", "Posterior 2", "Posterior 3")

colnames(posterior)<-c("Mu", "SD")

return(posterior)}

 

---

Joe King, M.A.

Ph.D. Student 

University of Washington - Seattle

206-913-2912  

  j...@joepking.com

---

"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] loop troubles

2010-07-18 Thread Joe P King
I tried that, this is what I tried, but I only get it to do one iteration
and then it wont cycle back. I am not sure how to tell it how to look at the
previous precision to add to the current new sample precision to get the new
precision. This is my first try at a loop so I am not sure if I am doing
anything right, sorry about the elementary question.

n=c(5,10,15)
ybar=c(12,13,14)
sd=c(2,3,4)
mutotals<-matrix(nrow=length(n), ncol=1)
mu=1;p0=0
for (i in 1:length(n)){
  var = sd[i]^2 #sample variance
  p = n[i]/var #sample precision
  p0[i]= i
  pn = p0[i]+p[i]
  mu.out = ((p0[i])/(pn)*mu[i])+((p)/(pn))*ybar[i]
  sigma[i] = 1/sqrt(pn[i])
  mutotals[i,]<-mu.out[i]
}

Joe King
206-913-2912
j...@joepking.com
"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt



-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Sunday, July 18, 2010 5:36 AM
To: Joe P King
Cc: r-help@r-project.org
Subject: Re: [R] loop troubles


On Jul 17, 2010, at 9:09 PM, Joe P King wrote:

> Hi all, I appreciate the help this list has given me before. I have a
> question which has been perplexing me. I have been working on doing a
> Bayesian calculating inserting studies sequentially after using a
> non-informative prior to get a meta-analysis type result. I created a
> function using three iterations of this, my code is below. I insert  
> prior
> mean and precision (I add precision manually because I want it to be  
> zero
> but if I include zero as prior variance I get an error cant divide  
> by zero.
> Now my question is instead of having the three iterations below, is  
> there
> anyway to create a loop, the only problem is I want to have elements  
> from
> the previous posterior to be the new prior and now I cant figure out  
> how to
> do the code below in a loop.

Perhaps if you set the problem up with vectors, it would become more  
obvious how to do it with indexing or loops:

n <-  c(5, 10, 15)
ybar <- c(12,12,14)  # and so on...

-- 
David
> The data below is dummy data, I used a starting
> mu of 1, and starting precision of 0.
>
>
>
> bayes.analysis.treat<-function(mu0,p0){
>
> n1 = 5
>
> n2 = 10
>
> n3 = 15
>
> ybar1 = 12
>
> ybar2 = 13
>
> ybar3 = 14
>
> sd1 = 2
>
> sd2 = 3
>
> sd3 = 4
>
> #posterior 1
>
> var1 = sd1^2 #sample variance
>
> p1 = n1/var1 #sample precision
>
> p1n = p0+p1
>
> mu1 = ((p0)/(p1n)*mu0)+((p1)/(p1n))*ybar1
>
> sigma1 = 1/sqrt(p1n)
>
> #posterior 2
>
> var2 = sd2^2 #sample variance
>
> p2 = n2/var2 #sample precision
>
> p2n = p1n+p2
>
> mu2 = ((p1n)/(p2n)*mu1)+((p2)/(p2n))*ybar2
>
> sigma2 = 1/sqrt(p2n)
>
> #posterior 3
>
> var3 = sd3^2 #sample variance
>
> p3 = n3/var3 #sample precision
>
> p3n = p2n+p3
>
> mu3 = ((p2n)/(p3n)*mu2)+((p3)/(p3n))*ybar3
>
> sigma3 = 1/sqrt(p3n)
>
> posterior<-cbind(rbind(mu1,mu2,mu3),rbind(sigma1,sigma2,sigma3))
>
> rownames(posterior)<-c("Posterior 1", "Posterior 2", "Posterior 3")
>
> colnames(posterior)<-c("Mu", "SD")
>
> return(posterior)}
>
>
>
> ---
>
> Joe King, M.A.
>
> Ph.D. Student
>
> University of Washington - Seattle
>
> 206-913-2912
>
> <mailto:j...@joepking.com> j...@joepking.com
>
> ---
>
> "Never throughout history has a man who lived a life of ease left a  
> name
> worth remembering." --Theodore Roosevelt
>
>
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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, MD
West Hartford, CT

__
R-help@r-project.org mailing list
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] loop troubles

2010-07-18 Thread Joe P King
This is the latest code I have been trying, but it when I try to turn the
vectors of SD into a vector of variances, it turns into a scalar.

n=c(NULL,13,89,50)
ybar=c(NULL,1.58,1.26,0.80)
sd=c(NULL,2.19,4.18,5.47)
mu=1;sigma=1;p0=0;var1=NULL;p=NULL;pn=NULL
for (i in 2:length(n)){
  var1[i] = sd[i]^2 #sample variance
  p[i] = n[i]/var1[i] #sample precision
  p0=p[i-1]
  pn[i] = p0[i]+p[i]
  mu[i] = ((p0[i])/(pn[i])*mu[i])+((p[i])/(pn[i]))*ybar[i]
  sigma[i] = 1/sqrt(pn[i])
  mutotals[i,]<-mu[i]
}

Joe King
206-913-2912
j...@joepking.com
"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt



-Original Message-----
From: Joe P King [mailto:j...@joepking.com] 
Sent: Sunday, July 18, 2010 6:13 AM
To: 'r-help@r-project.org'
Subject: RE: [R] loop troubles

I tried that, this is what I tried, but I only get it to do one iteration
and then it wont cycle back. I am not sure how to tell it how to look at the
previous precision to add to the current new sample precision to get the new
precision. This is my first try at a loop so I am not sure if I am doing
anything right, sorry about the elementary question.

n=c(5,10,15)
ybar=c(12,13,14)
sd=c(2,3,4)
mutotals<-matrix(nrow=length(n), ncol=1)
mu=1;p0=0
for (i in 1:length(n)){
  var = sd[i]^2 #sample variance
  p = n[i]/var #sample precision
  p0[i]= i
  pn = p0[i]+p[i]
  mu.out = ((p0[i])/(pn)*mu[i])+((p)/(pn))*ybar[i]
  sigma[i] = 1/sqrt(pn[i])
  mutotals[i,]<-mu.out[i]
}

Joe King
206-913-2912
j...@joepking.com
"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt



-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Sunday, July 18, 2010 5:36 AM
To: Joe P King
Cc: r-help@r-project.org
Subject: Re: [R] loop troubles


On Jul 17, 2010, at 9:09 PM, Joe P King wrote:

> Hi all, I appreciate the help this list has given me before. I have a
> question which has been perplexing me. I have been working on doing a
> Bayesian calculating inserting studies sequentially after using a
> non-informative prior to get a meta-analysis type result. I created a
> function using three iterations of this, my code is below. I insert  
> prior
> mean and precision (I add precision manually because I want it to be  
> zero
> but if I include zero as prior variance I get an error cant divide  
> by zero.
> Now my question is instead of having the three iterations below, is  
> there
> anyway to create a loop, the only problem is I want to have elements  
> from
> the previous posterior to be the new prior and now I cant figure out  
> how to
> do the code below in a loop.

Perhaps if you set the problem up with vectors, it would become more  
obvious how to do it with indexing or loops:

n <-  c(5, 10, 15)
ybar <- c(12,12,14)  # and so on...

-- 
David
> The data below is dummy data, I used a starting
> mu of 1, and starting precision of 0.
>
>
>
> bayes.analysis.treat<-function(mu0,p0){
>
> n1 = 5
>
> n2 = 10
>
> n3 = 15
>
> ybar1 = 12
>
> ybar2 = 13
>
> ybar3 = 14
>
> sd1 = 2
>
> sd2 = 3
>
> sd3 = 4
>
> #posterior 1
>
> var1 = sd1^2 #sample variance
>
> p1 = n1/var1 #sample precision
>
> p1n = p0+p1
>
> mu1 = ((p0)/(p1n)*mu0)+((p1)/(p1n))*ybar1
>
> sigma1 = 1/sqrt(p1n)
>
> #posterior 2
>
> var2 = sd2^2 #sample variance
>
> p2 = n2/var2 #sample precision
>
> p2n = p1n+p2
>
> mu2 = ((p1n)/(p2n)*mu1)+((p2)/(p2n))*ybar2
>
> sigma2 = 1/sqrt(p2n)
>
> #posterior 3
>
> var3 = sd3^2 #sample variance
>
> p3 = n3/var3 #sample precision
>
> p3n = p2n+p3
>
> mu3 = ((p2n)/(p3n)*mu2)+((p3)/(p3n))*ybar3
>
> sigma3 = 1/sqrt(p3n)
>
> posterior<-cbind(rbind(mu1,mu2,mu3),rbind(sigma1,sigma2,sigma3))
>
> rownames(posterior)<-c("Posterior 1", "Posterior 2", "Posterior 3")
>
> colnames(posterior)<-c("Mu", "SD")
>
> return(posterior)}
>
>
>
> ---
>
> Joe King, M.A.
>
> Ph.D. Student
>
> University of Washington - Seattle
>
> 206-913-2912
>
> <mailto:j...@joepking.com> j...@joepking.com
>
> ---
>
> "Never throughout history has a man who lived a life of ease left a  
> name
> worth remembering." --Theodore Roosevelt
>
>
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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, MD
West Hartford, CT

__
R-help@r-project.org mailing list
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] selected value in a vector to make bold

2010-10-06 Thread Joe P King
I wasn't sure about the subject so I am sorry about the vagueness, but if I
have a vector of values, how do I get a certain type of vectors to be bold
or italics?

 

So let x be a vector from -10 to 10, how would I tell it to bold the x
values that are greater than 0? Or like absolute value of 5? Is it possible
to do this in like an if else statement? Could I use 

 

x<-seq(-10,10,1)

x.bold<-expression(paste(bold(x))) 

 

thanks all!

 

---

Joe King, M.A.

Ph.D. Student 

University of Washington - Seattle

206-913-2912  

  j...@joepking.com

---

"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] selected value in a vector to make bold

2010-10-06 Thread Joe P King
oh sorry for not specifying, I want it returned in the console, another
vector I can call.

Joe King
206-913-2912
j...@joepking.com
"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt


-Original Message-
From: Erik Iverson [mailto:er...@ccbr.umn.edu] 
Sent: Wednesday, October 06, 2010 12:13 PM
To: Joe P King
Cc: r-help@r-project.org
Subject: Re: [R] selected value in a vector to make bold

What output medium? On a graphic? In LaTeX ouput?

Or do you mean in the R console?

Joe P King wrote:
> I wasn't sure about the subject so I am sorry about the vagueness, but 
> if I have a vector of values, how do I get a certain type of vectors 
> to be bold or italics?
> 
>  
> 
> So let x be a vector from -10 to 10, how would I tell it to bold the x 
> values that are greater than 0? Or like absolute value of 5? Is it 
> possible to do this in like an if else statement? Could I use
> 
>  
> 
> x<-seq(-10,10,1)
> 
> x.bold<-expression(paste(bold(x)))
> 
>  
> 
> thanks all!
> 
>  
> 
> ---
> 
> Joe King, M.A.
> 
> Ph.D. Student
> 
> University of Washington - Seattle
> 
> 206-913-2912
> 
>  <mailto:j...@joepking.com> j...@joepking.com
> 
> ---
> 
> "Never throughout history has a man who lived a life of ease left a 
> name worth remembering." --Theodore Roosevelt
> 
>  
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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
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] selected value in a vector to make bold

2010-10-06 Thread Joe P King
I am wondering, if I want the output in bold in the console, to hold in an
object, can I use the expression() command?

Joe King
206-913-2912
j...@joepking.com
"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt



-Original Message-
From: Erik Iverson [mailto:er...@ccbr.umn.edu] 
Sent: Wednesday, October 06, 2010 12:13 PM
To: Joe P King
Cc: r-help@r-project.org
Subject: Re: [R] selected value in a vector to make bold

What output medium? On a graphic? In LaTeX ouput?

Or do you mean in the R console?

Joe P King wrote:
> I wasn't sure about the subject so I am sorry about the vagueness, but 
> if I have a vector of values, how do I get a certain type of vectors 
> to be bold or italics?
> 
>  
> 
> So let x be a vector from -10 to 10, how would I tell it to bold the x 
> values that are greater than 0? Or like absolute value of 5? Is it 
> possible to do this in like an if else statement? Could I use
> 
>  
> 
> x<-seq(-10,10,1)
> 
> x.bold<-expression(paste(bold(x)))
> 
>  
> 
> thanks all!
> 
>  
> 
> ---
> 
> Joe King, M.A.
> 
> Ph.D. Student
> 
> University of Washington - Seattle
> 
> 206-913-2912
> 
>  <mailto:j...@joepking.com> j...@joepking.com
> 
> ---
> 
> "Never throughout history has a man who lived a life of ease left a 
> name worth remembering." --Theodore Roosevelt
> 
>  
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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
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] saving object function

2010-10-07 Thread Joe P King
Ok so if I have a function:

 

functest<-function(x){

a<-x+1

b<-x+2

c<-x+3

paste(a)

paste(b)

paste(c)

}

 

Now I know I can do cat(), or return() on one of them but if I was to run
the function with any number, how could I create objects to save so I could
do, I am wondering if I have more than one object within my function.

 

functest$a and get the result. I hope this is clear.

 

---

Joe King, M.A.

Ph.D. Student 

University of Washington - Seattle

206-913-2912  

  j...@joepking.com

---

"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] saving object function

2010-10-08 Thread Joe P King
Thank you, well I have a table I am wanting to print, yet I want it in a matrix 
but it has different number of columns, so if I had a table of 

1 1 1
2 2

Is there a way to get that table to print out as an object without having to 
put an NA or 0 in the last cell?

Joe King
206-913-2912
j...@joepking.com
"Never throughout history has a man who lived a life of ease left a name worth 
remembering." --Theodore Roosevelt



-Original Message-
From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] 
Sent: Thursday, October 07, 2010 11:43 PM
To: Joe P King
Cc: r-help@r-project.org
Subject: Re: [R] saving object function

Hi Joe,

You can just put the results into a named list, for example:

functest<-function(x){
  a <- x + 1
  b <- x + 2
  c <- x + 3
  results <- list("a" = a, "b" = b, "c" = c)
  return(results)
}

functest(1)$a

It is important to name the list or you would have to refer to it as:
functest(1)[[1]]  for the first element and so on.

HTH,

Josh

On Thu, Oct 7, 2010 at 11:30 PM, Joe P King  wrote:
> Ok so if I have a function:
>
>
>
> functest<-function(x){
>
>a<-x+1
>
>b<-x+2
>
>c<-x+3
>
> paste(a)
>
> paste(b)
>
> paste(c)
>
> }
>
>
>
> Now I know I can do cat(), or return() on one of them but if I was to 
> run the function with any number, how could I create objects to save 
> so I could do, I am wondering if I have more than one object within my 
> function.
>
>
>
> functest$a and get the result. I hope this is clear.
>
>
>
> ---
>
> Joe King, M.A.
>
> Ph.D. Student
>
> University of Washington - Seattle
>
> 206-913-2912
>
>  <mailto:j...@joepking.com> j...@joepking.com
>
> ---
>
> "Never throughout history has a man who lived a life of ease left a 
> name worth remembering." --Theodore Roosevelt
>
>
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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.
>



--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@r-project.org mailing list
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] saving object function

2010-10-08 Thread Joe P King
I did what you said and it worked perfectly, but I have tried to save some of 
my objects using paste because I want to limit the number of significant digits 
and one matrix has some empty spaces I use NA in, and I want those left blank, 
but when I paste into an object it doesn’t hold that formatting, any 
suggestions? How can I have a matrix that isn’t full to have empty spaces? If I 
just tell it " ", it turns the entire matrix into characters.

Joe King
206-913-2912
j...@joepking.com
"Never throughout history has a man who lived a life of ease left a name worth 
remembering." --Theodore Roosevelt



-Original Message-
From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] 
Sent: Thursday, October 07, 2010 11:43 PM
To: Joe P King
Cc: r-help@r-project.org
Subject: Re: [R] saving object function

Hi Joe,

You can just put the results into a named list, for example:

functest<-function(x){
  a <- x + 1
  b <- x + 2
  c <- x + 3
  results <- list("a" = a, "b" = b, "c" = c)
  return(results)
}

functest(1)$a

It is important to name the list or you would have to refer to it as:
functest(1)[[1]]  for the first element and so on.

HTH,

Josh

On Thu, Oct 7, 2010 at 11:30 PM, Joe P King  wrote:
> Ok so if I have a function:
>
>
>
> functest<-function(x){
>
>a<-x+1
>
>b<-x+2
>
>c<-x+3
>
> paste(a)
>
> paste(b)
>
> paste(c)
>
> }
>
>
>
> Now I know I can do cat(), or return() on one of them but if I was to 
> run the function with any number, how could I create objects to save 
> so I could do, I am wondering if I have more than one object within my 
> function.
>
>
>
> functest$a and get the result. I hope this is clear.
>
>
>
> ---
>
> Joe King, M.A.
>
> Ph.D. Student
>
> University of Washington - Seattle
>
> 206-913-2912
>
>  <mailto:j...@joepking.com> j...@joepking.com
>
> ---
>
> "Never throughout history has a man who lived a life of ease left a 
> name worth remembering." --Theodore Roosevelt
>
>
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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.
>



--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@r-project.org mailing list
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] saving object function

2010-10-08 Thread Joe P King
That’s what I was wanting was nice output, I suppose I framed my query wrong, 
but this is what I wanted! Thank you.

Joe King
206-913-2912
j...@joepking.com
"Never throughout history has a man who lived a life of ease left a name worth 
remembering." --Theodore Roosevelt



-Original Message-
From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] 
Sent: Friday, October 08, 2010 7:17 PM
To: Joe P King
Cc: r-help@r-project.org
Subject: Re: [R] saving object function

Hi Joe,

There is an important distinction between working with data and presenting 
data.  You do not want to change or get rid of the missing values in the actual 
data.  Believe it or not, this buys you something important.  Since appearance 
only matters for presentation, you can fudge what the data is, and it is fine 
if it is character data _for printing_.  Here is one possibility where I define 
a custom printing function (uninventively, myprinter() ):

# Some data
dat <- matrix(c(1:8, NA), ncol = 3)

# Define a function that removes row and column names, changes NA values to ""
# and prints the matrix without quotes
myprinter <- function(x) {
  dat <- x
  dimnames(dat) <- list(rep("", nrow(x)), rep("", ncol(x)))
  dat[is.na(dat)] <- ""
  noquote(format(dat, justify="right"))
}

myprinter(dat)

Ultimately your original data is unchanged, but you get some nice output.

HTH,

Josh

On Fri, Oct 8, 2010 at 6:42 PM, Joe P King  wrote:
> I did what you said and it worked perfectly, but I have tried to save some of 
> my objects using paste because I want to limit the number of significant 
> digits and one matrix has some empty spaces I use NA in, and I want those 
> left blank, but when I paste into an object it doesn’t hold that formatting, 
> any suggestions? How can I have a matrix that isn’t full to have empty 
> spaces? If I just tell it " ", it turns the entire matrix into characters.
>
> Joe King
> 206-913-2912
> j...@joepking.com
> "Never throughout history has a man who lived a life of ease left a 
> name worth remembering." --Theodore Roosevelt
>
>
>
> -Original Message-
> From: Joshua Wiley [mailto:jwiley.ps...@gmail.com]
> Sent: Thursday, October 07, 2010 11:43 PM
> To: Joe P King
> Cc: r-help@r-project.org
> Subject: Re: [R] saving object function
>
> Hi Joe,
>
> You can just put the results into a named list, for example:
>
> functest<-function(x){
>  a <- x + 1
>  b <- x + 2
>  c <- x + 3
>  results <- list("a" = a, "b" = b, "c" = c)
>  return(results)
> }
>
> functest(1)$a
>
> It is important to name the list or you would have to refer to it as:
> functest(1)[[1]]  for the first element and so on.
>
> HTH,
>
> Josh
>
> On Thu, Oct 7, 2010 at 11:30 PM, Joe P King  wrote:
>> Ok so if I have a function:
>>
>>
>>
>> functest<-function(x){
>>
>>a<-x+1
>>
>>b<-x+2
>>
>>c<-x+3
>>
>> paste(a)
>>
>> paste(b)
>>
>> paste(c)
>>
>> }
>>
>>
>>
>> Now I know I can do cat(), or return() on one of them but if I was to 
>> run the function with any number, how could I create objects to save 
>> so I could do, I am wondering if I have more than one object within my 
>> function.
>>
>>
>>
>> functest$a and get the result. I hope this is clear.
>>
>>
>>
>> ---
>>
>> Joe King, M.A.
>>
>> Ph.D. Student
>>
>> University of Washington - Seattle
>>
>> 206-913-2912
>>
>>  <mailto:j...@joepking.com> j...@joepking.com
>>
>> ---
>>
>> "Never throughout history has a man who lived a life of ease left a 
>> name worth remembering." --Theodore Roosevelt
>>
>>
>>
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> 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.
>>
>
>
>
> --
> Joshua Wiley
> Ph.D. Student, Health Psychology
> University of California, Los Angeles
> http://www.joshuawiley.com/
>
> __
> R-help@r-project.org mailing list
> 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.
>



--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@r-project.org mailing list
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] multivariate multi regression

2010-12-13 Thread Joe P King
I am not even sure what model you are trying to run, you are talking about
regression slopes for x1 being coef1, and coef2 being the slope for x2,
where are you getting coef3 from, is it in your data?

Joe King
206-913-2912
j...@joepking.com
"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of David Winsemius
Sent: Monday, December 13, 2010 6:06 PM
To: Bastiaan Bergman
Cc: r-help@r-project.org
Subject: Re: [R] multivariate multi regression


On Dec 13, 2010, at 8:46 PM, Bastiaan Bergman wrote:

> Hello,
>
>
> I want to model my data with the following model:
>
>
> Y1=X1*coef1+X2*coef2
> Y2=X1*coef2+X2*coef3
>
>
> Note: coef2 appears in both lines
>
> Xi, Yi is input versus output data respectively
>
> How can I do this in R?
>
> I got this far:
>
> lm(Y1~X1+X2,mydata)
>
> now how do I add the second line of the model including the cross
> dependency?

The usual way would be to extract coef2 from the object returned from  
the first invocation of lm(...)  and use it to calculate an offset  
term in a second model. It would not have any variance calculated  
since you are forcing it to be what was returned in the first model.  
Now, what is it that you are really trying to do with this procedure?

-- 
David.


David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
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
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] VarCorr

2011-01-19 Thread Joe P King
Cant you just save that column of values to an object

stddev<-VC[,2]#if it's the second column that has the values

also I wouldn't save your model name in the same name as the command, when
you have " lmer<-lmer(y~1+(1|sampfac)+(1|labfac))", may be best to have
"lmer.mod<-lmer(y~1+(1|sampfac)+(1|labfac))" or something.

Joe King
206-913-2912
j...@joepking.com
Ad astra per aspera - "Through hardships to the stars"


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Stephanie Cooke
Sent: Wednesday, January 19, 2011 11:33 AM
To: r-help@r-project.org
Subject: [R] VarCorr

I have a loop that I would like to use to extract the "stddev" for each
itteration so I can average the "stddev" for all the runs. It would be
helpful to know how to extract the "stddev" for each run from the VarCorr.
Thanks

MCruns<-1000
sighatlvec<-rep(NA,MCruns)
sighatbvec<-rep(NA,MCruns)
sighatevec<-rep(NA,MCruns)

for(mc in 1:MCruns)
{

samples<-(sqrt(sigbsq)*rnorm(6))
labs<-(sqrt(siglsq)*rnorm(2))
errors<-(sqrt(sigesq)*rnorm(24))
y<-errors+samples[sampfac]+labs[labfac]
lmer<-lmer(y~1+(1|sampfac)+(1|labfac))
print(VC<-VarCorr(lmer))
}

__
R-help@r-project.org mailing list
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
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] splitting a square symmetric matrix

2011-01-20 Thread Joe P King
So many matrices are square symmetrical (i.e. variance-covariance matrices),
is there any way to get R to split the matrix on its diagonal and just
return one diagonal?

 

So if I have

 

mat<-matrix(c(1,4,3,4,1,2,3,2,1), nrow = 3, ncol=3, byrow=TRUE)

 

is there anyway to get the lower right diagonal instead of the entire
symmetric matrix?

 

---

Joe King, M.A.

Ph.D. Student 

University of Washington - Seattle

206-913-2912  

  j...@joepking.com

---

Ad astra per aspera  - "Through hardships to the stars"

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] List of all times zones in R

2011-01-30 Thread Joe P King
Type in letters into command prompt

> letters
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r"
"s"
[20] "t" "u" "v" "w" "x" "y" "z"

Joe King
206-913-2912
j...@joepking.com
Ad astra per aspera – “Through hardships to the stars”


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Maithula Chandrashekhar
Sent: Sunday, January 30, 2011 10:08 PM
To: r-help@r-project.org
Subject: [R] List of all times zones in R

Hi all, in R I have Sys.timezone() function to get the current working
Time zone. However I want to have a vector to get the list of all
available time zones, like say, LETTERS gives me all letters. Is there
any function like that?

Thanks in advance,

__
R-help@r-project.org mailing list
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
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] Rubin's rules of multiple imputation

2011-01-30 Thread Joe P King
Hello all, if I have multiple imputed data sets, is there a command or
function in R in any package you know of to combine those, I know one common
MI approach is rubins rules, is there a way to do this using his rules or
others? I know theres ways, like using Amelia from Gary King's website to
create the imputed data sets, but how to make them into one or combine them
for analysis.

 

---

Joe King, M.A.

Ph.D. Student 

University of Washington - Seattle

206-913-2912  

  j...@joepking.com

---

Ad astra per aspera  - "Through hardships to the stars"

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] confidence intervals when using polr()

2011-03-09 Thread Joe P King
Hello, I am running a model with four categories and want predicted
probabilities in each category. Now for this example I wont give a
counterfactual just the training data is fine but is there anyway to get a
confidence interval around the predicted probabilities in each group? I have
tried but it gives me probabilities and I have used interval="confidence",
level=.095 and then interval = "prediction". Below is a sample of my data
and my code I am trying to run (its from an open access public data set; I
tried to make the size as small as possible, sorry for its length).

 

polr.result<-polr(ordered(tvwatch)~ses+testscores,method="probit",Hess =
T,data=testdata)

polr.predict<-predict(polr.result,type="probs",interval="confidence",level=.
95)

 

structure(list(tvwatch = c(2L, 2L, 1L, 4L, 2L, 4L, 3L, 2L, 3L, 

2L, 3L, 4L, 4L, 3L, 4L, 3L, 2L, 1L, 3L, 1L, 2L, 3L, 4L, 4L, 1L, 

1L, 2L, 2L, 4L, 4L, 2L, 1L, 3L, 3L, 3L, 2L, 4L, 2L, 1L, 1L, 1L, 

1L, 2L, 3L, 4L, 4L, 2L, 1L, 2L, 2L), ses = c(-0.529, -0.377, 

-0.859, -0.191, -0.319, -0.292, -0.601, -0.07, 0.198, 0.096, 

0.136, -0.101, 0.11, -0.182, -0.323, 0.205, 0.21, 0.749, -0.273, 

0.66, 0.009, -0.374, -0.094, -0.427, 1.369, -1.306, 0.611, 0.392, 

-0.371, 1.059, 1.308, -0.89, -1.741, -0.169, 0.13, -0.698, 0.385, 

-0.067, -0.386, 0.813, 0.997, 1.46, 1.196, -0.723, -0.612, 0.119, 

1.421, -1.02, -0.807, 1.33), testscores = c(53.38, 57.91, 54.64, 

45.67, 58.74, 57.55, 63.78, 59.97, 51.41, 49.54, 65.82, 44.04, 

45.8, 56.67, 35.6, 50.41, 45.18, 61.22, 61.24, 66.58, 64.91, 

40.79, 41.77, 46.51, 59.83, 49.95, 58.1, 54.53, 58.31, 69.92, 

66.4, 50.94, 51.23, 47.45, 37.93, 59.66, 60.59, 55.11, 40.65, 

67.89, 52.54, 61.76, 69.71, 44.37, 43.53, 45.89, 75.81, 53.18, 

51.85, 58.03)), .Names = c("tvwatch", "ses", "testscores"), row.names =
c(1L, 

2L, 3L, 4L, 5L, 6L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 18L, 

19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 28L, 29L, 30L, 31L, 32L, 

34L, 35L, 38L, 39L, 40L, 41L, 42L, 44L, 45L, 46L, 47L, 48L, 49L, 

50L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L), class = "data.frame")

 

 

---

Joe King, M.A.

Ph.D. Student 

University of Washington - Seattle

206-913-2912  

  j...@joepking.com

---

Ad astra per aspera  - "Through hardships to the stars"

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] predict ordered regresssion

2011-04-10 Thread Joe P King
Is there a way to get confidence intervals around an ordered regression like
polr() in the MASS package?

 

---

Joe King, M.A.

Ph.D. Student 

University of Washington - Seattle

206-913-2912  

  j...@joepking.com

---

Ad astra per aspera  - "Through hardships to the stars"

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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.