Re: [R] How to get a proportion of a Vector Member

2010-09-29 Thread Peng, C

sum(foo==o)/length(foo)


-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-get-a-proportion-of-a-Vector-Member-tp2720060p2720067.html
Sent from the R help mailing list archive at Nabble.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] constrained optimization -which package?

2010-09-28 Thread Peng, C

?constrOptim


-- 
View this message in context: 
http://r.789695.n4.nabble.com/constrained-optimization-which-package-tp2717677p2717719.html
Sent from the R help mailing list archive at Nabble.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] constrained optimization -which package?

2010-09-28 Thread Peng, C

constrOptim()  can do linear and quadratic programming problems!  See the
following example from the help document.   
 
## Solves linear and quadratic programming problems
 ## but needs a feasible starting value
 #
 # from example(solve.QP) in 'quadprog'
 # no derivative
 fQP - function(b) {-sum(c(0,5,0)*b)+0.5*sum(b*b)}
 Amat   - matrix(c(-4,-3,0,2,1,0,0,-2,1),3,3)
 bvec   - c(-8,2,0)
 constrOptim(c(2,-1,-1), fQP, NULL, ui=t(Amat),ci=bvec)
 # derivative
 gQP - function(b) {-c(0,5,0)+b}
 constrOptim(c(2,-1,-1), fQP, gQP, ui=t(Amat), ci=bvec)
 
 ## Now with maximisation instead of minimisation
 hQP - function(b) {sum(c(0,5,0)*b)-0.5*sum(b*b)}
 constrOptim(c(2,-1,-1), hQP, NULL, ui=t(Amat), ci=bvec,
 control=list(fnscale=-1))

-- 
View this message in context: 
http://r.789695.n4.nabble.com/constrained-optimization-which-package-tp2717677p2718136.html
Sent from the R help mailing list archive at Nabble.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] bptest

2010-09-24 Thread Peng, C

you have to load package {lmtest} first. That is,

library(lmtest)
bptest(modelCH, data=KP) 

-- 
View this message in context: 
http://r.789695.n4.nabble.com/bptest-tp2553506p2579815.html
Sent from the R help mailing list archive at Nabble.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] Problem with any()

2010-09-24 Thread Peng, C

Is as.integer() redundant for this vector of integers?

any(c(1, 3) == 3.0 )
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-any-tp2553226p2580659.html
Sent from the R help mailing list archive at Nabble.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] delete d-jackknife with R ?

2010-09-24 Thread Peng, C

You may want to use combinations() in package {gtools} and write a function
with a few lines to perform your leave-k-out procedure.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/delete-d-jackknife-with-R-tp2553192p2585783.html
Sent from the R help mailing list archive at Nabble.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] Odds ratio from Logistic model in R

2010-09-24 Thread Peng, C

The output of logisitic procdure only gives you the log(odds-ratio) and the
associated standard error of the log(odds-ratio). You need to exponentiate
the log(odds-ratio) to get your odds ratio. The code tells you how to obtain
the odds ratio from log(odds-ratio).
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Odds-ratio-from-Logistic-model-in-R-tp2630277p2651963.html
Sent from the R help mailing list archive at Nabble.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] Survival curve mean adjusted for covariate

2010-09-22 Thread Peng, C

do the same thing for female and then take the weighted average of the two
means.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Survival-curve-mean-adjusted-for-covariate-tp2548387p2550178.html
Sent from the R help mailing list archive at Nabble.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] Survival curve mean adjusted for covariate

2010-09-22 Thread Peng, C

do the same thing for female and then take the weighted average of the two
means.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Survival-curve-mean-adjusted-for-covariate-tp2548387p2550179.html
Sent from the R help mailing list archive at Nabble.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] apply union function vectorially

2010-09-22 Thread Peng, C

unique(unlist(list.array))
-- 
View this message in context: 
http://r.789695.n4.nabble.com/apply-union-function-vectorially-tp2550162p2550193.html
Sent from the R help mailing list archive at Nabble.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] kstest vs shapirotest

2010-09-22 Thread Peng, C

In general Shapiro's normality test is more powerful than the KS. For this
specific case, I don't see the significantly different results from both
tests. The normality assumption in this example seems to be questionable.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/kstest-vs-shapirotest-tp2550192p2550243.html
Sent from the R help mailing list archive at Nabble.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] eigen and svd

2010-09-22 Thread Peng, C

svd() does not return eigeinvectors!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/eigen-and-svd-tp2550210p2550257.html
Sent from the R help mailing list archive at Nabble.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] best model cp mallow

2010-09-22 Thread Peng, C

I think you need to set up a cut-off of Cp and then get the good values of
Cp from adjr$Cp.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/best-model-cp-mallow-tp2550015p2550283.html
Sent from the R help mailing list archive at Nabble.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] merge verctor and matrix

2010-09-22 Thread Peng, C

  v=data.frame(c1=c(e,r,t),v=c(1,4,2) )
  m=matrix(c(r,t,r,s,e,5,6,7,8,9),nr=5) 
  colnames(m)=c(c1,c2)
  m=as.data.frame(m)
  merge(v, m, by =c1 )
  c1 v c2
1  e 1  9
2  r 4  5
3  r 4  7
4  t 2  6

-- 
View this message in context: 
http://r.789695.n4.nabble.com/merge-verctor-and-matrix-tp2550280p2550315.html
Sent from the R help mailing list archive at Nabble.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] Problem with cat() == A related question

2010-09-16 Thread Peng, C

