Re: [R] question on lm or glm matrix of coeficients X test data terms

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Mon, 07 Jul 2008 20:08:49 -0400

Dear Dhruv,

Try this:

# data set
set.seed(123)
X=matrix(rpois(10,10),ncol=2)
X

[,1] [,2]
[1,]    8   15
[2,]    9   11
[3,]   14    5
[4,]   10    4
[5,]   10   13

# outcome
t(apply(X,1,function(x,betas){
if(length(x)!=length(betas)) stop("x and betas are of different length!") y=x*betas
y
},betas=c(0.05,0.6)))

[,1] [,2]
[1,] 0.40  9.0
[2,] 0.45  6.6
[3,] 0.70  3.0
[4,] 0.50  2.4
[5,] 0.50  7.8

HTH, Jorge

On Mon, Jul 7, 2008 at 7:56 PM, DS <ds5j_at_excite.com> wrote:

>
> Hi,
>
> is there an easy way to get the calculated weights in a regression
> equation?
>
>
>
> for e.g.
>
> if my model has 2 variables 1 and 2 with coefficient .05 and .6
>
> how can I get the computed values for a test dataset for each coefficient?
>
> data
>
> var1,var2
>
> 10,100
>
>
>
> so I want to get .5, 60 back in a vector. This is a one row example but I
> would want to get a matrix of multiplied out coefficients and terms for use
> in comparing contribution of variables to final score. As in a scorecard
> using logistic regression.
>
>
>
> Please advise.
>
> thanks
>
> Dhruv
>
> ______________________________________________
> R-help_at_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.
>

        [[alternative HTML version deleted]]



R-help_at_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. Received on Tue 08 Jul 2008 - 00:11:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Jul 2008 - 03:31:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive