Your code is full of syntactic errors. What do you think 1.71(se) means?
After you clean up your code, something like this might be what you want:
out <- lapply(seq(40,500,by = 25), f)
To get plots, just stick in a plot statement after you define m and d.
Have you gone through any R tutorials? You seem to be confused about basics
that tutorials could help you with. This list is not meant to replace such
homework on your own.
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, Sep 25, 2017 at 3:28 PM, Farnoosh Sheikhi <farnoosh_81 at
yahoo.com>
wrote:
> Hi Bert,
>
> Here is the code:
> f<-function(n){
> m=runif(n, 50, 100)
> d=rnorm(n, 0, 1)
> se=sd(d)/sqrt (n)
>
> ci.u<-mean(d)+1.96*sd(d)
> ci.l<-mean(d)-1.96*sd(d)
> ci.w<-ci.u-ci.l
>
> w.ci.uu<-ci.u+(qt (0.975, df=n-1)*1.71(se)
> w.ci.ul<-ci.u-(qt (0.975, df=n-1)*1.71(se)
> w.ci.upper<-w.ci.uu-w.ci.ul
>
> w.ci.lu<-ci.l+(qt (0.975, df=n-1)*1.71(se)
> w.ci.ll<-ci.l-(qt (0.975, df=n-1)*1.71(se)
> w.ci.lower<-w.ci.lu-w.ci.ll
>
> res<-as.data.frame(cbind(n, ci.u, ci.l, ci.w, w.ci.upper, w.ci.lower))
> return(res)
> }
>
>
> I would like to pass different sample sizes n<-seq(40, 500, by=25) and
add
> a scatter plot for each n.
> plot(m~d)
>
> Thanks.
>
>
>
> On Monday, September 25, 2017 3:00 PM, Bert Gunter <bgunter.4567 at
gmail.com>
> wrote:
>
>
> 1. 2o is gibberish; 20 is the number of fingers and toes most of us have.
>
> 2. This is a plain text list. Your code became gibberish with your HTML
> post.
>
> Cheers,
> Bert
>
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip
)
>
> On Mon, Sep 25, 2017 at 2:16 PM, Farnoosh Sheikhi via R-help <
> r-help at r-project.org> wrote:
>
>
>
>
>
> Hi,
> I have the below function which returns confidence intervals. I wanted to
> pass different sample sizes through the function, but for some reason
it's
> not working. n <- seq(from=40, to=300, by=2o)
>
> I was also wondering how I can return a plot for different sample
> sizes. plot(m~d, main="n(i)")
> Any help or suggestion is appreciated.
>
>
> ############################f< -function(n){ m = runif(n,50,200) d
> rnorm(n,0,1) ci.u<-mean(d)+1.96*sd(d) ci.l<-mean(d)-1.96*sd(d)
> ci.w<-ci.u-ci.l se=sd(d)/sqrt(n) w.ci.uu<-ci.u+(qt(.975,
> df=n-1))*1.71*se w.ci.ul<-ci.u-(qt(.975, df=n-1))*1.71*se
> w.ci.upper<-w.ci.uu- w.ci.ul w.ci.lu<-ci.l+(qt(. 975,
> df=n-1))*1.71*se w.ci.ll<-ci.l-(qt(.975, df=n-1))*1.71*se
> w.ci.lower<-w.ci.lu- w.ci.ll res<-as.data.frame(cbind(n, ci.u,
ci.l,
> ci.w, w.ci.upper, w.ci.lower)) return(res)} Best,Nooshi
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________ ________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/ listinfo/r-help
> <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.
>
>
>
>
>
[[alternative HTML version deleted]]