The question is wehter cat() can print out a matrix as it is. For example,
Let's assume that we have matrices A, B, D(= A+B), if it is possible that
cat(\n, A, +,B,=, D,  some control arguments , \n)
prints out

  matrix A +  matrix B  = matrix D

where matrices A, B, D (= A+B) should be in the form of their actual
matrices.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-cat-tp2538811p2542098.html
Sent from the R help mailing list archive at Nabble.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] Problem with cat() == A related question

2010-09-14 Thread Peng, C

Code:

 fn1 - function(n = 5){ 
+  mat - matrix(rnorm(5*5), 5, 5) 
+  cat(print(mat))  
+ } 
 fn1()
   [,1][,2]   [,3][,4]   [,5]
[1,] -0.7101952  0.78992424 -0.8310871  2.49560703 -0.9543827
[2,] -0.1425682 -2.69186367 -0.5937949  0.03188572 -0.5512154
[3,] -0.3041728  0.05099222 -2.0905322  0.19254519 -0.1208534
[4,]  2.0812597  1.22048195  1.9347253 -1.25478253  1.2998755
[5,]  0.9256113  0.02686392 -0.1059670 -2.62715239 -0.4826737
-0.7101952 -0.1425682 -0.3041728 2.081260 0.9256113 0.7899242 -2.691864
0.05099222 1.220482 0.02686392 -0.8310871 -0.5937949 -2.090532 1.934725
-0.1059670 2.495607 0.03188572 0.1925452 -1.254783 -2.627152 -0.9543827
-0.5512154 -0.1208534 1.299876 -0.4826737 
 

Question: Is there any control arguments can be used such that fn1() ONLY
prints out the matrix part?

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-cat-tp2538811p2539017.html
Sent from the R help mailing list archive at Nabble.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] Problem with cat() == A related question

2010-09-14 Thread Peng, C

It is still visible even it is set invisible(NULL):

  fn1 - function(n = 5){ 
+  mat - matrix(rnorm(5*5), 5, 5) 
+   cat(print(mat)) 
+  invisible(NULL)} 
 fn1()
[,1][,2]   [,3][,4]   [,5]
[1,] -1.22767085 -1.41468587 -2.0156231  0.29732942  0.5755600
[2,] -0.16775996 -0.03780596 -0.9461079  0.91289175  0.1254273
[3,]  0.09696032 -0.75522210 -0.7494442 -0.21341669  1.7088194
[4,]  0.13535505 -1.09011005 -0.6074198  0.05342614 -1.1996344
[5,]  0.66474083 -2.62206248  0.1329972  0.06132865  0.5124778
-1.227671 -0.1677600 0.09696032 0.1353550 0.6647408 -1.414686 -0.03780596
-0.7552221 -1.09011 -2.622062 -2.015623 -0.9461079 -0.7494442 -0.6074198
0.1329972 0.2973294 0.9128917 -0.2134167 0.05342614 0.06132865 0.57556
0.1254273 1.708819 -1.199634 0.5124778 
 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-cat-tp2538811p2539551.html
Sent from the R help mailing list archive at Nabble.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] for loop

2010-09-11 Thread Peng, C

or:

k=0 
for (i in 1:k) if(k0) print(i) 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/for-loop-tp2535626p2535640.html
Sent from the R help mailing list archive at Nabble.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] Generating multinomial distribution and plotting

2010-09-11 Thread Peng, C

package: {mnormt}
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Generating-multinomial-distribution-and-plotting-tp2535895p2535934.html
Sent from the R help mailing list archive at Nabble.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] confidence bands for a quasipoisson glm

2010-09-11 Thread Peng, C

Is this something you want to have  (based on a simulated dataset)?

counts - c(18,17,15,20,10,20,25,13,12)
#risk - round(rexp(9,0.5),3)
risk- c(2.242, 0.113, 1.480, 0.913, 5.795, 0.170, 0.846, 5.240, 0.648)
gm - glm(counts ~ risk, family=quasipoisson)
summary(gm)
new.risk=seq(min(risk), max(risk),0.1)
new.risk
y - predict.glm(gm, newdata=data.frame(risk=new.risk), se.fit=TRUE,
type=response) 
upper=y$fit+1.96*y$se.fit
lower=y$fit-1.96*y$se.fit
plot(new.risk,y$fit, type=l, col=4, lty=1, lwd=2)
lines(new.risk, upper, type=l, col=2, lty=2, lwd=2)
lines(new.risk, lower, type=l, col=2, lty=2, lwd=2)



-- 
View this message in context: 
http://r.789695.n4.nabble.com/confidence-bands-for-a-quasipoisson-glm-tp2535883p2535952.html
Sent from the R help mailing list archive at Nabble.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] Supplying function inputs interactively

2010-09-11 Thread Peng, C


Have you tried scan()?:


 y=scan()
1: 2
2: 
Read 1 item
 y
[1] 2
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Supplying-function-inputs-interactively-tp2536003p2536004.html
Sent from the R help mailing list archive at Nabble.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] Supplying function inputs interactively

2010-09-11 Thread Peng, C

Is this what you would expect to have. Definitely you can make this function
more elegant:

fn1 - function(x = 10) { 
cat(Please type the option number to get your Y value:\n\n)
cat( 1. Y = 1.\n
 2. Y = 2.\n
 3. Use the default y.\n
 4. Choose my own value for y.\n\n)
opt=scan()
if (opt==3) y -0
else if (opt==4) {
 cat(Please type your Y value:\n\n)
 y=scan()
 }
else y = opt 
return(x*y) 
} 



