[R] Question regarding error "x and y lengths differ"

Jim Lemon jim at bitwrit.com.au
Tue Apr 30 06:24:34 CEST 2013


On 04/30/2013 11:38 AM, Sean Doyle wrote:
> Hello, I'm a first semester statistics
> student<http://r.789695.n4.nabble.com/Question-regarding-error-quot-x-and-y-lengths-differ-quot-td4665773.html#>and
> I am using R for roughly the third time ever. I am following a
> tutorial
> and yet I still get the error "x and y lengths differ." I am very new to
> this program, and I have searched for solutions, but because I do not
> understand the program too well, I am not sure which solution may apply to
> me. Any help is much appreciated!
>
> The question is as follows:
>
> Do this given your population standard deviation. If we pick a confidence
> interval, say á
> = 0.1(90% confidence), we can compute a confidence interval for our measure
> of the
> population mean for each one of our samples. Now let¢s compute and plot the
> confidence intervals for the 50 samples:>  m = 50; n = 40; mu = mean(pop);
> sigma = sd(pop);
>> SE = sigma/sqrt(n) # Standard error in mean
>> alpha = 0.10 ; zstar = qnorm(1-alpha/2); # Find z for 90%
> confidence
>> matplot(rbind( samp_mean - zstar*SE, samp_mean +
> zstar*SE),rbind(1:m,1:m), type="l", lty=1);
>> abline(v=mu)
>
> I am receiving the error "Error in xy.coords(x, y, xlabel, ylabel, log =
> log) :
>    'x' and 'y' lengths differ" when inputting>matplot(rbind( samp_mean -
> zstar*SE, samp_mean +
> zstar*SE),rbind(1:m,1:m), type="l", lty=1);
>
Hi Sean,
Without doing your homework for you, I would suggest trying this:

length(samp_mean)
length(zstar*SE)
length(1:m)

I would be very surprised if you got the same answer for all three. Also 
you might want to read the help page for matplot carefully to decide 
which is the "x" and which is the "y" you want to plot.

Jim



More information about the R-help mailing list