Re: [R] on "do.call" function

2011-08-08 Thread Zhang,Yanwei
Hi, Your use of "do.call" is essentially equal to "dpois(lt$y0, exp(rowSums(t(X[lt$i,])*B[,1])))". You do not need to use "do.call", "sapply" or "apply" will do, e.g., > sapply(1:nrow(lt), function(x) fc(lt[x,2],lt[x,1])) [1] 0.1891356 0.1859965 0.3149658 0.3128512 0.2622549 0.2631122 Way

Re: [R] Problem on glmer

2011-05-17 Thread Zhang,Yanwei
nal Message- From: Dennis Murphy [mailto:djmu...@gmail.com] Sent: Tuesday, May 17, 2011 12:46 PM To: Zhang,Yanwei Cc: r-help@r-project.org Subject: Re: [R] Problem on glmer Hi: This might be helpful: http://glmm.wikidot.com/faq It has some commentary and potential workarounds re gamma GL

Re: [R] Problem on glmer

2011-05-17 Thread Zhang,Yanwei
. Thanks. Wayne (Yanwei) Zhang Statistical Research >CNA -Original Message- From: Dennis Murphy [mailto:djmu...@gmail.com] Sent: Tuesday, May 17, 2011 3:05 AM To: Zhang,Yanwei Cc: r-help@r-project.org Subject: Re: [R] Problem on glmer Hi: I believe that the problem with the gl

[R] Problem on glmer

2011-05-16 Thread Zhang,Yanwei
Hi all, I was trying to fit a Gamma hierarchical model using "glmer", but got weird error message that I could not understand. On the other hand, a similar call to the glmmPQL leads to results that are close to what I expect. I also tried to change tha "nAGQ" argument in "glmer", but it did not

[R] Help on simple problem with optim

2010-09-09 Thread Zhang,Yanwei
Dear all, I ran into problems with the function "optim" when I tried to do an mle estimation of a simple lognormal regression. Some warning message poped up saying NANs have been produced in the optimization process. But I could not figure out which part of my code has caused this. I wonder if

Re: [R] Help on glm and optim

2010-09-02 Thread Zhang,Yanwei
Thomas, Thanks a lot. This solves my problem. Wayne (Yanwei) Zhang Statistical Research >CNA -Original Message- From: Thomas Lumley [mailto:tlum...@u.washington.edu] Sent: Thursday, September 02, 2010 11:24 AM To: Zhang,Yanwei Cc: r-help@r-project.org Subject: Re: [R] Help on

[R] Help on glm and optim

2010-09-02 Thread Zhang,Yanwei
Dear all, I'm trying to use the "optim" function to replicate the results from the "glm" using an example from the help page of "glm", but I could not get the "optim" function to work. Would you please point out where I did wrong? Thanks a lot. The following is the code: # Step 1: fit the glm

Re: [R] Method dispatch

2010-03-01 Thread Zhang,Yanwei
tFrom(stats, quantile, predict, coef, vcov, residuals, fitted, fitted.values, rstandard) importFrom(methods, show, coerce) importFrom(graphics, plot) #Classes exportClasses(triangles, MultiChainLadder, MultiChainLadderFit, MCLFit, GMCLFit, MultiChainLadderMse)

[R] Method dispatch

2010-03-01 Thread Zhang,Yanwei
Dear all, In a package, I defined a method for "summary" using setMethod(summary, signature="abc") for my class "abc", but when the package is loaded, the function "summary(x)" where x is of class "abc" seems to have called the default summary function for "ANY" class. Shouldn't it call the met

[R] S4 issues

2010-03-01 Thread Zhang,Yanwei
Dear all, I ran into some issues that I've been trying to figure out for weeks but with no success. So I'm looking for some advice here. I've the following questions: 1. I want to write some S4 classes and methods and add them into a current package that was written in S3. Is this possible? Ca

[R] S4 programming

2010-02-25 Thread Zhang,Yanwei
Dear all, I'm new to S4 classes and have a question on this. I want to use S4 because I want to define explicitly the slots that the new class can have. But other than that, the new class behaves exactly like a list. But this will not allow me to use the generic functions that are already defi

Re: [R] Create R object

2009-06-15 Thread Zhang,Yanwei
fixed length? Thanks a lot. Wayne (Yanwei) Zhang Ttatistical Áesearch CNA From: jim holtman [mailto:jholt...@gmail.com] Sent: Monday, June 15, 2009 11:14 AM To: Zhang,Yanwei Cc: r-help@r-project.org Subject: R

[R] Create R object