-- 
View this message in context: 
http://r.789695.n4.nabble.com/Supplying-function-inputs-interactively-tp2536003p2536012.html
Sent from the R help mailing list archive at Nabble.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] Generating multinomial distribution and plotting

2010-09-11 Thread Peng, C

Oh,You actually want a mixture of two different normal random variables.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Generating-multinomial-distribution-and-plotting-tp2535895p2536026.html
Sent from the R help mailing list archive at Nabble.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] gee p values

2010-09-10 Thread Peng, C

There are two z-scores reported in the summary: Naive z and Robust z.

pvalue=2*min(pnorm(z-score), 1-pnorm(z-score))   # two-sided test

-- 
View this message in context: 
http://r.789695.n4.nabble.com/gee-p-values-tp2533835p2534302.html
Sent from the R help mailing list archive at Nabble.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] boxplot knowing Q1, Q3, median, upper and lower whisker value

2010-09-10 Thread Peng, C

 x=1:16
 S=summary(x)
 S
   Min. 1st Qu.  MedianMean 3rd Qu.Max. 
   1.004.758.508.50   12.25   16.00 
S[-4]
   Min. 1st Qu.  Median 3rd Qu.Max. 
   1.004.758.50   12.25   16.00 
 par(mfrow=c(1,2))
 boxplot(S[-4])   # based on the summarized stats
 boxplot(x) # based on the raw data
 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/boxplot-knowing-Q1-Q3-median-upper-and-lower-whisker-value-tp2528571p2534818.html
Sent from the R help mailing list archive at Nabble.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] Counting occurances of a letter by a factor

2010-09-10 Thread Peng, C

try:

?ftable
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Counting-occurances-of-a-letter-by-a-factor-tp2534993p2535002.html
Sent from the R help mailing list archive at Nabble.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] Dividing a vector into equal interval

2010-09-10 Thread Peng, C

just store the broken sequences in a matrix:

M=matrix(1:12, ncol=3, byrow=FALSE)
 M
 [,1] [,2] [,3]
[1,]159
[2,]26   10
[3,]37   11
[4,]48   12

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Dividing-a-vector-into-equal-interval-tp2534938p2535012.html
Sent from the R help mailing list archive at Nabble.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] convert 1, 10, and 100 to 0001, 0010, 0100 etc.

2010-09-10 Thread Peng, C

These are character values. Is there any way to get 001, 010, ..., as actual
numeric values?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/convert-1-10-and-100-to-0001-0010-0100-etc-tp2535023p2535296.html
Sent from the R help mailing list archive at Nabble.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] convert 1, 10, and 100 to 0001, 0010, 0100 etc.

2010-09-10 Thread Peng, C

I mean to display 001,010, ..., as there are.  In other words, whether there
is a function, say func(), such that func(001,010) displays 001, 010. 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/convert-1-10-and-100-to-0001-0010-0100-etc-tp2535023p2535318.html
Sent from the R help mailing list archive at Nabble.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] convert 1, 10, and 100 to 0001, 0010, 0100 etc.

2010-09-10 Thread Peng, C

Thanks David. 
func() simply prints out the 0010 as a text value. It is still not numeric.
I am just curious about it.

 is.numeric(func4(0100))
00100[1] FALSE


-- 
View this message in context: 
http://r.789695.n4.nabble.com/convert-1-10-and-100-to-0001-0010-0100-etc-tp2535023p2535345.html
Sent from the R help mailing list archive at Nabble.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] Reproducible research

2010-09-09 Thread Peng, C

FYI: If you use LaTex, you can work out on something between R and LaTex.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Reproducible-research-tp2532353p2532361.html
Sent from the R help mailing list archive at Nabble.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] Calculating with tolerances (error propagation)

2010-09-09 Thread Peng, C

 q-0.15 + c(-.1,0,.1) 
 h-10 + c(-.1,0,.1) 
 
 5*q/h[3:1] 
[1] 0.02475248 0.0750 0.12626263
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Re-Calculating-with-tolerances-error-propagation-tp2532640p2532991.html
Sent from the R help mailing list archive at Nabble.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] problem with outer

2010-09-09 Thread Peng, C

Can you set the multinomial prob. to zero for p1+p2+p3 != 1 if you have to
use the multinomial distribution in guete(). Otherwise, I would say the
problem/guete() itself is problematic.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2533050.html
Sent from the R help mailing list archive at Nabble.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] Help on simple problem with optim

2010-09-09 Thread Peng, C

Yanwei!!!

Have you tried to write the likelihood function using log-normal directly?
if you haven't so, you may want to check  ?rlnorm


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Help-on-simple-problem-with-optim-tp2533420p2533487.html
Sent from the R help mailing list archive at Nabble.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] How to change font size in plot() function

2010-09-08 Thread Peng, C

try:

?title
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-change-font-size-in-plot-function-tp2531127p2531161.html
Sent from the R help mailing list archive at Nabble.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] forecasting with non-linear models

2010-09-08 Thread Peng, C

predict x for a given y(response)?  If this is the case, you will have
multiple x for a single y for this exponential model. In terms of logistic
regression, If y =1, logit([P(Y=1)] = a + b*bx has infinite many x. The
question seems not quite clear to me.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/forecasting-with-non-linear-models-tp2531125p2531186.html
Sent from the R help mailing list archive at Nabble.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] How to project a vector on a subspace?

2010-09-08 Thread Peng, C

