functionexamples

functionexamples - b1=...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
fun2<-function(x1,a1=100,b1=-.05){ res1<-a1*(1-exp(b1*x1)) return(res1) } fun2(20) fun2(20,a1=90,b1=-0.07) fun3<-function(x1){ f1<-(7/10*sqrt(6*pi))+3/(10*sqrt(2*pi)) f1<-f1*exp(-1/18*(x1-3)^2-1/2*(x1-8)^2) return(f1) } ####Below code shows how to find the integral of the function#### intfun3<-function(a1=0,b1=1,delta1=0.1){ x1<-seq(a1,b1,by= delta1) return(res1) } intfun3(a1=2,b1=5,delta1=0.1) intfun3(a1=2,b1=5,delta1=0.01) ####Below code shows creating a list to return more than 1 value#### x1<-list(a1=c(1,2,3,4,5),
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: b1= c("True","False"), c1=c(1.983,2.425,3.334) ) ####If you want to see the names of items on a list, use the names() statement#### ####Below code is a function that returns a list#### fun2list<-function(y1,x1,a1=3,b1=.5){ pred1<-a1+b1*x1 resid1<-y1-pred1 MSE1<-sum(resid1^2)/length(x1-2) res1<-list(predicted=pred1, residuals=resid1, MSE=MSE1) return(res1) } ####Running code#### x1<-seq(0,10,by=1) y1<-c(3.03,3.51,4.06,4.46,5.01,5.53,5.93,6.51,7.07,7.44,8.05) fun2list(y1,x1,a1=3,b1=.5) f1a<-fun2list(y1,x1,a1=3,b1=.5) f1a$MSE f1a$predicted...
View Full Document

This note was uploaded on 11/15/2011 for the course STAT 321 taught by Professor Staff during the Spring '08 term at VCU.

Ask a homework question - tutors are online