# gls procedure in nlme

7 messages
Open this post in threaded view
|

## gls procedure in nlme

 I need help with gls{nlme}. Specifically, I am estimating an equation with AR(1) using maximum-likelihood. I am not understanding the correlationoption below. Help appreciated. === library(nlme) eq1<-log(chnimp)~log(chempi)+log(gas)+log(rtwex)+befile6+                   affile6+afdec6 reg1<-gls(eq1,data=mydata,correlation=corAR1(),method="ML",verbose=T)         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Matrix multiplication

 I need to have all elements of a matrix multiplied by a weight before being post-multiplied by itself, as shown in the forst block of codes below. I can also multiply the matrix by the square root of the weight and then take the outer product. Actually, what I need is this. Denote each row of the matrix by a row vector as xi and each element of the weighting vector as wi. Then, I need the sum of wi * t(xi) %*% xi over i. Any suggestion for a compact approach would be appreciated. set.seed(76543211) w<-1:10; w a<-matrix(rpois(20,2),nrow=10); a b<-a a<-w*a t(a)%*%b set.seed(76543211) a<-matrix(rpois(20,2),nrow=10); a a<-sqrt(w)*a; a t(a)%*%a On 1/4/2017 5:41 PM, Steven Yen wrote: > I need help with gls{nlme}. > Specifically, I am estimating an equation with AR(1) using > maximum-likelihood. I am not understanding the correlationoption > below. Help appreciated. > > === > library(nlme) > eq1<-log(chnimp)~log(chempi)+log(gas)+log(rtwex)+befile6+ >                  affile6+afdec6 > reg1<-gls(eq1,data=mydata,correlation=corAR1(),method="ML",verbose=T) >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Matrix multiplication

 Is this a question? You seem to have three possible calculations, have already implemented two of them (?) and it is unclear (to me) what you think the right answer for any of them is supposed to be. -- Sent from my phone. Please excuse my brevity. On June 7, 2017 8:50:55 PM PDT, Steven Yen <[hidden email]> wrote: >I need to have all elements of a matrix multiplied by a weight before >being post-multiplied by itself, as shown in the forst block of codes >below. I can also multiply the matrix by the square root of the weight >and then take the outer product. > >Actually, what I need is this. Denote each row of the matrix by a row >vector as xi and each element of the weighting vector as wi. Then, I >need the sum of wi * t(xi) %*% xi over i. > >Any suggestion for a compact approach would be appreciated. > >set.seed(76543211) >w<-1:10; w >a<-matrix(rpois(20,2),nrow=10); a >b<-a >a<-w*a >t(a)%*%b > >set.seed(76543211) >a<-matrix(rpois(20,2),nrow=10); a >a<-sqrt(w)*a; a >t(a)%*%a > > > > >On 1/4/2017 5:41 PM, Steven Yen wrote: >> I need help with gls{nlme}. >> Specifically, I am estimating an equation with AR(1) using >> maximum-likelihood. I am not understanding the correlationoption >> below. Help appreciated. >> >> === >> library(nlme) >> eq1<-log(chnimp)~log(chempi)+log(gas)+log(rtwex)+befile6+ >>                  affile6+afdec6 >> reg1<-gls(eq1,data=mydata,correlation=corAR1(),method="ML",verbose=T) >> > > [[alternative HTML version deleted]] > >______________________________________________ >[hidden email] mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help>PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html>and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Matrix multiplication

 OK Thanks. Your response made me think. Here (the last line) is what I need: set.seed(76543211) w<-1:10; w a<-matrix(rpois(20,2),nrow=10); a t(w*a)%*%a On 6/8/2017 12:09 PM, Jeff Newmiller wrote: > Is this a question? You seem to have three possible calculations, have already implemented two of them (?) and it is unclear (to me) what you think the right answer for any of them is supposed to be. > -- Sent from my phone. Please excuse my brevity. On June 7, 2017 > 8:50:55 PM PDT, Steven Yen <[hidden email]> wrote: >> I need to have all elements of a matrix multiplied by a weight before >> being post-multiplied by itself, as shown in the forst block of codes >> below. I can also multiply the matrix by the square root of the weight >> and then take the outer product. >> >> Actually, what I need is this. Denote each row of the matrix by a row >> vector as xi and each element of the weighting vector as wi. Then, I >> need the sum of wi * t(xi) %*% xi over i. >> >> Any suggestion for a compact approach would be appreciated. >> >> set.seed(76543211) >> w<-1:10; w >> a<-matrix(rpois(20,2),nrow=10); a >> b<-a >> a<-w*a >> t(a)%*%b >> >> set.seed(76543211) >> a<-matrix(rpois(20,2),nrow=10); a >> a<-sqrt(w)*a; a >> t(a)%*%a         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Matrix multiplication

 Fine,  except that you already seen to have a very compact solution if that really is what you are looking for. What am I missing? -- Sent from my phone. Please excuse my brevity. On June 7, 2017 9:16:48 PM PDT, Steven Yen <[hidden email]> wrote: >OK Thanks. Your response made me think. Here (the last line) is what I >need: > >set.seed(76543211) >w<-1:10; w >a<-matrix(rpois(20,2),nrow=10); a >t(w*a)%*%a > >On 6/8/2017 12:09 PM, Jeff Newmiller wrote: >> Is this a question? You seem to have three possible calculations, >have already implemented two of them (?) and it is unclear (to me) what >you think the right answer for any of them is supposed to be. >> -- Sent from my phone. Please excuse my brevity. On June 7, 2017 >> 8:50:55 PM PDT, Steven Yen <[hidden email]> wrote: >>> I need to have all elements of a matrix multiplied by a weight >before >>> being post-multiplied by itself, as shown in the forst block of >codes >>> below. I can also multiply the matrix by the square root of the >weight >>> and then take the outer product. >>> >>> Actually, what I need is this. Denote each row of the matrix by a >row >>> vector as xi and each element of the weighting vector as wi. Then, I >>> need the sum of wi * t(xi) %*% xi over i. >>> >>> Any suggestion for a compact approach would be appreciated. >>> >>> set.seed(76543211) >>> w<-1:10; w >>> a<-matrix(rpois(20,2),nrow=10); a >>> b<-a >>> a<-w*a >>> t(a)%*%b >>> >>> set.seed(76543211) >>> a<-matrix(rpois(20,2),nrow=10); a >>> a<-sqrt(w)*a; a >>> t(a)%*%a ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.