Can you be a little bit more specific? For example, the base vectors of the
subspace and the vector you want to project. Specific artificial
vectors/matrices are helpful.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-project-a-vector-on-a-subspace-tp2530886p2531245.html
Sent from the R help mailing list archive at Nabble.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] Interpolation missing data

2010-09-08 Thread Peng, C

try packages:

{yaImpute}, {impute}, etc.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Interpolation-missing-data-tp2530871p2531288.html
Sent from the R help mailing list archive at Nabble.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] Uniform Distribution

2010-09-08 Thread Peng, C

?runif
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Uniform-Distribution-tp2531282p2531292.html
Sent from the R help mailing list archive at Nabble.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] problem with outer

2010-09-08 Thread Peng, C

The defintion of the sequency of probability was wrong!
 p_11=seq(0,1,0.1) 
 p_12=seq(0,1,0.1) 

Since your multinomial distribution requires P_11, P_12, P13=1-P_11-P12 be
greater than or equal to zero and P_11+P_12+P_13 = 1. In your above
definition of P_11[6] =P_12[6]= 0.6, P_11[7] = P_12[7] = 0.7, ..., P_11[10]
=P_12[10]=1.0. For these pairs 1-p_11-p_12  0! There is why you had the
error message!

 X_1=rmultinom(n-q+1,size=1,prob=cbind(p_11,p_12,(1-p_11-p_12))) 

Suggested Solution:

Redefine P_11 and P_12 such that P_11[i] + P_12[i] 1 for all i! This will
sove your problem!