2009-06-15 Thread Zhang,Yanwei
Dear R users, I have two simple questions here, and hope someone can help me on this. Thanks in advance. 1. I have a list object lst=list(a1=matrix(rnorm(4),2,2), a2=matrix(rnorm(4),2,2),a3=matrix(rnorm(4),2,2)). Here I only use three elements for illustration, and in fact the length of lst, n

[R] Plot by column

2008-09-05 Thread Zhang Yanwei - Princeton-MRAm
Dear list, I have the following matrix. How can I make the following plot? 1. The x-axis has index 1:7, and the first column is plotted against index 1, second against 2, and so on. 2. I want the points from the left upper conner including the antidiagonal to be plotted with col=2, and the re

[R] VAR question

2008-08-12 Thread Zhang Yanwei - Princeton-MRAm
Hi all, I got another VAR question here and really appreciate if somebody would help me out :) I have five time series, say A,B,C,D,E. My objective is to predict the series A using the rest, that is, B, C, D and E. A Vector Autoregression Model should work here. But first of all, I should select

Re: [R] Multivariate regression with constraints

2008-08-08 Thread Zhang Yanwei - Princeton-MRAm
om: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Zhang Yanwei - Princeton-MRAm Sent: Friday, August 08, 2008 1:26 PM To: Patrizio Frederic Cc: r-help@r-project.org Subject: Re: [R] Multivariate regression with constraints Thanks. If I set the coefficient of p1 equal to zero, then I

Re: [R] Multivariate regression with constraints

2008-08-08 Thread Zhang Yanwei - Princeton-MRAm
CTED] Sent: Friday, August 08, 2008 12:57 PM To: Zhang Yanwei - Princeton-MRAm Cc: r-help@r-project.org Subject: Re: [R] Multivariate regression with constraints Hi Zhang , take a look to sur package http://www.systemfit.org/ regards, Patrizi

[R] Multivariate regression with constraints

2008-08-08 Thread Zhang Yanwei - Princeton-MRAm
Hi all, I am running a bivariate regression with the following: p1=c(184,155,676,67,922,22,76,24,39) p2=c(1845,1483,2287,367,1693,488,435,1782,745) I1=c(1530,1505,2505,204,2285,269,1271,298,2023) I2=c(8238,6247,6150,2748,4361,5549,2657,3533,5415) R1=I1-p1 R2=I2-p2 x1=cbind(p1,R1) y1=cbind(p2,R

[R] Switch two rows in a matrix

2008-08-07 Thread Zhang Yanwei - Princeton-MRAm
Hi all, I have a 4 by 4 matrix, and I want to switch row 2 and row 3 first, then switch column 2 and column 3. Is there an easy way to do it? The following is a tedious way to get what I want. But I wonder if there is a way to simplify this. > a=matrix(rnorm(16),4,4) > a [,1]

[R] Covariance matrix

2008-08-07 Thread Zhang Yanwei - Princeton-MRAm
Hi all, Assume I have a random vector with four variables, i.e. A=(a,b,c,d). I am able to get the covariance matrix of vector A, but how can I get the covariance matrix of vector B=(a,c,b,d) by manipulating the corresponding covariance matrix of A? Thanks. Sincerely, Yanwei Zhang Department

Re: [R] Matrix multiplication

2008-08-07 Thread Zhang Yanwei - Princeton-MRAm
:42 PM To: Zhang Yanwei - Princeton-MRAm; r-help@r-project.org Subject: RE: [R] Matrix multiplication Hi, Yes. this is a way, and relatively easy ... Using "Reduce". Note: in order to use "Reduce", you need an update-to-date version of R. I'm using 2.6.2. First you have

[R] Matrix multiplication

2008-08-06 Thread Zhang Yanwei - Princeton-MRAm
Hi all, Is there an easy way to do cumulative matrix multipliation in R? What's the syntex? Thanks. Sincerely, Yanwei Zhang Department of Actuarial Research and Modeling Munich Re America Tel: 609-275-2176 Email: [EMAIL PROTECTED] [[alternative HTML version

[R] Weighted multivariate regression

2008-08-06 Thread Zhang Yanwei - Princeton-MRAm
Hi all, I'd like to fit a multivariate regression with the variance of the error term porportional to the predictors, like the WLS in the univariate case. y_1~x_1+x_2 y_2~x_1+x_2 var(y_1)=x_1*sigma_1^2 var(y_2)=x_2*sigma_2^2 cov(y_1,y_2)=sqrt(x_1*x_2)*sigma_12^2 How can I specify thi

[R] Multivariate regression with weights

2008-08-04 Thread Zhang Yanwei - Princeton-MRAm
Hi all, I'd like to fit a multivariate regression with the variance of the error term porportional to the predictors, like the WLS in the univariate case. y_1~x_1+x_2 y_2~x_1+x_2 var(y_1)=x_1*sigma_1^2 var(y_2)=x_2*sigma_2^2 cov(y_1,y_2)=sqrt(x_1*x_2)*sigma_12^2 How can I specify thi

Re: [R] Multivariate Regression with Weights

2008-08-04 Thread Zhang Yanwei - Princeton-MRAm
Thanks. Sincerely, Yanwei Zhang Department of Actuarial Research and Modeling Munich Re America Tel: 609-275-2176 Email: [EMAIL PROTECTED] -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, August 04, 2008 5:15 PM To: Zhang Yanwei - Princeton-MRAm

[R] Multivariate Regression with Weights

2008-08-04 Thread Zhang Yanwei - Princeton-MRAm
Hi all, I'd like to fit a multivariate regression with the variance of the error term porportional to the predictors, like the WLS in the univariate case. y_1~x_1+x_2 y_2~x_1+x_2 var(y_1)=x_1*sigma_1^2 var(y_2)=x_2*sigma_2^2 cov(y_1,y_2)=sqrt(x_1*x_2)*sigma_12^2 How can I specify thi

Re: [R] Sampling two exponentials

2008-07-31 Thread Zhang Yanwei - Princeton-MRAm
CTED] [mailto:[EMAIL PROTECTED] On Behalf Of Zhang Yanwei - Princeton-MRAm Sent: Wednesday, July 30, 2008 5:48 PM To: r-help@r-project.org Subject: [R] Sampling two exponentials Hi all, I am going to sample two variables from two exponential distributions, but I want to specify a covariance str

Re: [R] Sampling two exponentials

2008-07-31 Thread Zhang Yanwei - Princeton-MRAm
] -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ben Bolker Sent: Wednesday, July 30, 2008 8:40 PM To: [EMAIL PROTECTED] Subject: Re: [R] Sampling two exponentials Zhang Yanwei - Princeton-MRAm munichreamerica.com> writes: > > Hi all, > I am going t

