[R] generating phi using function()

Daniel Nordlund djnordlund at frontier.com
Tue Mar 31 08:30:14 CEST 2015


On 3/30/2015 12:30 PM, T.Riedle wrote:
> Hi,
> I am struggling with following function
>> phi <- function(w1, w2, j, k, K){
> +   zaehler <- (k/K)^(w1-1)*(1-k/K)^(w2-1)
> +   nenner <- sum( ((1:K)/K)^(w1-1)*(1-(1:K)/K)^(w2-1))
> +   return( zaehler/nenner )
> + }
>> phi(c(1, 1), 44L, 1)
> Error in phi(c(1, 1), 44L, 1) : argument "k" is missing, with no default
>
>
> Hence, I have changed the function to
>
> phi <- function(w, k, K){
> + w1 <- w[1]
> + w2 <- w[2]
> + zaehler <- (k/K)^(w1-1)*(1-k/K)^(w2-1)
> + nenner <- sum( ((1:K)/K)^(w1-1)*(1-(1:K)/K)^(w2-1))
> + return( zaehler/nenner )
> + }
>
>   Unfortunately, when running the midas regression I get the following error message
>
>   m22.phi<- midas_r(rv~mls(rvh,1:max.lag+h1,1,phi), start = list(rvh=c(1,1)))
>
> Error in X[, inds] %*% fun(st) : non-conformable arguments
>
> I guess the problem is w but I do not find a solution how to produce the formula shown in the attached file where the exponents are w1 and w2, respectively.
>
> Thanks for your help
>
>
> From: JLucke at ria.buffalo.edu [mailto:JLucke at ria.buffalo.edu]
> Sent: 30 March 2015 16:01
> To: T.Riedle
> Cc: r-help at r-project.org; R-help
> Subject: Re: [R] generating phi using function()
>
> Your function phi has 5 arguments with no defaults.  Your call only has 3 arguments.  Hence the error message.
>> phi <- function(w1, w2, j, k, K){
> +   zaehler <- (k/K)^(w1-1)*(1-k/K)^(w2-1)
> +   nenner <- sum( ((1:K)/K)^(w1-1)*(1-(1:K)/K)^(w2-1))
> +   return( zaehler/nenner )
> + }
>> phi(c(1, 1), 44L, 1)
> Error in phi(c(1, 1), 44L, 1) : argument "k" is missing, with no default
>
>
>
>>
>
>
>
>
>
> "T.Riedle" <tr206 at kent.ac.uk<mailto:tr206 at kent.ac.uk>>
> Sent by: "R-help" <r-help-bounces at r-project.org<mailto:r-help-bounces at r-project.org>>
>
> 03/29/2015 08:59 AM
>
> To
>
> "r-help at r-project.org<mailto:r-help at r-project.org>" <r-help at r-project.org<mailto:r-help at r-project.org>>,
>
> cc
>
> Subject
>
> [R] generating phi using function()
>
>
>
>
>
>
>
> Hi everybody,
> I am trying to generate the formula shown in the attachment. My formula so far looks as follows:
>
> phi <- function(w1, w2, j, k, K){
> zaehler <- (k/K)^(w1-1)*(1-k/K)^(w2-1)
> nenner <- sum( ((1:K)/K)^(w1-1)*(1-(1:K)/K)^(w2-1))
> return( zaehler/nenner )
> }
>
> Unfortunately something must be wrong here as I get the following message when running a midas regression
>
> m22.phi<- midas_r(rv~mls(rvh,1:max.lag+h1,1,phi), start = list(rvh=c(1,1)))
> Error in phi(c(1, 1), 44L, 1) : argument "K" is missing, with no default
> Called from: .rs.breakOnError(TRUE)
> Browse[1]> K<-125
> Browse[1]> 125
>
> Could anybody look into my phi formula and tell me what is wrong with it?
>
> Thanks in advance.
>
> ______________________________________________
> R-help at r-project.org<mailto:R-help at r-project.org> 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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> ______________________________________________
> R-help at r-project.org 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.
>

You haven't provided a reproducible example, so it is difficult to 
trouble shoot errors.  However, it is not obvious to me that the error 
message has anything to do with parameter, w, in the phi function.  In 
reading the documentation for midas_r(), the help says of the formula 
argument

formula 	

formula for restricted MIDAS regression or midas_r object. Formula must 
include fmls function

your formula does not include the fmls() function, it uses mls().  So I 
think your problem may have to do with how you are calling the midas_r 
function, and how the parameters are created and passed to phi().


Unfortunately, I can't be of much more help,

Dan

-- 
Daniel Nordlund
Bothell, WA USA



More information about the R-help mailing list