# you choose whatever a and b such that a+b=1. for example,
a = 0.4
b = 0.6
# you need to adjust the increaments to get vectors with equal length.
p_11=seq(0,a,0.05*a)  
p_12=seq(0, b,0.05*b) 

 
 
 guete = function(p_11,p_12) { 
+if(p_11+p_121) 
+  set.seed(1000) 
+  S_vek=matrix(0,nrow=N,ncol=1) 
+   for(i in 1:N) { 
+ X_0=rmultinom(q-1,size=1,prob=p_0) 
+
X_1=rmultinom(n-q+1,size=1,prob=cbind(p_11,p_12,(1-p_11-p_12))) 
+ N_0=apply(X_0[,(n-2*k-L+1):(n-k-L)],1,sum) 
+ N_1=apply(X_1[,(n-q-k+2):(n-q+1)],1,sum) 
+
S_vek[i]=((sum(((N_1-k*cbind(p_11,p_12,(1-p_11-p_12)))^2)/k*cbind(p_11,p_12,(1-p_11-p_12/(sum(((N_0-k*p_0)^2)/k*p_0)))-1
 
+   } 
+   1-mean(f_1=S_vek  S_vek =f_2) 
+ } 
 
 
 f=outer(p_11,p_12,Vectorize(guete)) 
 f
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21]
 [1,]  1.0  0.9  0.9  0.8  0.8  0.7  0.6  0.6  0.6   0.4   0.7   0.8   0.8  
0.7   0.6   0.7   0.9   0.8   0.7   0.5   0.6
 [2,]  0.9  1.0  0.9  0.7  0.6  0.6  0.5  0.5  0.7   0.7   0.6   0.5   0.4  
0.2   0.3   0.4   0.7   0.6   0.2   0.3   0.3
 [3,]  0.9  1.0  0.8  0.8  0.7  0.7  0.7  0.6  0.6   0.5   0.7   0.6   0.3  
0.3   0.4   0.5   0.5   0.5   0.4   0.3   0.3
 [4,]  0.9  0.8  0.8  0.8  0.7  0.7  0.5  0.5  0.6   0.8   0.7   0.6   0.5  
0.5   0.4   0.6   0.5   0.6   0.5   0.4   0.5
 [5,]  0.8  0.8  0.9  0.7  0.6  0.5  0.4  0.4  0.5   0.6   0.4   0.6   0.5  
0.5   0.5   0.5   0.6   0.4   0.4   0.6   0.5
 [6,]  0.8  0.9  0.7  0.5  0.6  0.6  0.5  0.4  0.5   0.6   0.5   0.6   0.3  
0.4   0.6   0.5   0.6   0.4   0.3   0.6   0.5
 [7,]  0.8  1.0  0.6  0.4  0.5  0.7  0.6  0.6  0.7   0.7   0.5   0.4   0.4  
0.4   0.5   0.6   0.4   0.4   0.4   0.6   0.6
 [8,]  0.7  1.0  0.6  0.5  0.5  0.7  0.7  0.8  0.8   0.7   0.6   0.4   0.6  
0.6   0.7   0.7   0.6   0.5   0.5   0.5   0.8
 [9,]  0.7  0.7  0.6  0.7  0.5  0.4  0.5  0.6  0.6   0.4   0.2   0.2   0.5  
0.5   0.5   0.5   0.5   0.2   0.2   0.4   0.6
[10,]  0.6  0.7  0.7  0.5  0.4  0.4  0.5  0.7  0.7   0.5   0.3   0.4   0.5  
0.4   0.5   0.4   0.5   0.3   0.3   0.6   0.7
[11,]  0.7  0.7  0.8  0.7  0.6  0.5  0.5  0.7  0.7   0.5   0.5   0.6   0.5  
0.5   0.5   0.5   0.5   0.5   0.5   0.7   0.7
[12,]  0.7  0.7  0.6  0.5  0.5  0.4  0.5  0.5  0.6   0.5   0.4   0.2   0.2  
0.3   0.2   0.2   0.4   0.5   0.6   0.5   0.5
[13,]  0.6  0.6  0.6  0.4  0.3  0.2  0.7  0.6  0.5   0.6   0.4   0.4   0.3  
0.3   0.4   0.4   0.6   0.6   0.6   0.7   0.3
[14,]  0.4  0.6  0.6  0.4  0.1  0.7  0.7  0.5  0.6   0.6   0.5   0.4   0.3  
0.3   0.4   0.5   0.6   0.5   0.6   0.6   0.2
[15,]  0.4  0.6  0.6  0.4  0.3  0.4  0.4  0.3  0.4   0.5   0.5   0.5   0.3  
0.5   0.5   0.5   0.4   0.3   0.4   0.4   0.3
[16,]  0.7  0.3  0.3  0.2  0.2  0.2  0.1  0.1  0.2   0.1   0.1   0.2   0.2  
0.1   0.1   0.2   0.1   0.1   0.0   0.3   0.2
[17,]  0.7  0.4  0.4  0.2  0.2  0.2  0.2  0.2  0.2   0.1   0.3   0.3   0.3  
0.3   0.1   0.2   0.2   0.2   0.2   0.2   0.2
[18,]  0.8  0.3  0.3  0.2  0.2  0.2  0.1  0.1  0.1   0.1   0.1   0.1   0.1  
0.1   0.1   0.1   0.1   0.2   0.2   0.2   0.3
[19,]  0.8  0.7  0.7  0.6  0.5  0.4  0.4  0.3  0.2   0.2   0.2   0.2   0.2  
0.1   0.3   0.4   0.4   0.5   0.5   0.7   0.7
[20,]  0.6  0.4  0.3  0.2  0.3  0.3  0.3  0.3  0.2   0.3   0.3   0.3   0.2  
0.3   0.3   0.3   0.3   0.3   0.2   0.3   0.4
[21,]  0.6  0.3  0.4  0.4  0.4  0.3  0.3  0.4  0.4   0.1   0.1   0.1   0.4  
0.4   0.3   0.3   0.4   0.4   0.4   0.3   0.5






-- 
View this message in context: 
http://r.789695.n4.nabble.com/problem-with-outer-tp2532074p2532282.html
Sent from the R help mailing list archive at Nabble.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] coxph and ordinal variables?

2010-09-08 Thread Peng, C

I look at this question in a different angle. My understanding is:

1. If treat tumor_grade as a numerical variable, you assume the hazard ratio
is invariant between any two adjacent levels of the tumor grade (assuming
invariant covariate patterns of other risks);
2. If you treat the tumor_grade as factor, you don't assume the constant
hazard ratio between the levels (assuming invariant covariate patterns of
other risks).

I don't see the difference between continuous risk and discrete ordinal risk
in this case. 
If the tumor grade is the response, there will be a difference between
variables types (ordinal, continuous and nominal) since that information
will be used to select appropriate models.

-- 
View this message in context: 
http://r.789695.n4.nabble.com/coxph-and-ordinal-variables-tp2532149p2532299.html
Sent from the R help mailing list archive at Nabble.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] regression function for categorical predictor data

2010-09-08 Thread Peng, C

glm() is another choice. Using glm(), you response variable can be a discrete
random bariable, however, you need to specify the distribution in the
argument: family =  distriubtion name

Use Teds simulated data and glm(), you get the same result as that produced
in lm():

 summary(glm(Y ~ X + F, family=gaussian)) 

Call:
glm(formula = Y ~ X + F, family = gaussian)

Deviance Residuals: 
 Min1QMedian3Q   Max  
-0.53796  -0.16201  -0.08087   0.15080   0.47363  

Coefficients:
Estimate Std. Error t value Pr(|t|)
(Intercept)  0.037230.08457   0.440 0.662267
X0.510090.13036   3.913 0.000365 ***
FB   1.825780.15429  11.833  2.6e-14 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

(Dispersion parameter for gaussian family taken to be 0.06096497)

Null deviance: 59.7558  on 40  degrees of freedom
Residual deviance:  2.3167  on 38  degrees of freedom
AIC: 6.5418

Number of Fisher Scoring iterations: 2

-- 
View this message in context: 
http://r.789695.n4.nabble.com/regression-function-for-categorical-predictor-data-tp2532045p2532302.html
Sent from the R help mailing list archive at Nabble.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] regression function for categorical predictor data

2010-09-08 Thread Peng, C

Sorry, result is not the same, since our datasets are different. I also run
lm() based on the dataset that used in glm(). THe results are exactly the
same:

 summary(lm(Y ~ X + F)) 

Call:
lm(formula = Y ~ X + F)

Residuals:
 Min   1Q   Median   3Q  Max 
-0.53796 -0.16201 -0.08087  0.15080  0.47363 

Coefficients:
Estimate Std. Error t value Pr(|t|)
(Intercept)  0.037230.08457   0.440 0.662267
X0.510090.13036   3.913 0.000365 ***
FB   1.825780.15429  11.833  2.6e-14 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.2469 on 38 degrees of freedom
Multiple R-squared: 0.9612, Adjusted R-squared: 0.9592 
F-statistic: 471.1 on 2 and 38 DF,  p-value:  2.2e-16 


===
The dataset is given below:

 cbind(Y,X,F)