[R] Sampling two exponentials

2008-07-30 Thread Zhang Yanwei - Princeton-MRAm
Hi all, I am going to sample two variables from two exponential distributions, but I want to specify a covariance structure between these two variables. Is there any way to do it in R? Or is there a "Multivariate Exponential" thing corresponding to the multivariate normal? Thanks in advance.

[R] Numerical question

2008-07-25 Thread Zhang Yanwei - Princeton-MRAm
Hi all, I have n independent variables A_1, A_2, A_3,..,A_n, and each with known variances var(A_1), var(A_2),..., but unknown mean. How can I get the approximation of the variance of the product of the variables using numerical computation, i.e. var(A_1*A_2*A_3*.*A_n)? Thanks. Since

Re: [R] pca

2008-07-25 Thread Zhang Yanwei - Princeton-MRAm
Try ?princomp. Or you can just do it manually. eigen(data) Then the eigen vector corresponding to the biggest eigen value is the first principal component. It goes on. Sincerely, Yanwei Zhang Department of Actuarial Research and Modeling Munich Re America Tel: 609-275-2176 Email: [EMAIL PROTECTE

Re: [R] Questions on weighted least squares

2008-07-23 Thread Zhang Yanwei - Princeton-MRAm
I have figured out the problem. Thanks. Sincerely, Yanwei Zhang Department of Actuarial Research and Modeling Munich Re America Tel: 609-275-2176 Email: [EMAIL PROTECTED] -Original Message- From: Zhang Yanwei - Princeton-MRAm Sent: Wednesday, July 23, 2008 3:32 PM To: Zhang Yanwei

Re: [R] Questions on weighted least squares

2008-07-23 Thread Zhang Yanwei - Princeton-MRAm
artment of Actuarial Research and Modeling Munich Re America Tel: 609-275-2176 Email: [EMAIL PROTECTED] -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 23, 2008 3:00 PM To: Zhang Yanwei - Princeton-MRAm Subject: RE: [R] Questions on weighted least squa

[R] Questions on weighted least squares

2008-07-23 Thread Zhang Yanwei - Princeton-MRAm
Hi all, I met with a problem about the weighted least square regression. 1. I simulated a Normal vector (sim1) with mean 425906 and standard deviation 4. 2. I simulated a second Normal vector with conditional mean b1*sim1, where b1 is just a number I specified, and variance proportional to