[R] regession code

Rui Barradas ruipbarradas at sapo.pt
Tue Nov 5 13:22:38 CET 2013


Hello,

You are trying to get the coefficients of the function, nt of that 
function's result. Also, your function returns nothing. Try instead


fn <- function(x,y){
	lreg <- lm(y ~ x)
	lreg
}

fit <- fn(x,y)
b <- coef(fit)
b

Hope this helps,

Rui Barradas

Em 05-11-2013 10:56, IZHAK shabsogh escreveu:
>> y <- c(5.5199668,  1.5234525,  3.3557000,  6.7211704,  7.4237955,  1.9703127,
> +        4.3939336, -1.4380091,  3.2650180,  3.5760906,  0.2947972,  1.0569417)
>> x <- c(1,   0,   0,   4,   3,   5,  12,  10,  12, 100, 100, 100)
>>
>> fn<-function(x,y){
> + lreg<-lm(y ~ x)
> + }
>> fn(x,y)
>>
>> b<-coef(fn)
> Error: object of type 'closure' is not subsettable
>
> can you please correct this error and explain to me what is the problem with this code,that i am get the above error
>
>
> thankx
>
> 	[[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.
>



More information about the R-help mailing list