Y X F
 [1,] -0.28473266 -1.00 1
 [2,] -0.59041310 -0.95 1
 [3,] -0.50431754 -0.90 1
 [4,] -0.60095969 -0.85 1
 [5,] -0.45849905 -0.80 1
 [6,] -0.48287208 -0.75 1
 [7,] -0.49598666 -0.70 1
 [8,] -0.08746758 -0.65 1
 [9,] -0.18665177 -0.60 1
[10,] -0.01007210 -0.55 1
[11,] -0.45765308 -0.50 1
[12,] -0.27318684 -0.45 1
[13,]  0.07638855 -0.40 1
[14,]  0.27043727 -0.35 1
[15,]  0.26926216 -0.30 1
[16,] -0.43047783 -0.25 1
[17,]  0.40884468 -0.20 1
[18,] -0.14638563 -0.15 1
[19,] -0.31374179 -0.10 1
[20,] -0.15028159 -0.05 1
[21,] -0.12540519  0.00 1
[22,]  1.58015611  0.05 2
[23,]  1.68200774  0.10 2
[24,]  2.02821901  0.15 2
[25,]  2.02359285  0.20 2
[26,]  2.14133171  0.25 2
[27,]  2.06931685  0.30 2
[28,]  2.05561726  0.35 2
[29,]  2.35720999  0.40 2
[30,]  1.96134404  0.45 2
[31,]  2.26144356  0.50 2
[32,]  2.24454620  0.55 2
[33,]  2.55707426  0.60 2
[34,]  2.18732022  0.65 2
[35,]  1.90950697  0.70 2
[36,]  2.10371010  0.75 2
[37,]  2.18266009  0.80 2
[38,]  2.18490441  0.85 2
[39,]  2.45248295  0.90 2
[40,]  2.79851838  0.95 2
[41,]  1.83514341  1.00 2


-- 
View this message in context: 
http://r.789695.n4.nabble.com/regression-function-for-categorical-predictor-data-tp2532045p2532305.html
Sent from the R help mailing list archive at Nabble.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] minor diagonal in R

2010-09-07 Thread Peng, C

This this what you want?

 A=matrix(1:16,ncol=4)
 A
 [,1] [,2] [,3] [,4]
[1,]159   13
[2,]26   10   14
[3,]37   11   15
[4,]48   12   16
 diag(A[1:4,4:1])
[1] 13 10  7  4
 

-- 
View this message in context: 
http://r.789695.n4.nabble.com/minor-diagonal-in-R-tp2529676p2529710.html
Sent from the R help mailing list archive at Nabble.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] Percentile rank for each element in list

2010-09-07 Thread Peng, C

Is this what you want to have:

 x - c(1,5,100,300,250,200,550,900,1000) 
 # assume you want the position of 25th percentile
 which(x==quantile(x,0.25))
[1] 3

Note that position is meaningful only when the percentile is one of the
observed data values. If you want to know the position of 70th percentile
(that is between position 6 and position 7). You need to do something
coding to get these two adjacent positions.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Percentile-rank-for-each-element-in-list-tp2529523p2529741.html
Sent from the R help mailing list archive at Nabble.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] minor diagonal in R

2010-09-07 Thread Peng, C

diag has 4 letters
cbind has 5 letters  :)

-- 
View this message in context: 
http://r.789695.n4.nabble.com/minor-diagonal-in-R-tp2529676p2529746.html
Sent from the R help mailing list archive at Nabble.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] R package to identify model

2010-09-07 Thread Peng, C

what is ESP package? Thanks.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/R-package-to-identify-model-tp2529525p2529766.html
Sent from the R help mailing list archive at Nabble.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] Over lay 2 scale in same plot

2010-09-07 Thread Peng, C

Modified from Josh's code:

Is this you want to see?

  barplot(-50:50) 
  # add points into the existing plot at the coordinates set by x and y 
  # and use a line to connect them 
  points(x = 1:101, y = seq(from = 30, to = -20, length.out = 101), type =
 l) 
  # add right hand side axis labeled with different scales. You can adjust
 the 
  # labels according to what rule you have based on the original scale of
 left hand side axis.
  axis(4,at=seq(-40,40,20), label=seq(-4,4,2))
 

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Over-lay-2-scale-in-same-plot-tp2528661p2529802.html
Sent from the R help mailing list archive at Nabble.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] U value from wilcox.test

2010-09-07 Thread Peng, C

In addition to Cedric's comments, these are large sample procedures. Your
sample sizes are two small. I don't think any procedures using normal
approximations are inappropriate for your case. I would suggest making a
reasonable distribution on the populations to avoid asymptotic results.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/U-value-from-wilcox-test-tp2332811p2529823.html
Sent from the R help mailing list archive at Nabble.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] Percentile rank for each element in list

2010-09-07 Thread Peng, C

It seems to produce some strange values:

 xx=1:10
 which(xx==quantile(x,0.2,type=3))
[1] 5
 which(xx==quantile(x,0.5,type=3))
integer(0)

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Percentile-rank-for-each-element-in-list-tp2529523p2530060.html
Sent from the R help mailing list archive at Nabble.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] some questions about longitudinal study with baseline

2010-09-07 Thread Peng, C

You may be interested in the tutorial of repeated measure ANOVA at UCLA
computing page at:

http://www.ats.ucla.edu/stat/R/seminars/Repeated_Measures/repeated_measures.htm


-- 
View this message in context: 
http://r.789695.n4.nabble.com/some-questions-about-longitudinal-study-with-baseline-tp2530097p2530264.html
Sent from the R help mailing list archive at Nabble.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] likelyhood maximization problem with polr

2010-09-07 Thread Peng, C

If you can prove that the Fisher information matrix is positive definite, the
resulting estimate is MLE. Otherwise you can only claim it a local MLE (the
Hessian matrix at the estimate is negative definite). 





-- 
View this message in context: 
http://r.789695.n4.nabble.com/likelyhood-maximization-problem-with-polr-tp2528818p2530594.html
Sent from the R help mailing list archive at Nabble.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] repeated measurements ANOVA

2010-09-07 Thread Peng, C

You can find the layout of data for repeated measuremnt ANOVA in examples
from UCLA computing page:

http://www.ats.ucla.edu/stat/R/seminars/Repeated_Measures/repeated_measures.htm
-- 
View this message in context: 
http://r.789695.n4.nabble.com/repeated-measurements-ANOVA-tp2530368p2530600.html
Sent from the R help mailing list archive at Nabble.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] anova of glm output

2010-09-07 Thread Peng, C

The ANOVA adds the factors only in the order given in the model formula from
left to right. You may try

drop1(out, test=Chisq)


-- 
View this message in context: 
http://r.789695.n4.nabble.com/anova-of-glm-output-tp2528336p2530620.html
Sent from the R help mailing list archive at Nabble.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] likelyhood maximization problem with polr

2010-09-06 Thread Peng, C

Since the default initial value is not good enough. You should choose one
based on your experience or luck. I choose start=rep(1,5) since there are
parameters in the model.

 polr(Species~Sepal.Length+Sepal.Width+Petal.Length+Petal.Width,iris,
 start=rep(1,6), method = logistic) 
Call:
polr(formula = Species ~ Sepal.Length + Sepal.Width + Petal.Length + 
Petal.Width, data = iris, start = rep(1, 6), method = logistic)

Coefficients:
Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
   -2.471271-6.675614 9.43275318.266280 

Intercepts:
   setosa|versicolor versicolor|virginica 
5.51322342.598774 

Residual Deviance: 11.89856 
AIC: 23.89856 


-- 
View this message in context: 
http://r.789695.n4.nabble.com/likelyhood-maximization-problem-with-polr-tp2528818p2529174.html
Sent from the R help mailing list archive at Nabble.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] likelyhood maximization problem with polr

2010-09-06 Thread Peng, C

sorry: start=rep(1,6) since there are 6 parameters in the model.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/likelyhood-maximization-problem-with-polr-tp2528818p2529176.html
Sent from the R help mailing list archive at Nabble.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] row echelon form

2010-09-06 Thread Peng, C

Scott, it seems to have bug in your code:
 A=matrix(c(1,-2,3,9,-1,3,0,-4,2,-5,5,17),ncol=4,byrow=T)
 ref(A)
 [,1] [,2] [,3] [,4]
[1,]1 -2.5 2.17 7.83
[2,]0  1.0 3.00 5.00
[3,]0  0.0 1.00 2.00

the row echelon is apparently incorrect.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/row-echelon-form-tp833608p2529183.html
Sent from the R help mailing list archive at Nabble.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] Linear Logistic Regression - Understanding the output (and possibly the test to use!)

2010-09-05 Thread Peng, C


Calum-4 wrote:
 
 Hi I know asking which test to use is frowned upon on this list... so 
 please do read on for at least a couple on sentences...
 
 I have some multivariate data slit as follows
 
 Tumour Site (one of 5 categories) #
 Chemo Schedule (one of 3 cats) ##
 Cycle (one of 3 cats*) ##
 Dose (one of 3 cats*) #
 
 *These are actually integers but for all our other analysis so far we 
 have grouped them into logical bands of categories.
 
 The dependant variable is Reaction or No Reaction
 
 I have individually analysed each of the independant variables against 
 Reaction/No Reaction using ChiSq and Fisher Tests. Those marked ## 
 produced p values less than 0.05, and those marked # produce p values 
 close to 0.05.
 
 We believe that Cycle is the crucial piece of data - the others just 
 appear to be different because there are more early cycles in certain 
 groups than others.
 
 SO - I believe what I need to do is a Linear Logistic Regression on the 
 4 independant variables. And I'm expecting it to show that the tumour 
 site, schedule and dose don't matter, only the cycle matters. Done a lot 
 of reading and I'm clueless!!
 
 I think I want to do something like:
 
 glm (reaction ~ site + sched + cycle + dose, data=mydata, family=poisson)
 =
 Comment  1: If you stick to Linear Logistic Regression, the family should
 be binomial assuming that reaction has only two values (Yes/No).
 family=poisson should be used when the response is a frequency count
 such as the number of tumors.
 =
 
 I am then expecting to see some very long output with lots of numbers... 
 ...my question is TWO fold -
 
 1. is glm the right thing to use before I waste my time
 
 and 2. how do I interpret the result! (I'm kind of expect a lecture here 
 as I'm really looking for a nice snappy 'p0.05 means this variable is 
 the one having the influence' type answer and I suspect I'm going to be 
 told thats not possible...!
 
 Comment 2: The regression coefficients in binary logistic regression
 models are called log-odds ratio. The interpretation of odds ratio can be
 tricky but the p-value is interpreted in the usual way.
 
 To be clear the example given in the docs is:
 
  library(MASS)
 
  data(anorexia)
 
  anorex.1- glm(Postwt ~ Prewt + Treat + offset(Prewt), family =
 gaussian, data = anorexia)
 
 ===
 Comment 3. Here Postwt is a continuous variable. The specification family
 = gaussian assumes the that Postwt is a normal variable, therefore, the
 fitted model is the ordinary normal linear regression model.
 ===
 
 The output of anorex.1 is:
 
 Call:  glm(formula = Postwt ~ Prewt + Treat + offset(Prewt), family =
 gaussian,  data = anorexia)
 
 Coefficients:
 
 (Intercept)PrewtTreatCont  TreatFT
 
  49.7711  -0.5655  -4.0971   4.5631
 
 Degrees of Freedom: 71 Total (i.e. Null);  68 Residual
 
 Null Deviance:4525
 
 Residual Deviance: 3311 AIC: 490
 
 
 
 and the output of summary(anorex.1) is:
 
 Call:
 
 glm(formula = Postwt ~ Prewt + Treat + offset(Prewt), family = gaussian,
 
  data = anorexia)
 
 Deviance Residuals:
 
   Min1QMedian3Q   Max
 
 -14.1083   -4.2773   -0.54845.4838   15.2922
 
 Coefficients:
 
  Estimate Std. Error t value Pr(|t|)
 
 (Intercept)  49.771113.3910   3.717 0.000410 ***
 
 Prewt-0.5655 0.1612  -3.509 0.000803 ***
 
 TreatCont-4.0971 1.8935  -2.164 0.033999 *
 
 TreatFT   4.5631 2.1333   2.139 0.036035 *
 
 ---
 
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 
 (Dispersion parameter for gaussian family taken to be 48.69504)
 
  Null deviance: 4525.4  on 71  degrees of freedom
 
 Residual deviance: 3311.3  on 68  degrees of freedom
 
 AIC: 489.97
 
 Number of Fisher Scoring iterations: 2
 
 
 
 ---
 Either can someone point me to a decent place that would explain what 
 the means or provide me some pointers? i.e. which of the variables has 
 the influence on the outcome in the anorexia data?
 
 Please don't shout!! happy to be pointed to a reference but would prefer 
 one in common english not some stats mumbo jumbo!
 
 Calum
 
 __
 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.
 
 

-- 
View this message in context: 
http://r.789695.n4.nabble.com/non-zero-exit-status-error-when-install-GenomeGraphs-tp2526950p2527317.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list

Re: [R] How can I fixe convergence=1 in optim

2010-09-04 Thread Peng, C

To change the default maximum number of iterations (mxit =100 for derivative
based algorithm), add mxit = whatever number you want.

In most cases, you need a very good initial value! This is a real challenge
in using optim(). Quite often, if the initial values is not well selected,
optim() can give you nonsense estimates even the algorithm converges after
number of iterations.  

-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-can-I-fixe-convergence-1-in-optim-tp2527034p2527087.html
Sent from the R help mailing list archive at Nabble.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] how to get row name of matrix when result is a vector

2010-09-03 Thread Peng, C

R doesn't simply treat a row vector as a matrix.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/how-to-get-row-name-of-matrix-when-result-is-a-vector-tp2525631p2525666.html
Sent from the R help mailing list archive at Nabble.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] testing for emptyenv

2010-09-03 Thread Peng, C

Thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/testing-for-emptyenv-tp2432922p2525757.html
Sent from the R help mailing list archive at Nabble.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] 3d graph surface

2010-09-03 Thread Peng, C


?persp 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/3d-graph-surface-tp2525859p2525958.html
Sent from the R help mailing list archive at Nabble.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] Function Gini or Ineq

2010-09-03 Thread Peng, C

you need install and load package {reldist} before you call function gini().
HTH.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Function-Gini-or-Ineq-tp2525852p2525966.html
Sent from the R help mailing list archive at Nabble.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] density() with confidence intervals

2010-09-03 Thread Peng, C

One can write an R function to produce a kernel density curve with a
confidence band. See, for example, the steps of doing this in a technical
report at
  http://fmwww.bc.edu/repec/usug2003/bsciker.pdf
-- 
View this message in context: 
http://r.789695.n4.nabble.com/density-with-confidence-intervals-tp2525837p2526008.html
Sent from the R help mailing list archive at Nabble.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] how can I plot bar plots with all the bars (negative and positive) in the same direction????

2010-09-03 Thread Peng, C

In the bar plot, the vertical axis is a numerical axis representing the
frequency (the height of the vertival bar -= frequency). If you really want
to have vertical bar corresponding to the negative values go downward, you
need to make your own function to achieve the goal.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/how-can-I-plot-bar-plots-with-all-the-bars-negative-and-positive-in-the-same-direction-tp2526006p2526021.html
Sent from the R help mailing list archive at Nabble.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] What solve() does?

2010-09-03 Thread Peng, C

If A is a squared matrix, solve(A) gives the inverse of A; if you have a
system of linear equation AX=B, solve(A,B) gives the solution to this system
of equations. For example:

   x-2y =1
-2x+3y=-3

 A=matrix(c(1,-2,-2,3), ncol=2, byrow=T)
 B=c(1,-3)
 
 # to get the inverse of A
 solve(A)
 [,1] [,2]
[1,]   -3   -2
[2,]   -2   -1
 # to get the solution to the system of equation
 solve(A,B)
[1] 3 1



-- 
View this message in context: 
http://r.789695.n4.nabble.com/What-solve-does-tp2402922p2526066.html
Sent from the R help mailing list archive at Nabble.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] testing for emptyenv

2010-09-02 Thread Peng, C

Is there a complete list of these very handy and power functions in the base
R?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/testing-for-emptyenv-tp2432922p2525031.html
Sent from the R help mailing list archive at Nabble.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.